diff --git a/notifications/drf_views.py b/notifications/drf_views.py index 3c12c20ee..90178cf94 100644 --- a/notifications/drf_views.py +++ b/notifications/drf_views.py @@ -33,6 +33,7 @@ class SurgeAlertFilter(filters.FilterSet): help_text='Molnix_tag names, comma separated', widget=CSVWidget, ) + status = filters.NumberFilter(field_name='status', lookup_expr='exact') class Meta: model = SurgeAlert diff --git a/notifications/management/commands/update_alert_status.py b/notifications/management/commands/update_alert_status.py index 3b0e6dd21..0bdd76cb0 100644 --- a/notifications/management/commands/update_alert_status.py +++ b/notifications/management/commands/update_alert_status.py @@ -18,11 +18,9 @@ class Command(BaseCommand): def handle(self, *args, **options): now = timezone.now() try: - SurgeAlert.objects.exclude(status=SurgeAlertStatus.CLOSED).filter( - models.Q(opens__lte=now, closes__gte=now) | models.Q(is_stood_down=True) - ).update( + SurgeAlert.objects.update( status=models.Case( - models.When(opens__lte=now, closes__gte=now, then=models.Value(SurgeAlertStatus.OPEN)), + models.When(closes__gte=now, then=models.Value(SurgeAlertStatus.OPEN)), models.When(closes__lt=now, then=models.Value(SurgeAlertStatus.CLOSED)), models.When(is_stood_down=True, then=models.Value(SurgeAlertStatus.STOOD_DOWN)), default=models.F('status'), diff --git a/notifications/serializers.py b/notifications/serializers.py index e4684ef12..3bb1e5d9a 100644 --- a/notifications/serializers.py +++ b/notifications/serializers.py @@ -18,9 +18,9 @@ class SurgeAlertSerializer(ModelSerializer): class Meta: model = SurgeAlert fields = ( - 'operation', 'country', 'message', 'deployment_needed', 'is_private', 'event', 'created_at', 'id', + 'operation','country', 'message', 'deployment_needed', 'is_private', 'event', 'created_at', 'id', 'atype', 'atype_display', 'category', 'category_display', 'molnix_id', 'molnix_tags', - 'molnix_status', 'opens', 'closes', 'start', 'end', 'is_active', 'is_stood_down','status_display' + 'molnix_status', 'opens', 'closes', 'start', 'end', 'is_active', 'is_stood_down','status', 'status_display' )