Use new notifications API
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 12:13:08 +0200
changeset 16 9c4f1c598272
parent 15 eb863d6bc5a9
child 17 dfb0c634ee79
Use new notifications API
src/pyams_notify/viewlet/__init__.py
src/pyams_notify/viewlet/templates/notifications.pt
--- a/src/pyams_notify/viewlet/__init__.py	Wed Jul 12 12:12:08 2017 +0200
+++ b/src/pyams_notify/viewlet/__init__.py	Wed Jul 12 12:13:08 2017 +0200
@@ -16,10 +16,12 @@
 # import standard library
 
 # import interfaces
+from pyams_notify.interfaces import CACHE_CONFIGURATION_KEY
 from pyams_skin.interfaces.viewlet import IActivityViewletManager
 from pyams_skin.layer import IPyAMSLayer
 
 # import packages
+from pyams_notify.views.notification import get_user_notifications
 from pyams_skin.viewlet.activity import ActivityViewlet
 from pyams_template.template import template_config
 from pyams_viewlet.viewlet import viewlet_config
@@ -39,3 +41,10 @@
     @property
     def notify_server(self):
         return self.request.registry.settings.get('pyams_notify.tcp_handler')
+
+    @property
+    def cache_server(self):
+        return self.request.registry.settings.get(CACHE_CONFIGURATION_KEY)
+
+    def get_notifications(self):
+        return get_user_notifications(self.cache_server, self.request)
--- a/src/pyams_notify/viewlet/templates/notifications.pt	Wed Jul 12 12:12:08 2017 +0200
+++ b/src/pyams_notify/viewlet/templates/notifications.pt	Wed Jul 12 12:13:08 2017 +0200
@@ -1,5 +1,20 @@
 <div class="notifications-parent no-margin" i18n:domain="pyams_notify"
+	 tal:define="notifications view.get_notifications()['notifications']"
 	 tal:attributes="data-ams-notify-server view.notify_server">
-	<p class="alert alert-info" i18n:translate="">No notification to display.</p>
-	<ul class="notification-body"></ul>
+	<p tal:condition="not:notifications"
+	   class="alert alert-info" i18n:translate="">No notification to display.</p>
+	<ul class="notification-body">
+		<li tal:repeat="notification notifications">
+			<span>
+				<a class="msg" tal:attributes="href notification.url">
+					<img class="air air-top-left margin-top-2"
+						 tal:condition="notification.source.avatar"
+						 tal:attributes="src notification.source.avatar" />
+					<time tal:content="notification.timestamp"></time>
+					<span class="from" tal:content="notification.source.title"></span>
+					<span class="msg-body" tal:content="notification.message"></span>
+				</a>
+			</span>
+		</li>
+	</ul>
 </div>