Skip to content

Commit

Permalink
API: Add barcodes to participants
Browse files Browse the repository at this point in the history
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").
  • Loading branch information
tienne-B committed Dec 28, 2023
1 parent 1019814 commit 4eda790
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion tabbycat/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tabbycat/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 4eda790

Please sign in to comment.