-
Notifications
You must be signed in to change notification settings - Fork 9
DEP: Add emergency api endpoint #2723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: project/dref-emergency-pages
Are you sure you want to change the base?
Changes from all commits
de1fd13
6ba65e2
8464a7d
da0d8c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,6 +89,7 @@ | |||||||||||
| Export, | ||||||||||||
| ExternalPartner, | ||||||||||||
| FieldReport, | ||||||||||||
| KeyFigure, | ||||||||||||
| MainContact, | ||||||||||||
| Profile, | ||||||||||||
| Region, | ||||||||||||
|
|
@@ -122,6 +123,7 @@ | |||||||||||
| CountrySupportingPartnerSerializer, | ||||||||||||
| CountryTableauSerializer, | ||||||||||||
| DeploymentsByEventSerializer, | ||||||||||||
| DetailEmergencySerializer, | ||||||||||||
| DetailEventSerializer, | ||||||||||||
| DisasterTypeSerializer, | ||||||||||||
| DistrictSerializer, | ||||||||||||
|
|
@@ -751,7 +753,7 @@ def get_queryset(self, *args, **kwargs): | |||||||||||
| if self.action == "response_activity_events": | ||||||||||||
| return ( | ||||||||||||
| qset.filter(parent_event__isnull=True) | ||||||||||||
| .filter(Q(auto_generated=False) | Q(auto_generated_source="New field report")) | ||||||||||||
| .filter(Q(auto_generated=False) | Q(source=Event.EventSources.NEW_REPORT)) | ||||||||||||
| .select_related("dtype") | ||||||||||||
| ) | ||||||||||||
| return ( | ||||||||||||
|
|
@@ -1344,7 +1346,7 @@ class SupportedActivityViewset(viewsets.ReadOnlyModelViewSet): | |||||||||||
| # summary=report.description or "", | ||||||||||||
| # disaster_start_date=report.start_date, | ||||||||||||
| # auto_generated=True, | ||||||||||||
| # auto_generated_source=SOURCES["new_report"], | ||||||||||||
| # source=Event.EventSources.NEW_REPORT, | ||||||||||||
| # visibility=report.visibility, | ||||||||||||
| # **{TRANSLATOR_ORIGINAL_LANGUAGE_FIELD_NAME: django_get_language()}, | ||||||||||||
| # ) | ||||||||||||
|
|
@@ -1542,3 +1544,34 @@ class CountrySupportingPartnerViewSet(viewsets.ModelViewSet): | |||||||||||
|
|
||||||||||||
| def get_queryset(self): | ||||||||||||
| return CountrySupportingPartner.objects.select_related("country") | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class EmergencyViewset(viewsets.ReadOnlyModelViewSet): | ||||||||||||
|
|
||||||||||||
| queryset = Event.objects.all() | ||||||||||||
|
Comment on lines
+1549
to
+1551
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| lookup_field = "id" | ||||||||||||
| serializer_class = DetailEmergencySerializer | ||||||||||||
| filterset_class = EventFilter | ||||||||||||
|
|
||||||||||||
| def get_queryset(self): | ||||||||||||
| return ( | ||||||||||||
| super() | ||||||||||||
| .get_queryset() | ||||||||||||
| .select_related( | ||||||||||||
| "dtype", | ||||||||||||
| "parent_event", | ||||||||||||
| ) | ||||||||||||
| .prefetch_related( | ||||||||||||
| "regions", | ||||||||||||
| "countries", | ||||||||||||
| "countries_for_preview", | ||||||||||||
| Prefetch("key_figures", queryset=KeyFigure.objects.all()), | ||||||||||||
| Prefetch("contacts", queryset=EventContact.objects.all()), | ||||||||||||
| ) | ||||||||||||
| .annotate( | ||||||||||||
| latest_field_report_id=Subquery( | ||||||||||||
| FieldReport.objects.filter(event=OuterRef("pk")).order_by("-created_at").values("id")[:1] | ||||||||||||
| ), | ||||||||||||
|
Comment on lines
+1572
to
+1574
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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]), | ||||||||||||
| ) | ||||||||||||
|
Comment on lines
+1575
to
+1576
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||
| ) | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def migrate_sources(apps, schema_editor): | ||
| """ | ||
| Populate the source field for Event records: | ||
| - Non auto generated events are mapped to MANUAL_INPUT | ||
| - Events that are auto generated and have auto_generated_source are mapped to the corresponding enum value | ||
| - Events that are auto generated and auto_generated_source is null or unrecognized are mapped to UNKNOWN | ||
| """ | ||
|
|
||
| Model = apps.get_model("api", "Event") | ||
| for obj in Model.objects.iterator(): | ||
| if not obj.auto_generated: | ||
| value = 100 | ||
|
|
||
| else: | ||
| src = (obj.auto_generated_source or "").lower() | ||
|
|
||
| if "who.int" in src: | ||
| value = 120 | ||
| elif "gdacs" in src: | ||
| value = 110 | ||
| elif "field report dmis ingest" in src: | ||
| value = 130 | ||
| elif "field report admin" in src: | ||
| value = 140 | ||
| elif "appeal" in src: | ||
| value = 150 | ||
| elif "new field report" in src: | ||
| value = 160 | ||
| else: | ||
| value = 180 | ||
|
|
||
| obj.source = value | ||
| obj.save(update_fields=["source"]) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('api', '0230_alter_districtgeoms_district'), | ||
| ] | ||
|
|
||
| operations = [ | ||
|
|
||
| migrations.AddField( | ||
| model_name='event', | ||
| name='source', | ||
| field=models.IntegerField(choices=[(100, 'Manual input'), (110, 'GDACs scraper'), (120, 'WHO scraper'), (130, 'Field report DMIS ingest'), (140, 'Field report admin'), (150, 'Appeal admin'), (160, 'New field report'), (170, 'DREF'), (180, 'Unknown')], default=100, verbose_name='Event source'), | ||
| ), | ||
| migrations.RunPython(migrate_sources,reverse_code=migrations.RunPython.noop), | ||
|
|
||
| migrations.RemoveField( | ||
| model_name='event', | ||
| name='auto_generated_source', | ||
| ), | ||
| ] |
There was a problem hiding this comment.
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
ReadOnlyVisibilityViewsetclass, same as EventViewset.