Add add-ons to pretixdroid API

This commit is contained in:
Raphael Michel
2018-05-18 12:15:32 +02:00
parent 777424ad18
commit 835bcb7207
3 changed files with 22 additions and 4 deletions
+4
View File
@@ -81,6 +81,7 @@ uses to communicate with the pretix server.
"attention": false,
"redeemed": true,
"checkin_allowed": true,
"addons_text": "Parking spot",
"paid": true
}
}
@@ -106,6 +107,7 @@ uses to communicate with the pretix server.
"attention": false,
"redeemed": true,
"checkin_allowed": true,
"addons_text": "Parking spot",
"paid": true
},
"questions": [
@@ -152,6 +154,7 @@ uses to communicate with the pretix server.
"attention": false,
"redeemed": true,
"checkin_allowed": true,
"addons_text": "Parking spot",
"paid": true
}
}
@@ -212,6 +215,7 @@ uses to communicate with the pretix server.
"redeemed": false,
"attention": false,
"checkin_allowed": true,
"addons_text": "Parking spot",
"paid": true
},
...
+11 -3
View File
@@ -257,7 +257,11 @@ def serialize_op(op, redeemed, clist):
'attention': op.item.checkin_attention or op.order.checkin_attention,
'redeemed': redeemed,
'paid': op.order.status == Order.STATUS_PAID,
'checkin_allowed': checkin_allowed
'checkin_allowed': checkin_allowed,
'addons_text': ", ".join([
'{} - {}'.format(p.item, p.variation) if p.variation else str(p.item)
for p in op.addons.all()
])
}
@@ -281,7 +285,9 @@ class ApiSearchView(ApiView):
subevent=self.config.list.subevent
).annotate(
last_checked_in=Subquery(cqs)
).select_related('item', 'variation', 'order', 'order__invoice_address', 'addon_to')
).select_related('item', 'variation', 'order', 'order__invoice_address', 'addon_to').prefetch_related(
'addons', 'addons__item', 'addons__variation'
)
if not self.config.list.all_products:
qs = qs.filter(item__in=self.config.list.limit_products.values_list('id', flat=True))
@@ -329,7 +335,9 @@ class ApiDownloadView(ApiView):
subevent=self.config.list.subevent
).annotate(
last_checked_in=Subquery(cqs)
).select_related('item', 'variation', 'order', 'addon_to')
).select_related('item', 'variation', 'order', 'addon_to').prefetch_related(
'addons', 'addons__item', 'addons__variation'
)
if not self.config.list.all_products:
qs = qs.filter(item__in=self.config.list.limit_products.values_list('id', flat=True))
+7 -1
View File
@@ -283,12 +283,18 @@ def test_search_invoice_name(client, env):
@pytest.mark.django_db
def test_download_all_data(client, env):
OrderPosition.objects.create(
order=Order.objects.first(), item=Item.objects.first(), addon_to=OrderPosition.objects.last(),
price=12, secret='foooo'
)
AppConfiguration.objects.create(event=env[0], key='abcdefg', list=env[5])
resp = client.get('/pretixdroid/api/%s/%s/download/?key=%s' % (env[0].organizer.slug, env[0].slug, 'abcdefg'))
jdata = json.loads(resp.content.decode("utf-8"))
assert len(jdata['results']) == 2
assert len(jdata['results']) == 3
assert jdata['results'][0]['secret'] == '1234'
assert jdata['results'][0]['addons_text'] == ''
assert jdata['results'][1]['secret'] == '5678910'
assert jdata['results'][1]['addons_text'] == 'T-Shirt'
@pytest.mark.django_db