Coverage for website/events/api/calendarjs/serializers.py: 91.30%
42 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from rest_framework.reverse import reverse
3from events import services
4from events.models import Event, status
5from events.models.external_event import ExternalEvent
6from thaliawebsite.api.calendarjs.serializers import CalenderJSSerializer
9class EventsCalenderJSSerializer(CalenderJSSerializer):
10 class Meta(CalenderJSSerializer.Meta):
11 model = Event
13 def _url(self, instance):
14 return instance.get_absolute_url()
16 def _class_names(self, instance):
17 if self.context["member"] and len(instance.member_registration) > 0: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true
18 registration = instance.member_registration[-1]
19 else:
20 registration = None
21 reg_status = services.registration_status(
22 instance, registration, self.context["member"]
23 )
24 return [status.calendarjs_class_name(reg_status)]
26 def _registration_info(self, instance):
27 if self.context["member"] and len(instance.member_registration) > 0: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true
28 registration = instance.member_registration[-1]
29 else:
30 registration = None
32 status = services.registration_status(
33 instance, registration, self.context["member"]
34 )
35 return services.registration_status_string(
36 status,
37 instance,
38 registration,
39 )
42class UnpublishedEventsCalenderJSSerializer(CalenderJSSerializer):
43 """See CalenderJSSerializer, customised classes."""
45 class Meta(CalenderJSSerializer.Meta):
46 model = Event
48 def _class_names(self, instance):
49 return ["unpublished-event"]
51 def _url(self, instance):
52 return reverse("admin:events_event_details", kwargs={"pk": instance.id})
54 def _registration_info(self, instance):
55 return "Unpublished event"
58class ExternalEventCalendarJSSerializer(CalenderJSSerializer):
59 """External event calender serializer."""
61 class Meta(CalenderJSSerializer.Meta):
62 """Meta class for partner event calendar serializer."""
64 model = ExternalEvent
66 def _title(self, instance):
67 return f"{instance.title} ({instance.organiser})"
69 def _class_names(self, instance):
70 """Return the color of the background."""
71 return ["external-event"]
73 def _url(self, instance):
74 """Return the url of the partner event."""
75 return instance.url
77 def _target_blank(self, instance):
78 """Return whether the anchor tag should have 'target="_blank"'."""
79 return True