From 17e1c57b859e663cd3c026dbee331ca8348b2997 Mon Sep 17 00:00:00 2001 From: rup-narayan-rajbanshi Date: Thu, 25 Jul 2024 17:25:06 +0545 Subject: [PATCH] Remove is_active, is_stood_down from SurgeAlert model. --- api/management/commands/sync_molnix.py | 4 ++-- notifications/admin.py | 6 +++--- notifications/drf_views.py | 3 +-- ...16_remove_surgealert_is_active_and_more.py | 21 +++++++++++++++++++ notifications/models.py | 5 ----- notifications/serializers.py | 1 - 6 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 notifications/migrations/0016_remove_surgealert_is_active_and_more.py diff --git a/api/management/commands/sync_molnix.py b/api/management/commands/sync_molnix.py index a3d1c98a5..c2081cc60 100644 --- a/api/management/commands/sync_molnix.py +++ b/api/management/commands/sync_molnix.py @@ -490,7 +490,7 @@ def sync_open_positions(molnix_positions, molnix_api, countries): successful_updates += 1 # Find existing active alerts that are not in the current list from Molnix - existing_alerts = SurgeAlert.objects.filter(SurgeAlertStatus.OPEN).exclude(molnix_id__isnull=True) + existing_alerts = SurgeAlert.objects.filter(molnix_status=SurgeAlertStatus.OPEN).exclude(molnix_id__isnull=True) existing_alert_ids = [e.molnix_id for e in existing_alerts] inactive_alerts = list(set(existing_alert_ids) - set(molnix_ids)) @@ -502,7 +502,7 @@ def sync_open_positions(molnix_positions, molnix_api, countries): position = molnix_api.get_position(alert.molnix_id) if not position: warnings.append("Position id %d not found in Molnix API" % alert.molnix_id) - if position and position["status"].lower(): + if position and position["status"]: alert.molnix_status = SurgeAlert.parse_molnix_status(position["status"]) if position and position["closes"]: alert.closes = get_datetime(position["closes"]) diff --git a/notifications/admin.py b/notifications/admin.py index 3d6e9df0a..71ad1d475 100644 --- a/notifications/admin.py +++ b/notifications/admin.py @@ -11,7 +11,7 @@ class SurgeAlertAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdm @admin.display(description="std") def std(self, obj): - return obj.is_stood_down + return obj.molnix_status == models.SurgeAlertStatus.STOOD_DOWN std.boolean = True country_in = "event__countries__in" @@ -22,9 +22,9 @@ def std(self, obj): "message", "event__name", ) - readonly_fields = ("molnix_id", "is_stood_down") + readonly_fields = ("molnix_id",) list_display = ("__str__", "message", "start", "molnix_id", "molnix_status", "std") - list_filter = ("molnix_status", "is_stood_down") + list_filter = ("molnix_status",) class SubscriptionAdmin(CompareVersionAdmin): diff --git a/notifications/drf_views.py b/notifications/drf_views.py index 54cf69c5e..cacec13c2 100644 --- a/notifications/drf_views.py +++ b/notifications/drf_views.py @@ -48,7 +48,6 @@ class Meta: "created_at": ("exact", "gt", "gte", "lt", "lte"), "start": ("exact", "gt", "gte", "lt", "lte"), "end": ("exact", "gt", "gte", "lt", "lte"), - "is_stood_down": ("exact",), "molnix_id": ("exact", "in"), "message": ("exact", "in"), "country": ("exact", "in"), @@ -66,7 +65,7 @@ class SurgeAlertViewset(viewsets.ReadOnlyModelViewSet): authentication_classes = (TokenAuthentication,) queryset = SurgeAlert.objects.prefetch_related("molnix_tags", "molnix_tags__groups").select_related("event", "country").all() filterset_class = SurgeAlertFilter - ordering_fields = ("created_at", "atype", "category", "event", "is_stood_down", "molnix_status", "opens") + ordering_fields = ("created_at", "atype", "category", "event", "molnix_status", "opens") search_fields = ( "operation", "message", diff --git a/notifications/migrations/0016_remove_surgealert_is_active_and_more.py b/notifications/migrations/0016_remove_surgealert_is_active_and_more.py new file mode 100644 index 000000000..c13194dcf --- /dev/null +++ b/notifications/migrations/0016_remove_surgealert_is_active_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.13 on 2024-07-25 11:38 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("notifications", "0015_rename_molnix_status_surgealert_molnix_status_old"), + ] + + operations = [ + migrations.RemoveField( + model_name="surgealert", + name="is_active", + ), + migrations.RemoveField( + model_name="surgealert", + name="is_stood_down", + ), + ] diff --git a/notifications/models.py b/notifications/models.py index 55db8120c..e717fada6 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -49,17 +49,12 @@ class SurgeAlert(models.Model): # ID in Molnix system, if parsed from Molnix. molnix_id = models.IntegerField(blank=True, null=True) - # It depends on molnix_status. Check "save" method below. - is_stood_down = models.BooleanField(verbose_name=_("is stood down?"), default=False) opens = models.DateTimeField(blank=True, null=True) closes = models.DateTimeField(blank=True, null=True) start = models.DateTimeField(blank=True, null=True) end = models.DateTimeField(blank=True, null=True) molnix_tags = models.ManyToManyField(MolnixTag, blank=True) - # Set to inactive when position is no longer in Molnix - is_active = models.BooleanField(default=True) - # Don't set `auto_now_add` so we can modify it on save created_at = models.DateTimeField(verbose_name=_("created at")) molnix_status = models.IntegerField( diff --git a/notifications/serializers.py b/notifications/serializers.py index 2faeb4630..d8196bd82 100644 --- a/notifications/serializers.py +++ b/notifications/serializers.py @@ -41,7 +41,6 @@ class Meta: "closes", "start", "end", - "is_stood_down", "molnix_status", "molnix_status_display", )