mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Fix #202 -- Allow the manual ordering of questions
* Allow the manual ordering of questions Update Unit Tests Fix some typos * Add migrations * Minor notation change
This commit is contained in:
committed by
Raphael Michel
parent
68967fbfda
commit
3583dde1db
@@ -41,6 +41,10 @@
|
||||
{% url "control:event.items.questions.edit" organizer=request.event.organizer.slug event=request.event.slug question=q.id %}">{{ q.question }}</a></strong>
|
||||
</td>
|
||||
<td>{{ q.get_type_display }}</td>
|
||||
<td>
|
||||
<a href="{% url "control:event.items.questions.up" organizer=request.event.organizer.slug event=request.event.slug question=q.id %}" class="btn btn-default btn-sm {% if forloop.counter0 == 0 %}disabled{% endif %}"><i class="fa fa-arrow-up"></i></a>
|
||||
<a href="{% url "control:event.items.questions.down" organizer=request.event.organizer.slug event=request.event.slug question=q.id %}" class="btn btn-default btn-sm {% if forloop.revcounter0 == 0 %}disabled{% endif %}"><i class="fa fa-arrow-down"></i></a>
|
||||
</td>
|
||||
<td class="text-right"><a href="
|
||||
{% url "control:event.items.questions.delete" organizer=request.event.organizer.slug event=request.event.slug question=q.id %}" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
|
||||
@@ -50,6 +50,9 @@ urlpatterns = [
|
||||
url(r'^questions/$', item.QuestionList.as_view(), name='event.items.questions'),
|
||||
url(r'^questions/(?P<question>\d+)/delete$', item.QuestionDelete.as_view(),
|
||||
name='event.items.questions.delete'),
|
||||
url(r'^questions/(?P<question>\d+)/up$', item.question_move_up, name='event.items.questions.up'),
|
||||
url(r'^questions/(?P<question>\d+)/down$', item.question_move_down,
|
||||
name='event.items.questions.down'),
|
||||
url(r'^questions/(?P<question>\d+)/$', item.QuestionUpdate.as_view(),
|
||||
name='event.items.questions.edit'),
|
||||
url(r'^questions/add$', item.QuestionCreate.as_view(), name='event.items.questions.add'),
|
||||
|
||||
@@ -208,7 +208,7 @@ def category_move(request, category, up=True):
|
||||
if cat.position != i:
|
||||
cat.position = i
|
||||
cat.save()
|
||||
messages.success(request, _('The order of categories as been updated.'))
|
||||
messages.success(request, _('The order of categories has been updated.'))
|
||||
|
||||
|
||||
@event_permission_required("can_change_items")
|
||||
@@ -237,6 +237,49 @@ class QuestionList(ListView):
|
||||
return self.request.event.questions.all()
|
||||
|
||||
|
||||
def question_move(request, question, up=True):
|
||||
"""
|
||||
This is a helper function to avoid duplicating code in question_move_up and
|
||||
question_move_down. It takes a question and a direction and then tries to bring
|
||||
all items for this question in a new order.
|
||||
"""
|
||||
try:
|
||||
question = request.event.questions.get(
|
||||
id=question
|
||||
)
|
||||
except Question.DoesNotExist:
|
||||
raise Http404(_("The selected question does not exist."))
|
||||
questions = list(request.event.questions.order_by("position"))
|
||||
|
||||
index = questions.index(question)
|
||||
if index != 0 and up:
|
||||
questions[index - 1], questions[index] = questions[index], questions[index - 1]
|
||||
elif index != len(questions) - 1 and not up:
|
||||
questions[index + 1], questions[index] = questions[index], questions[index + 1]
|
||||
|
||||
for i, qt in enumerate(questions):
|
||||
if qt.position != i:
|
||||
qt.position = i
|
||||
qt.save()
|
||||
messages.success(request, _('The order of questions has been updated.'))
|
||||
|
||||
|
||||
@event_permission_required("can_change_items")
|
||||
def question_move_up(request, organizer, event, question):
|
||||
question_move(request, question, up=True)
|
||||
return redirect('control:event.items.questions',
|
||||
organizer=request.event.organizer.slug,
|
||||
event=request.event.slug)
|
||||
|
||||
|
||||
@event_permission_required("can_change_items")
|
||||
def question_move_down(request, organizer, event, question):
|
||||
question_move(request, question, up=False)
|
||||
return redirect('control:event.items.questions',
|
||||
organizer=request.event.organizer.slug,
|
||||
event=request.event.slug)
|
||||
|
||||
|
||||
class QuestionDelete(EventPermissionRequiredMixin, DeleteView):
|
||||
model = Question
|
||||
template_name = 'pretixcontrol/items/question_delete.html'
|
||||
|
||||
Reference in New Issue
Block a user