Skip to content

Commit 0ca4fe8

Browse files
Remove is_active, is_stood_down from SurgeAlert model.
1 parent cacaa13 commit 0ca4fe8

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

api/management/commands/sync_molnix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def sync_open_positions(molnix_positions, molnix_api, countries):
490490
successful_updates += 1
491491

492492
# Find existing active alerts that are not in the current list from Molnix
493-
existing_alerts = SurgeAlert.objects.filter(SurgeAlertStatus.OPEN).exclude(molnix_id__isnull=True)
493+
existing_alerts = SurgeAlert.objects.filter(molnix_status=SurgeAlertStatus.OPEN).exclude(molnix_id__isnull=True)
494494
existing_alert_ids = [e.molnix_id for e in existing_alerts]
495495
inactive_alerts = list(set(existing_alert_ids) - set(molnix_ids))
496496

@@ -502,7 +502,7 @@ def sync_open_positions(molnix_positions, molnix_api, countries):
502502
position = molnix_api.get_position(alert.molnix_id)
503503
if not position:
504504
warnings.append("Position id %d not found in Molnix API" % alert.molnix_id)
505-
if position and position["status"].lower():
505+
if position and position["status"]:
506506
alert.molnix_status = SurgeAlert.parse_molnix_status(position["status"])
507507
if position and position["closes"]:
508508
alert.closes = get_datetime(position["closes"])

notifications/admin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SurgeAlertAdmin(CompareVersionAdmin, RegionRestrictedAdmin, TranslationAdm
1111

1212
@admin.display(description="std")
1313
def std(self, obj):
14-
return obj.is_stood_down
14+
return obj.molnix_status == models.SurgeAlertStatus.STOOD_DOWN
1515

1616
std.boolean = True
1717
country_in = "event__countries__in"
@@ -22,9 +22,9 @@ def std(self, obj):
2222
"message",
2323
"event__name",
2424
)
25-
readonly_fields = ("molnix_id", "is_stood_down")
25+
readonly_fields = ("molnix_id",)
2626
list_display = ("__str__", "message", "start", "molnix_id", "molnix_status", "std")
27-
list_filter = ("molnix_status", "is_stood_down")
27+
list_filter = ("molnix_status",)
2828

2929

3030
class SubscriptionAdmin(CompareVersionAdmin):

notifications/drf_views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Meta:
4949
"created_at": ("exact", "gt", "gte", "lt", "lte"),
5050
"start": ("exact", "gt", "gte", "lt", "lte"),
5151
"end": ("exact", "gt", "gte", "lt", "lte"),
52-
"is_stood_down": ("exact",),
5352
"molnix_id": ("exact", "in"),
5453
"message": ("exact", "in"),
5554
"country": ("exact", "in"),
@@ -67,7 +66,7 @@ class SurgeAlertViewset(viewsets.ReadOnlyModelViewSet):
6766
authentication_classes = (TokenAuthentication,)
6867
queryset = SurgeAlert.objects.prefetch_related("molnix_tags", "molnix_tags__groups").select_related("event", "country").all()
6968
filterset_class = SurgeAlertFilter
70-
ordering_fields = ("created_at", "atype", "category", "event", "is_stood_down", "molnix_status", "opens")
69+
ordering_fields = ("created_at", "atype", "category", "event", "molnix_status", "opens")
7170
search_fields = (
7271
"operation",
7372
"message",
@@ -80,6 +79,10 @@ def get_serializer_class(self):
8079
# return UnauthenticatedSurgeAlertSerializer
8180
return SurgeAlertSerializer
8281

82+
def get_queryset(self):
83+
queryset = self.get_queryset()
84+
return queryset.filter(molnix_id__isnull=False).exclude(molnix_tags__name="NO_GO")
85+
8386

8487
# def get_queryset(self):
8588
# # limit = 14 # days

notifications/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Meta:
99
model = SurgeAlert
1010

1111
message = fuzzy.FuzzyText(length=100)
12+
molnix_id = fuzzy.FuzzyInteger(low=1)
1213
atype = fuzzy.FuzzyInteger(low=1)
1314
category = fuzzy.FuzzyInteger(low=1)
1415
molnix_status = fuzzy.FuzzyChoice(choices=SurgeAlertStatus)

notifications/migrations/0015_rename_molnix_status_surgealert_molnix_status_old.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ class Migration(migrations.Migration):
1919
old_name="status",
2020
new_name="molnix_status",
2121
),
22+
migrations.RemoveField(
23+
model_name="surgealert",
24+
name="is_active",
25+
),
26+
migrations.RemoveField(
27+
model_name="surgealert",
28+
name="is_stood_down",
29+
),
2230
]

notifications/models.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,12 @@ class SurgeAlert(models.Model):
4949
# ID in Molnix system, if parsed from Molnix.
5050
molnix_id = models.IntegerField(blank=True, null=True)
5151

52-
# It depends on molnix_status. Check "save" method below.
53-
is_stood_down = models.BooleanField(verbose_name=_("is stood down?"), default=False)
5452
opens = models.DateTimeField(blank=True, null=True)
5553
closes = models.DateTimeField(blank=True, null=True)
5654
start = models.DateTimeField(blank=True, null=True)
5755
end = models.DateTimeField(blank=True, null=True)
5856
molnix_tags = models.ManyToManyField(MolnixTag, blank=True)
5957

60-
# Set to inactive when position is no longer in Molnix
61-
is_active = models.BooleanField(default=True)
62-
6358
# Don't set `auto_now_add` so we can modify it on save
6459
created_at = models.DateTimeField(verbose_name=_("created at"))
6560
molnix_status = models.IntegerField(

notifications/serializers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class Meta:
4141
"closes",
4242
"start",
4343
"end",
44-
"is_stood_down",
4544
"molnix_status",
4645
"molnix_status_display",
4746
)

0 commit comments

Comments
 (0)