mirror of
https://github.com/pretix/pretix.git
synced 2026-09-15 16:34:42 +00:00
API: Fix selecting checkin question answers by option identifier
This commit is contained in:
@@ -1116,10 +1116,13 @@ class Question(LoggedModel):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if self.type == Question.TYPE_CHOICE:
|
if self.type == Question.TYPE_CHOICE:
|
||||||
try:
|
q = Q(identifier=answer)
|
||||||
return self.options.get(Q(pk=answer) | Q(identifier=answer))
|
if answer.isdigit():
|
||||||
except:
|
q |= Q(pk=answer)
|
||||||
|
o = self.options.filter(q).first()
|
||||||
|
if not o:
|
||||||
raise ValidationError(_('Invalid option selected.'))
|
raise ValidationError(_('Invalid option selected.'))
|
||||||
|
return o
|
||||||
elif self.type == Question.TYPE_CHOICE_MULTIPLE:
|
elif self.type == Question.TYPE_CHOICE_MULTIPLE:
|
||||||
if isinstance(answer, str):
|
if isinstance(answer, str):
|
||||||
l_ = list(self.options.filter(
|
l_ = list(self.options.filter(
|
||||||
|
|||||||
@@ -749,6 +749,29 @@ def test_question_choice(token_client, organizer, clist, event, order, question)
|
|||||||
assert list(order.positions.first().answers.get(question=question[0]).options.all()) == [question[1]]
|
assert list(order.positions.first().answers.get(question=question[0]).options.all()) == [question[1]]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_question_choice_identifier(token_client, organizer, clist, event, order, question):
|
||||||
|
with scopes_disabled():
|
||||||
|
p = order.positions.first()
|
||||||
|
resp = token_client.post('/api/v1/organizers/{}/events/{}/checkinlists/{}/positions/{}/redeem/'.format(
|
||||||
|
organizer.slug, event.slug, clist.pk, p.pk
|
||||||
|
), {}, format='json')
|
||||||
|
assert resp.status_code == 400
|
||||||
|
assert resp.data['status'] == 'incomplete'
|
||||||
|
with scopes_disabled():
|
||||||
|
assert resp.data['questions'] == [QuestionSerializer(question[0]).data]
|
||||||
|
|
||||||
|
resp = token_client.post('/api/v1/organizers/{}/events/{}/checkinlists/{}/positions/{}/redeem/'.format(
|
||||||
|
organizer.slug, event.slug, clist.pk, p.pk
|
||||||
|
), {'answers': {question[0].pk: str(question[1].identifier)}}, format='json')
|
||||||
|
print(resp.data)
|
||||||
|
assert resp.status_code == 201
|
||||||
|
assert resp.data['status'] == 'ok'
|
||||||
|
with scopes_disabled():
|
||||||
|
assert order.positions.first().answers.get(question=question[0]).answer == 'M'
|
||||||
|
assert list(order.positions.first().answers.get(question=question[0]).options.all()) == [question[1]]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_question_invalid(token_client, organizer, clist, event, order, question):
|
def test_question_invalid(token_client, organizer, clist, event, order, question):
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
|
|||||||
Reference in New Issue
Block a user