From 4eda790b7c48a2524f6e3957a65a002d394979a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Beaul=C3=A9?= Date: Thu, 28 Dec 2023 15:06:26 +0700 Subject: [PATCH] API: Add barcodes to participants This commit adds participants' checkin barcodes to the participants' list and detail endpoints to allow for them to be easily exported without needing to make one request per participant. This field is private, and currently read-only, but can be opened up. It also fixes the type for the barcode in the main checkin serializer, as barcodes are strings rather than numbers (e.g. allowing "000001"). --- tabbycat/api/serializers.py | 6 +++++- tabbycat/api/views.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tabbycat/api/serializers.py b/tabbycat/api/serializers.py index 4b9ba5f7aa4..87bae6e07a8 100644 --- a/tabbycat/api/serializers.py +++ b/tabbycat/api/serializers.py @@ -63,7 +63,7 @@ class V1LinksSerializer(serializers.Serializer): class CheckinSerializer(serializers.Serializer): object = serializers.HyperlinkedIdentityField(view_name='api-root') - barcode = serializers.IntegerField() + barcode = serializers.CharField() checked = serializers.BooleanField() timestamp = serializers.DateTimeField() @@ -456,6 +456,7 @@ class SpeakerLinksSerializer(serializers.Serializer): queryset=SpeakerCategory.objects.all(), ) _links = SpeakerLinksSerializer(source='*', read_only=True) + barcode = serializers.CharField(source='checkin_identifier.barcode', read_only=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -465,6 +466,7 @@ def __init__(self, *args, **kwargs): self.fields.pop('phone') self.fields.pop('pronoun') self.fields.pop('url_key') + self.fields.pop('barcode') if kwargs['context']['tournament'].pref('participant_code_names') == 'everywhere': self.fields.pop('name') @@ -519,6 +521,7 @@ class AdjudicatorLinksSerializer(serializers.Serializer): ) venue_constraints = VenueConstraintSerializer(many=True, required=False) _links = AdjudicatorLinksSerializer(source='*', read_only=True) + barcode = serializers.CharField(source='checkin_identifier.barcode', read_only=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -545,6 +548,7 @@ def __init__(self, *args, **kwargs): self.fields.pop('phone') self.fields.pop('pronoun') self.fields.pop('url_key') + self.fields.pop('barcode') class Meta: model = Adjudicator diff --git a/tabbycat/api/views.py b/tabbycat/api/views.py index 20319d2dfff..486791452a3 100644 --- a/tabbycat/api/views.py +++ b/tabbycat/api/views.py @@ -330,7 +330,7 @@ def get_queryset(self): return super().get_queryset().select_related('tournament').prefetch_related( Prefetch( 'speaker_set', - queryset=Speaker.objects.all().prefetch_related(category_prefetch).select_related('team__tournament'), + queryset=Speaker.objects.all().prefetch_related(category_prefetch).select_related('team__tournament', 'checkin_identifier'), ), 'institution_conflicts', 'venue_constraints__category__tournament', 'break_categories', 'break_categories__tournament', @@ -360,7 +360,7 @@ def get_queryset(self): if self.request.query_params.get('break') and self.get_break_permission(): filters &= Q(breaking=True) - return super().get_queryset().prefetch_related( + return super().get_queryset().select_related('checkin_identifier').prefetch_related( 'team_conflicts', 'team_conflicts__tournament', 'adjudicator_conflicts', 'adjudicator_conflicts__tournament', 'institution_conflicts', 'venue_constraints__category__tournament', @@ -410,7 +410,7 @@ def get_queryset(self): if not self.request.user or not self.request.user.is_staff: category_prefetch.queryset = category_prefetch.queryset.filter(public=True) - return super().get_queryset().prefetch_related(category_prefetch) + return super().get_queryset().select_related('checkin_identifier').prefetch_related(category_prefetch) @extend_schema(tags=['venues'], parameters=[tournament_parameter])