# HG changeset patch # User Thierry Florac # Date 1538587637 -7200 # Node ID 77ec84eff41cf14d854303f927b78202ce513e65 # Parent 559bb6d3d0f09c8e099013ecc2f95744df0c202e Added base alerts content provider diff -r 559bb6d3d0f0 -r 77ec84eff41c src/pyams_default_theme/features/alert/__init__.py --- /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 +# 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)) diff -r 559bb6d3d0f0 -r 77ec84eff41c src/pyams_default_theme/features/alert/templates/alerts.pt