Skip to content

Commit

Permalink
Fix comparing CAP dates with current datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
erick-otenyo committed Feb 12, 2024
1 parent 959bfe5 commit bde4e4a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pages/cap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pages/cap/templatetags/cap_tags.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

from django import template
from django.utils import timezone

from pages.cap.models import CapAlertPage

Expand All @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions pages/cap/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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
from django.contrib.syndication.views import Feed
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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bde4e4a

Please sign in to comment.