Skip to content
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

Hotfix for reverting Emergency title separation #2422

Merged
merged 20 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-publish-docker-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: 🐳 Helm dependency
working-directory: deploy/helm/ifrcgo-helm
run: |
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./helm/Chart.lock | sh --
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./Chart.lock | sh --
helm dependency build ./

- name: Tag docker image in Helm Chart values.yaml
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,16 @@ jobs:
- name: Install Helm
uses: azure/setup-helm@v4

- name: 🐳 Helm dependency
working-directory: deploy/helm/ifrcgo-helm
run: |
yq --indent 0 '.dependencies | map(["helm", "repo", "add", .name, .repository] | join(" ")) | .[]' ./Chart.lock | sh --
helm dependency build ./

- name: 🐳 Helm lint
run: helm lint deploy/helm/ifrcgo-helm --values ./deploy/helm/ifrcgo-helm/values-staging.yaml
working-directory: deploy/helm/ifrcgo-helm
run: helm lint ./ --values ./values-staging.yaml

- name: 🐳 Helm template
run: helm template deploy/helm/ifrcgo-helm --values ./deploy/helm/ifrcgo-helm/values-staging.yaml
working-directory: deploy/helm/ifrcgo-helm
run: helm template ./ --values ./values-staging.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WORKDIR $HOME
COPY pyproject.toml poetry.lock $HOME/

# Upgrade pip and install python packages for code
RUN pip install --upgrade --no-cache-dir pip poetry \
RUN pip install --upgrade --no-cache-dir pip "poetry>=2.1,<2.2" \
&& poetry --version \
# Configure to use system instead of virtualenvs
&& poetry config virtualenvs.create false \
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,7 @@ To import GEC codes along with country ids, run `python manage.py import-gec-cod
## SSO setup

For more info checkout [GO-SSO](./docs/go-sso.md)

## Playwright exports

For more info checkout [Playwright exports](./docs/playwright-exports.md)
7 changes: 2 additions & 5 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ class EventAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdmin):
"districts",
"parent_event",
)
readonly_fields = ("name",)

def appeals(self, instance):
if getattr(instance, "appeals").exists():
Expand All @@ -249,14 +248,12 @@ def changeform_view(self, request, *args, **kwargs):
"field_reports",
"auto_generated_source",
"parent_event",
"name",
)
else:
self.readonly_fields = (
"appeals",
"field_reports",
"auto_generated_source",
"name",
)

return super(EventAdmin, self).changeform_view(request, *args, **kwargs)
Expand Down Expand Up @@ -340,7 +337,7 @@ class FieldReportAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAd
def create_events(self, request, queryset):
for report in queryset:
event = models.Event.objects.create(
title=report.title,
name=report.summary,
dtype=getattr(report, "dtype"),
disaster_start_date=getattr(report, "created_at"),
auto_generated=True,
Expand Down Expand Up @@ -1047,5 +1044,5 @@ class ExportTokenAdmin(admin.ModelAdmin):
admin.site.register(models.CountryOfFieldReportToReview, CountryOfFieldReportToReviewAdmin)
# admin.site.register(Revision, RevisionAdmin)

admin.site.site_url = "https://" + settings.FRONTEND_URL
admin.site.site_url = settings.GO_WEB_URL
admin.widgets.RelatedFieldWidgetWrapper.template_name = "related_widget_wrapper.html"
1 change: 0 additions & 1 deletion api/factories/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Meta:
model = Event

name = fuzzy.FuzzyText(length=50)
title = fuzzy.FuzzyText(length=10)
slug = fuzzy.FuzzyText(length=50)
dtype = factory.SubFactory(DisasterTypeFactory)

Expand Down
2 changes: 1 addition & 1 deletion api/management/commands/cron_job_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def handle(self, *args, **options):
project_id = parsed_url.path.strip("/")
api_key = parsed_url.username

SENTRY_INGEST = f"https://{parsed_url.hostname}"
SENTRY_INGEST = f"{parsed_url.scheme}://{parsed_url.hostname}"

for cronjob in SentryMonitor.choices:
job, schedule = cronjob
Expand Down
8 changes: 4 additions & 4 deletions api/management/commands/index_and_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def get_admin_uri(self, record, rtype):
RecordType.SURGE_DEPLOYMENT_MESSAGES: "deployments/personneldeployment",
RecordType.SURGE_ALERT: "notifications/surgealert",
}[rtype]
return "https://%s/admin/%s/%s/change" % (
settings.BASE_URL,
return "%s/admin/%s/%s/change" % (
settings.GO_API_URL,
admin_page,
record.id,
)
Expand Down Expand Up @@ -960,8 +960,8 @@ def check_ingest_issues(self, having_ingest_issue):
(
"Ingest issue(s) occured, one of them is "
+ ingestor_name
+ ", via CronJob log record id: https://"
+ settings.BASE_URL
+ ", via CronJob log record id: "
+ settings.GO_API_URL
+ "/admin/api/cronjob/"
+ str(ingest_issue_id)
+ ". Please fix it ASAP."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Generated by Django 4.2.17 on 2025-02-20 09:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0217_merge_20250107_1019"),
]

operations = [
migrations.RemoveField(
model_name="event",
name="title",
),
migrations.RemoveField(
model_name="event",
name="title_ar",
),
migrations.RemoveField(
model_name="event",
name="title_en",
),
migrations.RemoveField(
model_name="event",
name="title_es",
),
migrations.RemoveField(
model_name="event",
name="title_fr",
),
migrations.AlterField(
model_name="fieldreport",
name="title",
field=models.CharField(
blank=True,
help_text="Title is used to generate the summary/name of the Field Report. </br>The summary is constructed as: <b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>",
max_length=256,
),
),
migrations.AlterField(
model_name="fieldreport",
name="title_ar",
field=models.CharField(
blank=True,
help_text="Title is used to generate the summary/name of the Field Report. </br>The summary is constructed as: <b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>",
max_length=256,
null=True,
),
),
migrations.AlterField(
model_name="fieldreport",
name="title_en",
field=models.CharField(
blank=True,
help_text="Title is used to generate the summary/name of the Field Report. </br>The summary is constructed as: <b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>",
max_length=256,
null=True,
),
),
migrations.AlterField(
model_name="fieldreport",
name="title_es",
field=models.CharField(
blank=True,
help_text="Title is used to generate the summary/name of the Field Report. </br>The summary is constructed as: <b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>",
max_length=256,
null=True,
),
),
migrations.AlterField(
model_name="fieldreport",
name="title_fr",
field=models.CharField(
blank=True,
help_text="Title is used to generate the summary/name of the Field Report. </br>The summary is constructed as: <b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>",
max_length=256,
null=True,
),
),
]
68 changes: 28 additions & 40 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,16 @@ class Event(models.Model):
"""A disaster, which could cover multiple countries"""

name = models.CharField(verbose_name=_("name"), max_length=256)
dtype = models.ForeignKey(DisasterType, verbose_name=_("disaster type"), null=True, on_delete=models.SET_NULL)
disaster_start_date = models.DateTimeField(verbose_name=_("disaster start date"))
regions = models.ManyToManyField(Region, verbose_name=_("regions"))
countries = models.ManyToManyField(Country, verbose_name=_("countries"))
countries_for_preview = models.ManyToManyField(
Country, verbose_name=_("countries for preview"), blank=True, related_name="countries_for_preview"
)
districts = models.ManyToManyField(District, verbose_name=_("districts"), blank=True)
# visibility
visibility = models.IntegerField(choices=VisibilityChoices.choices, verbose_name=_("visibility"), default=1)
# Obsolete: slug is not editable until we resolve https://github.com/IFRCGo/go-frontend/issues/1013
slug = models.CharField(
verbose_name=_("slug"),
Expand All @@ -758,13 +768,6 @@ class Event(models.Model):
" Recommend using hyphens over underscores. Special characters like # is not allowed."
),
)
dtype = models.ForeignKey(DisasterType, verbose_name=_("disaster type"), null=True, on_delete=models.SET_NULL)
districts = models.ManyToManyField(District, verbose_name=_("districts"), blank=True)
countries = models.ManyToManyField(Country, verbose_name=_("countries"))
countries_for_preview = models.ManyToManyField(
Country, verbose_name=_("countries for preview"), blank=True, related_name="countries_for_preview"
)
regions = models.ManyToManyField(Region, verbose_name=_("regions"))
parent_event = models.ForeignKey(
"self",
null=True,
Expand All @@ -778,7 +781,6 @@ class Event(models.Model):
)
image = models.ImageField(verbose_name=_("image"), null=True, blank=True, upload_to=snippet_image_path)
summary = HTMLField(verbose_name=_("summary"), blank=True, default="")
title = models.CharField(max_length=256, blank=True)

num_injured = models.IntegerField(verbose_name=_("number of injured"), null=True, blank=True)
num_dead = models.IntegerField(verbose_name=_("number of dead"), null=True, blank=True)
Expand All @@ -789,7 +791,6 @@ class Event(models.Model):
ifrc_severity_level = models.IntegerField(choices=AlertLevel.choices, default=0, verbose_name=_("IFRC Severity level"))
glide = models.CharField(verbose_name=_("glide"), max_length=18, blank=True)

disaster_start_date = models.DateTimeField(verbose_name=_("disaster start date"))
created_at = models.DateTimeField(verbose_name=_("created at"), auto_now_add=True)
updated_at = models.DateTimeField(verbose_name=_("updated at"), auto_now=True)
previous_update = models.DateTimeField(verbose_name=_("previous update"), null=True, blank=True)
Expand All @@ -816,8 +817,6 @@ class Event(models.Model):
tab_two_title = models.CharField(verbose_name=_("tab two title"), max_length=50, null=True, blank=True)
tab_three_title = models.CharField(verbose_name=_("tab three title"), max_length=50, null=True, blank=True)

# visibility
visibility = models.IntegerField(choices=VisibilityChoices.choices, verbose_name=_("visibility"), default=1)
emergency_response_contact_email = models.CharField(
verbose_name=_("emergency response contact email"), null=True, blank=True, max_length=255
)
Expand Down Expand Up @@ -873,15 +872,6 @@ def record_type(self):
def to_dict(self):
return to_dict(self)

def generate_formatted_name(self):
country_iso3 = self.countries.first().iso3 if self.id and self.countries.first() else "N/A"
disaster_start_date = self.disaster_start_date.strftime("%m-%Y")
for lang in AVAILABLE_LANGUAGES:
with translation_override(lang):
dtype = self.dtype.name if self.dtype else "N/A"
self.name = f"{country_iso3}: {dtype} - {disaster_start_date} - {self.title}"
yield build_localized_fieldname("name", lang)

def save(self, *args, **kwargs):

# Make the slug lowercase
Expand All @@ -892,15 +882,6 @@ def save(self, *args, **kwargs):
if not self.id and not self.disaster_start_date:
self.disaster_start_date = timezone.now()

updated_name_fields = list(self.generate_formatted_name())

# Updating the updated_fields with the fields that are updated
if kwargs.get("update_fields"):
kwargs["update_fields"] = (
*kwargs["update_fields"],
*updated_name_fields,
)

return super(Event, self).save(*args, **kwargs)

def __str__(self):
Expand Down Expand Up @@ -1479,21 +1460,31 @@ class RecentAffected(models.IntegerChoices):
default=False,
help_text=_("Is this a Field Report specific to the COVID-19 emergency?"),
)

# Used to differentiate reports that have and have not been synced from DMIS
rid = models.CharField(verbose_name=_("r id"), max_length=100, null=True, blank=True, editable=False)
summary = models.TextField(verbose_name=_("summary"), blank=True)
# Title field is used for the translation and later adding formated into the summary
title = models.CharField(max_length=256, blank=True)
fr_num = models.IntegerField(verbose_name=_("field report number"), null=True, blank=True)
title = models.CharField(
max_length=256,
blank=True,
help_text=_(
"Title is used to generate the summary/name of the Field Report. </br>"
"The summary is constructed as: "
"<b><i>Country IS03: Disaster Type - Start Date - Title - Field Report Number - (date)</b><i>"
),
)
description = HTMLField(verbose_name=_("description"), blank=True, default="")
dtype = models.ForeignKey(DisasterType, verbose_name=_("disaster type"), on_delete=models.PROTECT)
event = models.ForeignKey(
Event, verbose_name=_("event"), related_name="field_reports", null=True, blank=True, on_delete=models.SET_NULL
)
districts = models.ManyToManyField(District, verbose_name=_("districts"), blank=True)
countries = models.ManyToManyField(Country, verbose_name=_("countries"))
regions = models.ManyToManyField(Region, verbose_name=_("regions"), blank=True)
countries = models.ManyToManyField(Country, verbose_name=_("countries"))
districts = models.ManyToManyField(District, verbose_name=_("districts"), blank=True)
# visibility
visibility = models.IntegerField(choices=VisibilityChoices.choices, verbose_name=_("visibility"), default=1)
# Used to differentiate reports that have and have not been synced from DMIS
rid = models.CharField(verbose_name=_("r id"), max_length=100, null=True, blank=True, editable=False)
summary = models.TextField(verbose_name=_("summary"), blank=True)

fr_num = models.IntegerField(verbose_name=_("field report number"), null=True, blank=True)
# This entity is more a type than a status, so let's label it this way on admin page:
status = models.IntegerField(
choices=Status.choices,
Expand Down Expand Up @@ -1582,9 +1573,6 @@ class RecentAffected(models.IntegerChoices):
# actions taken
actions_others = models.TextField(verbose_name=_("actions taken (others)"), null=True, blank=True)

# visibility
visibility = models.IntegerField(choices=VisibilityChoices.choices, verbose_name=_("visibility"), default=1)

# information
bulletin = models.IntegerField(choices=RequestChoices.choices, verbose_name=_("bulletin"), default=0, null=True)
dref = models.IntegerField(choices=RequestChoices.choices, verbose_name=_("DREF"), default=0, null=True)
Expand Down
9 changes: 0 additions & 9 deletions api/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,6 @@ def remove_appeal_filter(sender, instance, using, **kwargs):
appealFilter.save()


@receiver(m2m_changed, sender=Event.countries.through)
def update_event_name(sender, instance, action, **kwargs):
"""
Update the event name when the countries are changed.
"""
if action in ["post_add", "post_remove"]:
instance.save()


@receiver(m2m_changed, sender=FieldReport.countries.through)
def update_fieldreport_summary(sender, instance, action, **kwargs):
"""
Expand Down
8 changes: 3 additions & 5 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,6 @@ class Meta:
"dtype",
"countries",
"summary",
"title",
"num_affected",
"ifrc_severity_level",
"ifrc_severity_level_display",
Expand Down Expand Up @@ -1300,7 +1299,6 @@ class Meta:
"countries",
"districts",
"summary",
"title",
"num_affected",
"tab_two_title",
"tab_three_title",
Expand Down Expand Up @@ -2058,7 +2056,7 @@ class Meta:

def create_event(self, report):
event = Event.objects.create(
title=report.title,
name=report.summary,
dtype=report.dtype,
summary=report.description or "",
disaster_start_date=report.start_date,
Expand Down Expand Up @@ -2438,9 +2436,9 @@ def create(self, validated_data):
title = "Export"
user = self.context["request"].user
if export_type == Export.ExportType.PER:
validated_data["url"] = f"https://{settings.FRONTEND_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
else:
validated_data["url"] = f"https://{settings.FRONTEND_URL}/{export_type}/{export_id}/export/"
validated_data["url"] = f"{settings.GO_WEB_INTERNAL_URL}/{export_type}/{export_id}/export/"

# Adding is_pga to the url
is_pga = validated_data.pop("is_pga")
Expand Down
Loading
Loading