API: Provide useful device_id in checkins (Z#23163025) (#4427)

This commit is contained in:
Raphael Michel
2024-08-29 12:36:27 +02:00
committed by GitHub
parent 0b4e99c2d8
commit b1bfa1acee
7 changed files with 26 additions and 14 deletions

View File

@@ -273,9 +273,15 @@ class AnswerSerializer(I18nAwareModelSerializer):
class CheckinSerializer(I18nAwareModelSerializer):
device_id = serializers.SlugRelatedField(
source='device',
slug_field='device_id',
read_only=True,
)
class Meta:
model = Checkin
fields = ('id', 'datetime', 'list', 'auto_checked_in', 'gate', 'device', 'type')
fields = ('id', 'datetime', 'list', 'auto_checked_in', 'gate', 'device', 'device_id', 'type')
class FailedCheckinSerializer(I18nAwareModelSerializer):

View File

@@ -377,7 +377,7 @@ def _checkin_list_position_queryset(checkinlists, ignore_status=False, ignore_pr
Prefetch(
'positions',
OrderPosition.objects.prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related('device')),
'item', 'variation', 'answers', 'answers__options', 'answers__question',
)
)

View File

@@ -78,7 +78,7 @@ class ReusableMediaViewSet(viewsets.ModelViewSet):
queryset=OrderPosition.objects.select_related(
'order', 'order__event', 'order__event__organizer', 'seat',
).prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related('device')),
'answers', 'answers__options', 'answers__question',
)
),

View File

@@ -258,7 +258,7 @@ class OrderViewSetMixin:
return Prefetch(
'positions',
opq.all().prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related('device')),
Prefetch('item', queryset=self.request.event.items.prefetch_related(
Prefetch('meta_values', ItemMetaValue.objects.select_related('property'), to_attr='meta_values_cached')
)),
@@ -279,7 +279,7 @@ class OrderViewSetMixin:
return Prefetch(
'positions',
opq.all().prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related('device')),
'item', 'variation',
Prefetch('answers', queryset=QuestionAnswer.objects.prefetch_related('options', 'question').order_by('question__position')),
'seat',
@@ -1092,7 +1092,7 @@ class OrderPositionViewSet(viewsets.ModelViewSet):
'item_meta_properties',
)
qs = qs.prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related("device")),
Prefetch('item', queryset=self.request.event.items.prefetch_related(
Prefetch('meta_values', ItemMetaValue.objects.select_related('property'),
to_attr='meta_values_cached')
@@ -1111,7 +1111,7 @@ class OrderPositionViewSet(viewsets.ModelViewSet):
Prefetch(
'positions',
qs.prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related('device')),
Prefetch('item', queryset=self.request.event.items.prefetch_related(
Prefetch('meta_values', ItemMetaValue.objects.select_related('property'),
to_attr='meta_values_cached')
@@ -1135,7 +1135,7 @@ class OrderPositionViewSet(viewsets.ModelViewSet):
)
else:
qs = qs.prefetch_related(
Prefetch('checkins', queryset=Checkin.objects.all()),
Prefetch('checkins', queryset=Checkin.objects.select_related("device")),
'answers', 'answers__options', 'answers__question',
).select_related(
'item', 'order', 'order__event', 'order__event__organizer', 'seat'

View File

@@ -498,6 +498,7 @@ def test_list_all_items_positions(token_client, organizer, event, clist, clist_a
'datetime': c.datetime.isoformat().replace('+00:00', 'Z'),
'auto_checked_in': False,
'device': None,
'device_id': None,
'gate': None,
'type': 'entry',
}
@@ -540,6 +541,7 @@ def test_list_all_items_positions(token_client, organizer, event, clist, clist_a
'datetime': c.datetime.isoformat().replace('+00:00', 'Z'),
'auto_checked_in': False,
'device': None,
'device_id': None,
'gate': None,
'type': 'entry',
}

View File

@@ -959,7 +959,7 @@ def test_refund_cancel(token_client, organizer, event, order):
@pytest.mark.django_db
def test_orderposition_list(token_client, organizer, event, order, item, subevent, subevent2, question):
def test_orderposition_list(token_client, organizer, device, event, order, item, subevent, subevent2, question, django_assert_num_queries):
i2 = copy.copy(item)
i2.pk = None
i2.save()
@@ -1060,19 +1060,22 @@ def test_orderposition_list(token_client, organizer, event, order, item, subeven
with scopes_disabled():
cl = event.checkin_lists.create(name="Default")
c = op.checkins.create(datetime=datetime.datetime(2017, 12, 26, 10, 0, 0, tzinfo=datetime.timezone.utc), list=cl)
c = op.checkins.create(datetime=datetime.datetime(2017, 12, 26, 10, 0, 0, tzinfo=datetime.timezone.utc), list=cl, device=device)
op.checkins.create(datetime=datetime.datetime(2017, 12, 26, 10, 0, 0, tzinfo=datetime.timezone.utc), list=cl, successful=False)
res['checkins'] = [{ # successful only
'id': c.pk,
'datetime': '2017-12-26T10:00:00Z',
'list': cl.pk,
'auto_checked_in': False,
'device': None,
'device': device.pk,
'device_id': device.device_id,
'gate': None,
'type': 'entry'
}]
resp = token_client.get(
'/api/v1/organizers/{}/events/{}/orderpositions/?has_checkin=true'.format(organizer.slug, event.slug))
with django_assert_num_queries(15):
resp = token_client.get(
'/api/v1/organizers/{}/events/{}/orderpositions/?has_checkin=true'.format(organizer.slug, event.slug)
)
assert [res] == resp.data['results']
op.subevent = subevent