--- a/src/pyams_content/features/alert/container.py Wed Oct 03 16:11:39 2018 +0200
+++ b/src/pyams_content/features/alert/container.py Wed Oct 03 19:24:25 2018 +0200
@@ -12,20 +12,18 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
+from datetime import datetime
-# import interfaces
-from pyams_content.features.alert.interfaces import IAlertContainer, IAlertItem, IAlertTarget, ALERT_CONTAINER_KEY
+from zope.container.ordered import OrderedContainer
+from zope.interface import implementer
+from zope.location import locate
from zope.location.interfaces import ISublocations
from zope.traversing.interfaces import ITraversable
-# import packages
from pyams_catalog.utils import index_object
-from pyams_utils.adapter import adapter_config, ContextAdapter, get_annotation_adapter
-from zope.container.ordered import OrderedContainer
-from zope.interface import implementer
-from zope.location import locate
+from pyams_content.features.alert.interfaces import ALERT_CONTAINER_KEY, IAlertContainer, IAlertItem, IAlertTarget
+from pyams_utils.adapter import ContextAdapter, adapter_config, get_annotation_adapter
+from pyams_utils.timezone import tztime
@implementer(IAlertContainer)
@@ -46,7 +44,13 @@
index_object(value)
def get_visible_items(self):
- yield from filter(lambda x: IAlertItem(x).visible, self.values())
+ now = tztime(datetime.utcnow())
+ for alert in filter(lambda x: IAlertItem(x).visible, self.values()):
+ if alert.start_date and (alert.start_date > now):
+ continue
+ if alert.end_date and (alert.end_date < now):
+ continue
+ yield alert
@adapter_config(context=IAlertTarget, provides=IAlertContainer)