work in progress: notifications listing
This commit is contained in:
parent
019eef29a6
commit
d09e2a9d0a
5 changed files with 48 additions and 8 deletions
|
@ -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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,6 +20,7 @@
|
|||
View extension for support of i18n content.
|
||||
"""
|
||||
|
||||
from datetime import date, datetime
|
||||
from zope import interface, component
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.app.session.interfaces import ISession
|
||||
|
@ -28,6 +29,7 @@ from zope.i18n.interfaces import IUserPreferredLanguages
|
|||
from zope.i18n.negotiator import negotiator
|
||||
|
||||
from cybertools.meta.interfaces import IOptions
|
||||
from cybertools.util import format
|
||||
from loops.common import adapted
|
||||
|
||||
|
||||
|
@ -76,6 +78,8 @@ class I18NView(object):
|
|||
""" View mix-in class.
|
||||
"""
|
||||
|
||||
timeStampFormat = 'short'
|
||||
|
||||
@Lazy
|
||||
def languageInfo(self):
|
||||
return LanguageInfo(self.context, self.request)
|
||||
|
@ -114,3 +118,10 @@ class I18NView(object):
|
|||
self.setLanguage(lang)
|
||||
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)
|
||||
|
||||
|
|
|
@ -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
|
||||
# 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.relation.interfaces import IRelationRegistry
|
||||
from cybertools.typology.interfaces import IType
|
||||
from loops.common import AdapterBase
|
||||
from loops.common import AdapterBase, baseObject
|
||||
from loops.concept import Concept
|
||||
from loops.interfaces import IConcept
|
||||
from loops.organize.interfaces import IAddress, IPerson, IHasRole
|
||||
|
@ -64,7 +64,7 @@ def getPersonForUser(context, request=None, principal=None):
|
|||
principal = getattr(request, 'principal', None)
|
||||
if principal is None:
|
||||
return None
|
||||
loops = context.getLoopsRoot()
|
||||
loops = baseObject(context).getLoopsRoot()
|
||||
pa = annotations(principal).get(ANNOTATION_KEY, None)
|
||||
if pa is None:
|
||||
return None
|
||||
|
|
|
@ -24,7 +24,9 @@ from zope import component
|
|||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.util.date import formatTimeStamp
|
||||
from loops.browser.concept import ConceptView
|
||||
from loops.common import adapted, baseObject
|
||||
from loops.organize.personal.notification import Notifications
|
||||
from loops.organize.party import getPersonForUser
|
||||
from loops import util
|
||||
|
@ -50,3 +52,22 @@ class NotificationsListing(ConceptView):
|
|||
def getNotifications(self, unreadOnly=True):
|
||||
tracks = self.notifications.listTracks()
|
||||
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
|
||||
|
|
|
@ -58,9 +58,16 @@
|
|||
<th>Text</th>
|
||||
<th>Date/Time read</th>
|
||||
</tr>
|
||||
<tr tal:repeat="notif item/getNotifications">
|
||||
<td colspan="5"
|
||||
tal:content="notif" />
|
||||
<tr tal:repeat="notif item/getNotificationsFormatted">
|
||||
<td tal:content="notif/timeStamp" />
|
||||
<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>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
# 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):
|
||||
|
||||
def update(self):
|
||||
self.stateful.request = self.request
|
||||
self.stateful.doTransition(self.action)
|
||||
formData = self.request.form
|
||||
# store data in target object (unless field.nostore)
|
||||
|
|
Loading…
Add table
Reference in a new issue