views.py 1.39 KB
Newer Older
Sylvain Thénault's avatar
Sylvain Thénault committed
1
from logilab.mtconverter import xml_escape
Nicolas Chauvat's avatar
Nicolas Chauvat committed
2
3
4
5
from cubicweb.selectors import is_instance, adaptable
from cubicweb.view import EntityView

class AStreamView(EntityView):
6
    __regid__ = 'activitystream'
Nicolas Chauvat's avatar
Nicolas Chauvat committed
7
    __select__ = EntityView.__select__ & adaptable('IActivityStream')
8
    title = _('activitystream')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
9

10
11
    def cell_call(self, row, col):
        entity = self.cw_rset.get_entity(row, col)
12
        rset = self._cw.execute(entity.cw_adapt_to('IActivityStream').astream_rql,
13
14
15
16
                                dict(x=entity.eid))
        self.paginate(rset=rset)
        self.wview('activitystream_item', rset, 'null')

17

18
19
20
21
class AStreamItemView(EntityView):
    __regid__ = 'activitystream_item'
    __select__ = EntityView.__select__ & adaptable('IActivityStreamItem')

Nicolas Chauvat's avatar
Nicolas Chauvat committed
22
    def cell_call(self, row, col):
23
        self._cw.add_css('cubes.activitystream.css')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
24
        entity = self.cw_rset.get_entity(row, col)
25
        activity = entity.cw_adapt_to('IActivityStreamItem')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
26
27
28
29
        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>'
Sylvain Thénault's avatar
Sylvain Thénault committed
30
31
32
               u'</div>' % (xml_escape(activity.actor),
                            xml_escape(activity.content),
                            xml_escape(entity.absolute_url()),
33
                            self._cw.format_date(activity.date, time=True)))