work in progress: notifications listing

This commit is contained in:
Helmut Merz 2015-10-25 15:42:36 +01:00
parent 019eef29a6
commit d09e2a9d0a
5 changed files with 48 additions and 8 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de # Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
View extension for support of i18n content. View extension for support of i18n content.
""" """
from datetime import date, datetime
from zope import interface, component from zope import interface, component
from zope.app.pagetemplate import ViewPageTemplateFile from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.session.interfaces import ISession from zope.app.session.interfaces import ISession
@ -28,6 +29,7 @@ from zope.i18n.interfaces import IUserPreferredLanguages
from zope.i18n.negotiator import negotiator from zope.i18n.negotiator import negotiator
from cybertools.meta.interfaces import IOptions from cybertools.meta.interfaces import IOptions
from cybertools.util import format
from loops.common import adapted from loops.common import adapted
@ -76,6 +78,8 @@ class I18NView(object):
""" View mix-in class. """ View mix-in class.
""" """
timeStampFormat = 'short'
@Lazy @Lazy
def languageInfo(self): def languageInfo(self):
return LanguageInfo(self.context, self.request) return LanguageInfo(self.context, self.request)
@ -114,3 +118,10 @@ class I18NView(object):
self.setLanguage(lang) self.setLanguage(lang)
return self() return self()
def formatTimeStamp(self, ts, f='dateTime'):
if not ts:
return u''
value = datetime.fromtimestamp(ts)
return format.formatDate(value, f, self.timeStampFormat,
self.languageInfo.language)

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de # Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -35,7 +35,7 @@ from zope.traversing.api import getName
from cybertools.organize.party import Person as BasePerson from cybertools.organize.party import Person as BasePerson
from cybertools.relation.interfaces import IRelationRegistry from cybertools.relation.interfaces import IRelationRegistry
from cybertools.typology.interfaces import IType from cybertools.typology.interfaces import IType
from loops.common import AdapterBase from loops.common import AdapterBase, baseObject
from loops.concept import Concept from loops.concept import Concept
from loops.interfaces import IConcept from loops.interfaces import IConcept
from loops.organize.interfaces import IAddress, IPerson, IHasRole from loops.organize.interfaces import IAddress, IPerson, IHasRole
@ -64,7 +64,7 @@ def getPersonForUser(context, request=None, principal=None):
principal = getattr(request, 'principal', None) principal = getattr(request, 'principal', None)
if principal is None: if principal is None:
return None return None
loops = context.getLoopsRoot() loops = baseObject(context).getLoopsRoot()
pa = annotations(principal).get(ANNOTATION_KEY, None) pa = annotations(principal).get(ANNOTATION_KEY, None)
if pa is None: if pa is None:
return None return None

View file

@ -24,7 +24,9 @@ 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 loops.browser.concept import ConceptView from loops.browser.concept import ConceptView
from loops.common import adapted, baseObject
from loops.organize.personal.notification import Notifications from loops.organize.personal.notification import Notifications
from loops.organize.party import getPersonForUser from loops.organize.party import getPersonForUser
from loops import util from loops import util
@ -50,3 +52,22 @@ class NotificationsListing(ConceptView):
def getNotifications(self, unreadOnly=True): def getNotifications(self, unreadOnly=True):
tracks = self.notifications.listTracks() tracks = self.notifications.listTracks()
return tracks return tracks
def getNotificationsFormatted(self, unreadOnly=True):
result = []
for track in self.getNotifications(unreadOnly):
data = track.data
s = util.getObjectForUid(data.get('sender'))
sender = dict(label=s.title,
url=self.nodeView.getUrlForTarget(baseObject(s)))
obj = util.getObjectForUid(track.taskId)
object = dict(label=obj.title,
url=self.nodeView.getUrlForTarget(baseObject(obj)))
read_ts = self.formatTimeStamp(data.get('read_ts'))
item = dict(timeStamp=self.formatTimeStamp(track.timeStamp),
sender=sender,
object=object,
text=data.get('text') or u'',
read_ts=read_ts)
result.append(item)
return result

View file

@ -58,9 +58,16 @@
<th>Text</th> <th>Text</th>
<th>Date/Time read</th> <th>Date/Time read</th>
</tr> </tr>
<tr tal:repeat="notif item/getNotifications"> <tr tal:repeat="notif item/getNotificationsFormatted">
<td colspan="5" <td tal:content="notif/timeStamp" />
tal:content="notif" /> <td tal:define="sender notif/sender">
<a tal:attributes="href sender/url"
tal:content="sender/label" /></td>
<td tal:define="object notif/object">
<a tal:attributes="href object/url"
tal:content="object/label" /></td>
<td tal:content="notif/text" />
<td tal:content="notif/read_ts" />
</tr> </tr>
</table> </table>
</div> </div>

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2014 Helmut Merz helmutm@cy55.de # Copyright (c) 2015 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -153,6 +153,7 @@ class ChangeStateForm(ChangeStateBase, ObjectForm):
class ChangeState(ChangeStateBase, EditObject): class ChangeState(ChangeStateBase, EditObject):
def update(self): def update(self):
self.stateful.request = self.request
self.stateful.doTransition(self.action) self.stateful.doTransition(self.action)
formData = self.request.form formData = self.request.form
# store data in target object (unless field.nostore) # store data in target object (unless field.nostore)