notifications listing fully operative with marking notifications as read and filtering
This commit is contained in:
parent
d09e2a9d0a
commit
4a0b31b34d
4 changed files with 67 additions and 28 deletions
|
@ -35,4 +35,11 @@
|
||||||
class="loops.organize.personal.browser.notification.NotificationsListing"
|
class="loops.organize.personal.browser.notification.NotificationsListing"
|
||||||
permission="zope.View" />
|
permission="zope.View" />
|
||||||
|
|
||||||
|
<zope:adapter
|
||||||
|
name="notification_read"
|
||||||
|
for="loops.browser.node.NodeView
|
||||||
|
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||||
|
factory="loops.organize.personal.browser.notification.ReadNotification"
|
||||||
|
permission="zope.View" />
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -24,7 +24,8 @@ from zope import component
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
|
||||||
from cybertools.util.date import formatTimeStamp
|
from cybertools.browser.form import FormController
|
||||||
|
from cybertools.util.date import formatTimeStamp, getTimeStamp
|
||||||
from loops.browser.concept import ConceptView
|
from loops.browser.concept import ConceptView
|
||||||
from loops.common import adapted, baseObject
|
from loops.common import adapted, baseObject
|
||||||
from loops.organize.personal.notification import Notifications
|
from loops.organize.personal.notification import Notifications
|
||||||
|
@ -49,11 +50,12 @@ class NotificationsListing(ConceptView):
|
||||||
def notifications(self):
|
def notifications(self):
|
||||||
return Notifications(self.person)
|
return Notifications(self.person)
|
||||||
|
|
||||||
def getNotifications(self, unreadOnly=True):
|
def getNotifications(self, unreadOnly):
|
||||||
tracks = self.notifications.listTracks()
|
tracks = self.notifications.listTracks(unreadOnly)
|
||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
def getNotificationsFormatted(self, unreadOnly=True):
|
def getNotificationsFormatted(self):
|
||||||
|
unreadOnly = not self.request.form.get('show_all')
|
||||||
result = []
|
result = []
|
||||||
for track in self.getNotifications(unreadOnly):
|
for track in self.getNotifications(unreadOnly):
|
||||||
data = track.data
|
data = track.data
|
||||||
|
@ -61,8 +63,11 @@ class NotificationsListing(ConceptView):
|
||||||
sender = dict(label=s.title,
|
sender = dict(label=s.title,
|
||||||
url=self.nodeView.getUrlForTarget(baseObject(s)))
|
url=self.nodeView.getUrlForTarget(baseObject(s)))
|
||||||
obj = util.getObjectForUid(track.taskId)
|
obj = util.getObjectForUid(track.taskId)
|
||||||
object = dict(label=obj.title,
|
ov = self.nodeView.getViewForTarget(obj)
|
||||||
url=self.nodeView.getUrlForTarget(baseObject(obj)))
|
url = '%s?form.action=notification_read&track=%s' % (
|
||||||
|
self.nodeView.getUrlForTarget(obj),
|
||||||
|
util.getUidForObject(track))
|
||||||
|
object = dict(label=ov.title, url=url)
|
||||||
read_ts = self.formatTimeStamp(data.get('read_ts'))
|
read_ts = self.formatTimeStamp(data.get('read_ts'))
|
||||||
item = dict(timeStamp=self.formatTimeStamp(track.timeStamp),
|
item = dict(timeStamp=self.formatTimeStamp(track.timeStamp),
|
||||||
sender=sender,
|
sender=sender,
|
||||||
|
@ -71,3 +76,17 @@ class NotificationsListing(ConceptView):
|
||||||
read_ts=read_ts)
|
read_ts=read_ts)
|
||||||
result.append(item)
|
result.append(item)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class ReadNotification(FormController):
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
form = self.request.form
|
||||||
|
trackId = form.get('track')
|
||||||
|
track = util.getObjectForUid(trackId)
|
||||||
|
data = track.data
|
||||||
|
alreadyRead = data.get('read_ts')
|
||||||
|
if not alreadyRead:
|
||||||
|
data['read_ts'] = getTimeStamp()
|
||||||
|
track.data = data
|
||||||
|
return True
|
||||||
|
|
|
@ -50,13 +50,22 @@
|
||||||
<metal:block define-macro="notifications">
|
<metal:block define-macro="notifications">
|
||||||
<div tal:attributes="class string:content-$level;">
|
<div tal:attributes="class string:content-$level;">
|
||||||
<metal:title use-macro="item/concept_macros/concepttitle" />
|
<metal:title use-macro="item/concept_macros/concepttitle" />
|
||||||
|
<form name="notifications" method="post">
|
||||||
|
<input type="checkbox" name="show_all" id="notifications.show_all"
|
||||||
|
title="Show all notifications"
|
||||||
|
i18n:attributes="title"
|
||||||
|
onclick="submit()"
|
||||||
|
tal:attributes="checked request/form/show_all|nothing" />
|
||||||
|
<label for="notifications.show_all"
|
||||||
|
i18n:translate="">Show all notifications</label>
|
||||||
|
<br />
|
||||||
<table class="listing">
|
<table class="listing">
|
||||||
<tr class="header">
|
<tr class="header">
|
||||||
<th>Date/Time</th>
|
<th i18n:translate="">Date/Time</th>
|
||||||
<th>Sender</th>
|
<th i18n:translate="">Sender</th>
|
||||||
<th>Object</th>
|
<th i18n:translate="">Object</th>
|
||||||
<th>Text</th>
|
<th i18n:translate="">Message</th>
|
||||||
<th>Date/Time read</th>
|
<th i18n:translate="">Date/Time read</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr tal:repeat="notif item/getNotificationsFormatted">
|
<tr tal:repeat="notif item/getNotificationsFormatted">
|
||||||
<td tal:content="notif/timeStamp" />
|
<td tal:content="notif/timeStamp" />
|
||||||
|
@ -70,5 +79,6 @@
|
||||||
<td tal:content="notif/read_ts" />
|
<td tal:content="notif/read_ts" />
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</metal:block>
|
</metal:block>
|
||||||
|
|
|
@ -33,9 +33,12 @@ class Notifications(Favorites):
|
||||||
self.context = (baseObject(person).
|
self.context = (baseObject(person).
|
||||||
getLoopsRoot().getRecordManager()['favorites'])
|
getLoopsRoot().getRecordManager()['favorites'])
|
||||||
|
|
||||||
def listTracks(self):
|
def listTracks(self, unreadOnly=False):
|
||||||
return super(Notifications, self).listTracks(
|
tracks = super(Notifications, self).listTracks(
|
||||||
baseObject(self.person), type='notification')
|
baseObject(self.person), type='notification')
|
||||||
|
if unreadOnly:
|
||||||
|
tracks = [t for t in tracks if not t.data.get('read_ts')]
|
||||||
|
return tracks
|
||||||
|
|
||||||
def add(self, obj, sender, text):
|
def add(self, obj, sender, text):
|
||||||
senderUid = util.getUidForObject(baseObject(sender))
|
senderUid = util.getUidForObject(baseObject(sender))
|
||||||
|
|
Loading…
Add table
Reference in a new issue