Skip to content

Commit

Permalink
Add status filter for surge-alert
Browse files Browse the repository at this point in the history
  • Loading branch information
k9845 committed Feb 12, 2024
1 parent d183164 commit 2d2d2b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions notifications/drf_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions notifications/management/commands/update_alert_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions notifications/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)


Expand Down

0 comments on commit 2d2d2b7

Please sign in to comment.