Updated container method to get visible items
authorThierry Florac <tflorac@ulthar.net>
Wed, 03 Oct 2018 19:24:25 +0200
changeset 994 0f73d19137e4
parent 993 ce5091a24640
child 995 a219e2e20779
Updated container method to get visible items
src/pyams_content/features/alert/container.py
--- 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)