DEP: Add emergency api endpoint#2723
DEP: Add emergency api endpoint#2723sudip-khanal wants to merge 4 commits intoproject/dref-emergency-pagesfrom
Conversation
- Add Enum for event sources. - Add source field in place of auto generated source field on event model. - Migrate existing event records to enum type. - Update related serializers and tests.
- Add new emergency api for. - Attach latest field report. - Add test case for emergency endpoint.
| class Event(models.Model): | ||
| """A disaster, which could cover multiple countries""" | ||
|
|
||
| class EventSources(models.IntegerChoices): |
There was a problem hiding this comment.
| class EventSources(models.IntegerChoices): | |
| class EventSource(models.IntegerChoices): |
| auto_generated_source = models.CharField( | ||
| verbose_name=_("auto generated source"), max_length=50, null=True, blank=True, editable=False | ||
| ) | ||
| source = models.IntegerField(choices=EventSources.choices, default=EventSources.Manual_Input, verbose_name=_("Event source")) |
There was a problem hiding this comment.
| source = models.IntegerField(choices=EventSources.choices, default=EventSources.Manual_Input, verbose_name=_("Event source")) | |
| source = models.IntegerField(choices=EventSource.choices, default=EventSource.Manual_Input, verbose_name=_("Event source")) |
| disaster_start_date=report.start_date, | ||
| auto_generated=True, | ||
| auto_generated_source=SOURCES["new_report"], | ||
| source=Event.EventSources.NEW_REPORT, |
There was a problem hiding this comment.
| source=Event.EventSources.NEW_REPORT, | |
| source=Event.EventSource.NEW_REPORT, |
| return CountrySupportingPartner.objects.select_related("country") | ||
|
|
||
|
|
||
| class EmergencyViewset(viewsets.ReadOnlyModelViewSet): |
There was a problem hiding this comment.
We might need to use the ReadOnlyVisibilityViewset class, same as EventViewset.
| class EmergencyViewset(viewsets.ReadOnlyModelViewSet): | ||
|
|
||
| queryset = Event.objects.all() |
There was a problem hiding this comment.
| class EmergencyViewset(viewsets.ReadOnlyModelViewSet): | |
| queryset = Event.objects.all() | |
| class EmergencyViewset(viewsets.ReadOnlyModelViewSet): | |
| queryset = Event.objects.all() |
| latest_field_report_id=Subquery( | ||
| FieldReport.objects.filter(event=OuterRef("pk")).order_by("-created_at").values("id")[:1] | ||
| ), |
There was a problem hiding this comment.
We need to filter this out from the Field Report number.
Line 2304 in e96df48
| appeal_id=Subquery(Appeal.objects.filter(event=OuterRef("pk")).order_by("-created_at").values("id")[:1]), | ||
| ) |
There was a problem hiding this comment.
Check this logic against how it was done in the frontend before. @shreeyash07
| class EventSources(models.IntegerChoices): | ||
|
|
||
| Manual_Input = 100, _("Manual input") | ||
| """MANUAL_INPUT: Event data manually entered by a user through the event administration interface.""" |
There was a problem hiding this comment.
| """MANUAL_INPUT: Event data manually entered by a user through the event administration interface.""" | |
| """MANUAL_INPUT: Event data manually entered by a user through the event administration interface.""" |
| DREF = 170, _("DREF") | ||
| """DREF: Event originating records.""" | ||
|
|
||
| Unknown = 180, _("Unknown") |
There was a problem hiding this comment.
This case should not occur. If there is existing data, we may need to populate it other source but now unknown.
| latest_field_report_id = serializers.IntegerField(read_only=True) | ||
| appeal_id = serializers.IntegerField(read_only=True) |
There was a problem hiding this comment.
| latest_field_report_id = serializers.IntegerField(read_only=True) | |
| appeal_id = serializers.IntegerField(read_only=True) | |
| # NOTE: Populated from Queryset using Annotate | |
| latest_field_report_id = serializers.IntegerField(read_only=True) | |
| appeal_id = serializers.IntegerField(read_only=True) |
Changes
Checklist
Things that should succeed before merging.
Release
If there is a version update, make sure to tag the repository with the latest version.