Reordering questions with drag'n'drop (#1433)

* Reordering questions with drag'n'drop

* Add permission check

* Test permissions for question reordering

* Handle malformed requests for question reordering

* Show first up arrow and last down arrow

* Provide page offset

* Revert "Provide page offset"

This reverts commit 8090bd573f.

* Reorder questions endpoint with pagination support

* Rudimentary test for reordering endpoint

* Make reordering questions atomic

* cache questions

* Properly support pagination for reorder_questions

* appease linter

* Fix test
This commit is contained in:
Sohalt
2019-10-14 10:54:20 +02:00
committed by Raphael Michel
parent f10d1bd236
commit 91b586ce08
9 changed files with 3823 additions and 5 deletions

View File

@@ -174,7 +174,7 @@ class QuestionsTest(ItemFormTest):
def test_sort(self):
with scopes_disabled():
q1 = Question.objects.create(event=self.event1, question="Vegetarian?", type="N", required=True, position=0)
Question.objects.create(event=self.event1, question="Food allergies?", position=1)
q2 = Question.objects.create(event=self.event1, question="Food allergies?", position=1)
doc = self.get_doc('/control/event/%s/%s/questions/' % (self.orga1.slug, self.event1.slug))
self.assertIn("Vegetarian?", doc.select("table > tbody > tr")[0].text)
self.assertIn("Food allergies?", doc.select("table > tbody > tr")[1].text)
@@ -189,6 +189,17 @@ class QuestionsTest(ItemFormTest):
self.assertIn("Vegetarian?", doc.select("table > tbody > tr")[0].text)
self.assertIn("Food allergies?", doc.select("table > tbody > tr")[1].text)
self.client.post(
'/control/event/%s/%s/questions/reorder' % (self.orga1.slug, self.event1.slug),
{
"ids": [q2.id, q1.id]
},
content_type='application/json'
)
doc = self.get_doc('/control/event/%s/%s/questions/' % (self.orga1.slug, self.event1.slug))
self.assertIn("Vegetarian?", doc.select("table > tbody > tr")[1].text)
self.assertIn("Food allergies?", doc.select("table > tbody > tr")[0].text)
def test_delete(self):
with scopes_disabled():
c = Question.objects.create(event=self.event1, question="What is your shoe size?", type="N", required=True)

View File

@@ -249,6 +249,9 @@ event_permission_urls = [
# ("can_change_items", "questions/", 200),
("can_change_items", "questions/2/", 404),
("can_change_items", "questions/2/delete", 404),
("can_change_items", "questions/2/up", 404),
("can_change_items", "questions/2/down", 404),
("can_change_items", "questions/reorder", 400),
("can_change_items", "questions/add", 200),
# ("can_change_items", "quotas/", 200),
("can_change_items", "quotas/2/change", 404),