Skip to content

Commit 2d2d2b7

Browse files
committed
Add status filter for surge-alert
1 parent d183164 commit 2d2d2b7

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

notifications/drf_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class SurgeAlertFilter(filters.FilterSet):
3333
help_text='Molnix_tag names, comma separated',
3434
widget=CSVWidget,
3535
)
36+
status = filters.NumberFilter(field_name='status', lookup_expr='exact')
3637

3738
class Meta:
3839
model = SurgeAlert

notifications/management/commands/update_alert_status.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ class Command(BaseCommand):
1818
def handle(self, *args, **options):
1919
now = timezone.now()
2020
try:
21-
SurgeAlert.objects.exclude(status=SurgeAlertStatus.CLOSED).filter(
22-
models.Q(opens__lte=now, closes__gte=now) | models.Q(is_stood_down=True)
23-
).update(
21+
SurgeAlert.objects.update(
2422
status=models.Case(
25-
models.When(opens__lte=now, closes__gte=now, then=models.Value(SurgeAlertStatus.OPEN)),
23+
models.When(closes__gte=now, then=models.Value(SurgeAlertStatus.OPEN)),
2624
models.When(closes__lt=now, then=models.Value(SurgeAlertStatus.CLOSED)),
2725
models.When(is_stood_down=True, then=models.Value(SurgeAlertStatus.STOOD_DOWN)),
2826
default=models.F('status'),

notifications/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class SurgeAlertSerializer(ModelSerializer):
1818
class Meta:
1919
model = SurgeAlert
2020
fields = (
21-
'operation', 'country', 'message', 'deployment_needed', 'is_private', 'event', 'created_at', 'id',
21+
'operation','country', 'message', 'deployment_needed', 'is_private', 'event', 'created_at', 'id',
2222
'atype', 'atype_display', 'category', 'category_display', 'molnix_id', 'molnix_tags',
23-
'molnix_status', 'opens', 'closes', 'start', 'end', 'is_active', 'is_stood_down','status_display'
23+
'molnix_status', 'opens', 'closes', 'start', 'end', 'is_active', 'is_stood_down','status', 'status_display'
2424
)
2525

2626

0 commit comments

Comments
 (0)