author Samuel Trégouët <>
Fri, 01 Sep 2017 15:46:52 +0200
changeset 181 d49d242230ff
parent 178 336aa0819b5c
child 186 b9915b5c011d
permissions -rw-r--r--
new style: update spec

"""Notification views for keywords / classification schemes

:organization: Logilab
:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: --
__docformat__ = "restructuredtext en"

from logilab.common.decorators import cached

from cubicweb.predicates import is_instance
from cubicweb.sobjects.notification import NotificationView

class KeywordNotificationView(NotificationView):
    __select__ = is_instance('Keyword')
    msgid_timestamp = True

    def recipients(self):
        """Returns the project's interested people (entities)"""
        creator = self.cw_rset.get_entity(0, 0).created_by[0]
        if not creator.is_in_group('managers') and creator.primary_email:
            return [(creator.primary_email[0].address, 'fr')]
        return []

    def context(self, **kwargs):
        context = NotificationView.context(self, **kwargs)
        entity = self.cw_rset.get_entity(0, 0)
        context['kw'] =
        return context

class KeywordNameChanged(KeywordNotificationView):
    __regid__ = 'notif_after_update_entity'

    content = _("keyword name changed from %(oldname)s to %(kw)s")

    def get_oldname(self, entity):
        session = self.req
            return session.execute('Any N WHERE X eid %(x)s, X name N',
                                   {'x' : entity.eid}, 'x')[0][0]
        except IndexError:
            return u'?'

    def context(self, **kwargs):
        entity = self.cw_rset.get_entity(0, 0)
        context = KeywordNotificationView.context(self, **kwargs)
        context['oldname'] = self.get_oldname(entity)
        return context

    def subject(self):
        entity = self.cw_rset.get_entity(0, 0)
        return self.req._('keyword name changed from %s to %s') % (