Coverage for events/serializers/checkin.py: 67%
30 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-10-26 14:43 -0500
« prev ^ index » next coverage.py v6.4.4, created at 2022-10-26 14:43 -0500
1import datetime
2from rest_framework import serializers
3from ..models import StationCheckIn
6class MakeCheckInSerializer(serializers.ModelSerializer):
7 """
8 Serializer to make Check In
9 """
10 class Meta:
11 model = StationCheckIn
12 fields = ['checkin_media', 'participant']
14 def update(self, instance, validated_data):
15 station = instance.station
16 instance = super(MakeCheckInSerializer, self).update(instance, validated_data)
18 instance.checkin_timestamp = datetime.datetime.now()
19 instance.has_checkin = True
20 if station.type_of == station.StationCheckInType.QR:
21 instance.approve_timestamp = datetime.datetime.now()
22 instance.is_approved = True
23 instance.save()
25 return instance
28class StationCheckInSerializer(serializers.ModelSerializer):
29 participant = serializers.SerializerMethodField(read_only=True)
31 class Meta:
32 model = StationCheckIn
33 fields = ['random_slug', 'has_checkin', 'is_approved', 'checkin_timestamp', 'participant']
35 def get_participant(self, station):
36 if station.participant is not None:
37 return station.participant.user.name
40class StationCheckInDetailSerializer(StationCheckInSerializer):
41 """
42 Station Check In Serializer for list endpoint
43 """
44 station = serializers.CharField(source='station.name', read_only=True)
45 team = serializers.CharField(source='team.name', read_only=True)
47 class Meta(StationCheckInSerializer.Meta):
48 fields = StationCheckInSerializer.Meta.fields + ['station', 'team', 'checkin_media']