-
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
Draft
sudip-khanal
wants to merge
4
commits into
project/dref-emergency-pages
Choose a base branch
from
feat/add-emergency-api-endpoint
base: project/dref-emergency-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
89231d1
feat(event): make event source enum
sudip-khanal a40688d
feat(api): add new api endpoint for emergency
sudip-khanal d1ede06
feat(api): add related appeal id on emergency api endpoint
sudip-khanal efb86d8
feat(api): add script to update event source
sudip-khanal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ class Command(BaseCommand): | |||
| help = "Add new event (=emergency) entries from WHO API" | ||||
|
|
||||
| def handle(self, *args, **options): | ||||
| guids = [e.auto_generated_source for e in Event.objects.filter(auto_generated_source__startswith="www.who.int")] | ||||
| guids = [e.source for e in Event.objects.filter(source=Event.EventSource.WHO)] | ||||
|
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. Can you confirm this? It looks like GUIDs are being used for mapping, but they might not match when scraping from the source.
|
||||
|
|
||||
| logger.info("Querying WHO RSS feed for new emergency data") | ||||
| # get latest | ||||
|
|
@@ -131,7 +131,7 @@ def handle(self, *args, **options): | |||
| "summary": summary, | ||||
| "disaster_start_date": date, | ||||
| "auto_generated": True, | ||||
| "auto_generated_source": data["guid"], | ||||
| "source": Event.EventSource.WHO, | ||||
| "ifrc_severity_level": alert_level, | ||||
| } | ||||
| # TODO: fields['name'] sometimes exceeds 100 maxlength, so will need some altering if this will be used | ||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||
| from django.core.management.base import BaseCommand | ||||||||||
|
|
||||||||||
| from api.models import Event | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class Command(BaseCommand): | ||||||||||
| help = "Update event sources based on name prefix and auto-generated status" | ||||||||||
|
|
||||||||||
| def handle(self, *args, **options): | ||||||||||
| queryset = Event.objects.filter(auto_generated=True, source=0) | ||||||||||
| self.stdout.write( | ||||||||||
| self.style.NOTICE( | ||||||||||
| f"{queryset.count()} events will be assigned a source (GDACS or Manual Input) based on name prefix." | ||||||||||
| ) | ||||||||||
| ) | ||||||||||
| to_update = [] | ||||||||||
| for event in queryset.iterator(): | ||||||||||
| if event.name.startswith("GDACS"): | ||||||||||
| event.source = Event.EventSource.GDACS | ||||||||||
| else: | ||||||||||
| event.source = Event.EventSource.Manual_Input | ||||||||||
| event.auto_generated = False | ||||||||||
| to_update.append(event) | ||||||||||
|
|
||||||||||
| Event.objects.bulk_update(to_update, ["source", "auto_generated"]) | ||||||||||
| self.stdout.write(self.style.SUCCESS("Event sources have been updated successfully.")) | ||||||||||
|
Comment on lines
+25
to
+26
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
|
||||||||||
58 changes: 58 additions & 0 deletions
58
api/migrations/0231_remove_event_auto_generated_source_event_source.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Generated by Django 4.2.29 on 2026-04-29 05:48 | ||
|
|
||
| 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. | ||
| - 0 is temporary placeholder for unmapped/unknown auto-generated sources that will be reclassified into proper EventSource via `migrate_event_source` command. | ||
| """ | ||
|
|
||
| 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 "gdacs" in src: | ||
| value = 110 | ||
| elif "who.int" in src: | ||
| value = 120 | ||
| 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 = 0 | ||
| 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')], default=100, verbose_name='Event source'), | ||
| ), | ||
| migrations.RunPython(migrate_sources,reverse_code=migrations.RunPython.noop), | ||
|
|
||
| migrations.RemoveField( | ||
| model_name='event', | ||
| name='auto_generated_source', | ||
| ), | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.