diff --git a/pages/cap/models.py b/pages/cap/models.py index 16a6ab51..eef9f732 100644 --- a/pages/cap/models.py +++ b/pages/cap/models.py @@ -4,6 +4,7 @@ from capeditor.pubsub.publish import publish_cap_mqtt_message from django.db import models from django.urls import reverse +from django.utils import timezone from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ from geomanager.models import SubCategory, Metadata @@ -61,7 +62,7 @@ def active_alerts(self): for alert in alerts: for alert_info in alert.infos: info = alert_info.get("info") - if info.value.get('expires') > datetime.today(): + if info.value.get('expires') > timezone.localtime(): active_alert_infos.append(alert_info) return active_alert_infos diff --git a/pages/cap/templatetags/cap_tags.py b/pages/cap/templatetags/cap_tags.py index 9246f722..e121dbf1 100644 --- a/pages/cap/templatetags/cap_tags.py +++ b/pages/cap/templatetags/cap_tags.py @@ -1,6 +1,7 @@ from datetime import datetime from django import template +from django.utils import timezone from pages.cap.models import CapAlertPage @@ -15,7 +16,7 @@ def get_latest_active_cap_alert(): for alert in alerts: for alert_info in alert.infos: info = alert_info.get("info") - if info.value.get('expires') > datetime.today(): + if info.value.get('expires') > timezone.localtime(): active_alert_infos.append(alert_info) if len(active_alert_infos) == 0: diff --git a/pages/cap/views.py b/pages/cap/views.py index 5a6dfc16..629e45e1 100644 --- a/pages/cap/views.py +++ b/pages/cap/views.py @@ -1,7 +1,5 @@ -from datetime import datetime from typing import Any, Dict, List -import pytz from capeditor.models import CapSetting from capeditor.renderers import CapXMLRenderer from capeditor.serializers import AlertSerializer @@ -9,6 +7,7 @@ from django.db.models.base import Model from django.http import JsonResponse from django.urls import reverse +from django.utils import timezone from django.utils.feedgenerator import Enclosure from django.utils.feedgenerator import Rss201rev2Feed from rest_framework import generics @@ -72,7 +71,6 @@ def items(self): for alert in alerts: for info in alert.info: - # if info.value.get('expires') >= datetime.today().replace(tzinfo=pytz.UTC): active_alert_infos.append(alert.id) return CapAlertPage.objects.filter(id__in=active_alert_infos).live() @@ -138,7 +136,7 @@ def cap_geojson(request): for alert in alerts: for info in alert.info: - if info.value.get('expires') >= datetime.today().replace(tzinfo=pytz.UTC): + if info.value.get('expires') > timezone.localtime(): active_alert_infos.append(alert.id) active_alerts = CapAlertPage.objects.filter(id__in=active_alert_infos).live()