views.py 1.29 KB
Newer Older
Nicolas Chauvat's avatar
Nicolas Chauvat committed
1
2
3
4
from cubicweb.selectors import is_instance, adaptable
from cubicweb.view import EntityView

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

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

16

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

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