|
17 | 17 | from rest_framework.mixins import CreateModelMixin, RetrieveModelMixin |
18 | 18 | from rest_framework.permissions import IsAuthenticated |
19 | 19 | from rest_framework.response import Response |
20 | | -from rest_framework.viewsets import GenericViewSet |
| 20 | +from rest_framework.viewsets import GenericViewSet, ReadOnlyModelViewSet |
| 21 | +from django.utils.timezone import now |
21 | 22 |
|
22 | 23 | from ..models import ( |
23 | 24 | Discharge, |
|
27 | 28 | Patient, |
28 | 29 | PatientHospitalMapping, |
29 | 30 | PreferredHospital, |
| 31 | + Announcement, |
30 | 32 | ) |
31 | 33 | from .serializers import ( |
32 | 34 | CreatePatientSerializer, |
|
41 | 43 | PatientHospitalMappingWriteSerializer, |
42 | 44 | PreferredHospitalReadSerializer, |
43 | 45 | ReadPatientSerializer, |
44 | | - SurgeonEpisodeSummarySerializer, OwnedEpisodeSerializer, UnlinkedPatientSerializer, |
| 46 | + SurgeonEpisodeSummarySerializer, OwnedEpisodeSerializer, UnlinkedPatientSerializer, AnnouncementSerializer, |
45 | 47 | ) |
46 | 48 | from ...users.models import MedicalPersonnel |
47 | 49 |
|
@@ -401,3 +403,13 @@ def get_serializer_context(self): |
401 | 403 | context = super().get_serializer_context() |
402 | 404 | context['request'] = self.request |
403 | 405 | return context |
| 406 | + |
| 407 | +class AnnouncementViewSet(ReadOnlyModelViewSet): |
| 408 | + serializer_class = AnnouncementSerializer |
| 409 | + |
| 410 | + def get_queryset(self): |
| 411 | + current_time = now() |
| 412 | + return Announcement.objects.filter( |
| 413 | + Q(display_from__lte=current_time) | Q(display_from__isnull=True), |
| 414 | + Q(display_until__gte=current_time) | Q(display_until__isnull=True) |
| 415 | + ).order_by("-created_at") |
0 commit comments