views.py 1.58 KB
Newer Older
Nicolas Chauvat's avatar
Nicolas Chauvat committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from cubicweb.selectors import is_instance, adaptable
from cubicweb.view import EntityView
from cubicweb.view import EntityAdapter

class IActivityStreamAdapter(EntityAdapter):
    __regid__ = 'IActivityStream'

    @property
    def content(self):
        raise NotImplementedError()

    @property
    def date(self):
        raise NotImplementedError()

class TrinfoAStreamAdapter(IActivityStreamAdapter):
    __select__ = is_instance('TrInfo')

    @property
    def content(self):
        return (u'%s %s transition from state %s to state %s with comment %s'
                % (self.entity.wf_info_for[0].e_schema,
                   self.entity.wf_info_for[0].dc_title(),
                   self.entity.from_state[0].name,
                   self.entity.to_state[0].name,
                   self.entity.printable_value('comment'),
                   ))

    @property
    def date(self):
        return self.entity.creation_date

class AStreamView(EntityView):
    __regid__ = 'astream'
    __select__ = EntityView.__select__ & adaptable('IActivityStream')

    def cell_call(self, row, col):
        self._cw.add_css('cubes.astream.css')
        entity = self.cw_rset.get_entity(row, col)
        ablock = entity.dc_creator()
        activity = entity.cw_adapt_to('IActivityStream')
        self.w(u'<div class="activitystream">'
               u'<span class="author">%s</span>'
               u'<span class="msgtxt">%s</span>'
               u'<span class="meta"><a href="%s">%s</a></span>'
               u'</div>' % (ablock, activity.content,
                            entity.absolute_url(), activity.date))