Skip to content

Commit

Permalink
Remove is_active, is_stood_down from SurgeAlert model.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Jul 26, 2024
1 parent 13c9692 commit 17e1c57
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/management/commands/sync_molnix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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"])
Expand Down
6 changes: 3 additions & 3 deletions notifications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions notifications/drf_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
]
5 changes: 0 additions & 5 deletions notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion notifications/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Meta:
"closes",
"start",
"end",
"is_stood_down",
"molnix_status",
"molnix_status_display",
)
Expand Down

0 comments on commit 17e1c57

Please sign in to comment.