Added base alerts content provider
authorThierry Florac <tflorac@ulthar.net>
Wed, 03 Oct 2018 19:27:17 +0200
changeset 162 77ec84eff41c
parent 161 559bb6d3d0f0
child 163 de718ccf8bcc
child 166 dcf8ca8f9bf1
Added base alerts content provider
src/pyams_default_theme/features/alert/__init__.py
src/pyams_default_theme/features/alert/templates/alerts.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/features/alert/__init__.py	Wed Oct 03 19:27:17 2018 +0200
@@ -0,0 +1,34 @@
+#
+# Copyright (c) 2008-2018 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+from zope.interface import Interface
+
+from pyams_content.features.alert.interfaces import IAlertContainer, ALERT_GRAVITY_NAMES
+from pyams_skin.layer import IPyAMSUserLayer
+from pyams_template.template import template_config
+from pyams_viewlet.viewlet import ViewContentProvider, contentprovider_config
+
+
+@contentprovider_config(name='pyams.alerts', layer=IPyAMSUserLayer, view=Interface)
+@template_config(template='templates/alerts.pt', layer=IPyAMSUserLayer)
+class AlertsContentProvider(ViewContentProvider):
+    """Alerts content provider"""
+
+    def get_alerts(self):
+        alerts = IAlertContainer(self.request.root, None)
+        if alerts is not None:
+            yield from alerts.get_visible_items()
+
+    def get_gravity(self, alert):
+        return self.request.localizer.translate(ALERT_GRAVITY_NAMES.get(alert.gravity))