Skip to content

DEP: Add emergency api endpoint#2723

Draft
sudip-khanal wants to merge 4 commits intoproject/dref-emergency-pagesfrom
feat/add-emergency-api-endpoint
Draft

DEP: Add emergency api endpoint#2723
sudip-khanal wants to merge 4 commits intoproject/dref-emergency-pagesfrom
feat/add-emergency-api-endpoint

Conversation

@sudip-khanal
Copy link
Copy Markdown
Contributor

Changes

  • Add source Enum field in place of auto generated source field on event model.
  • Migrate existing event records to enum type.
  • Update related serializer and tests.
  • Add new emergency api endpoint.
  • Attach latest field report to emergency api endpoint.

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

- 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.
@sudip-khanal sudip-khanal requested a review from susilnem April 24, 2026 10:36
Comment thread api/models.py
class Event(models.Model):
"""A disaster, which could cover multiple countries"""

class EventSources(models.IntegerChoices):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class EventSources(models.IntegerChoices):
class EventSource(models.IntegerChoices):

Comment thread api/models.py
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"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"))

Comment thread api/serializers.py
disaster_start_date=report.start_date,
auto_generated=True,
auto_generated_source=SOURCES["new_report"],
source=Event.EventSources.NEW_REPORT,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
source=Event.EventSources.NEW_REPORT,
source=Event.EventSource.NEW_REPORT,

Comment thread api/drf_views.py
return CountrySupportingPartner.objects.select_related("country")


class EmergencyViewset(viewsets.ReadOnlyModelViewSet):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to use the ReadOnlyVisibilityViewset class, same as EventViewset.

Comment thread api/drf_views.py
Comment on lines +1549 to +1551
class EmergencyViewset(viewsets.ReadOnlyModelViewSet):

queryset = Event.objects.all()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class EmergencyViewset(viewsets.ReadOnlyModelViewSet):
queryset = Event.objects.all()
class EmergencyViewset(viewsets.ReadOnlyModelViewSet):
queryset = Event.objects.all()

Comment thread api/drf_views.py
Comment on lines +1572 to +1574
latest_field_report_id=Subquery(
FieldReport.objects.filter(event=OuterRef("pk")).order_by("-created_at").values("id")[:1]
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to filter this out from the Field Report number.

fr_num = models.IntegerField(verbose_name=_("field report number"), null=True, blank=True)

Comment thread api/drf_views.py
Comment on lines +1575 to +1576
appeal_id=Subquery(Appeal.objects.filter(event=OuterRef("pk")).order_by("-created_at").values("id")[:1]),
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this logic against how it was done in the frontend before. @shreeyash07

Comment thread api/models.py
class EventSources(models.IntegerChoices):

Manual_Input = 100, _("Manual input")
"""MANUAL_INPUT: Event data manually entered by a user through the event administration interface."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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."""

Comment thread api/models.py
DREF = 170, _("DREF")
"""DREF: Event originating records."""

Unknown = 180, _("Unknown")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should not occur. If there is existing data, we may need to populate it other source but now unknown.

Comment thread api/serializers.py
Comment on lines +2613 to +2614
latest_field_report_id = serializers.IntegerField(read_only=True)
appeal_id = serializers.IntegerField(read_only=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants