cubicweb_activitystream/views.py
author Nsukami Patrick <ndkpatt at gmail dot com>
Wed, 12 Jun 2019 11:04:02 +0000
changeset 39 1042a52ceb67
parent 37 0b5cb6030125
permissions -rw-r--r--
Flake8: fix errors - F401 'cubicweb.predicates.is_instance' imported but unused - F821 undefined name '_'

from logilab.mtconverter import xml_escape
from cubicweb.predicates import adaptable
from cubicweb.view import EntityView
from cubicweb import _


class AStreamView(EntityView):
    __regid__ = 'activitystream'
    __select__ = EntityView.__select__ & adaptable('IActivityStream')
    title = _('activitystream')

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


class AStreamItemView(EntityView):
    __regid__ = 'activitystream_item'
    __select__ = EntityView.__select__ & adaptable('IActivityStreamItem')

    def cell_call(self, row, col):
        self._cw.add_css('cubes.activitystream.css')
        entity = self.cw_rset.get_entity(row, col)
        activity = entity.cw_adapt_to('IActivityStreamItem')
        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>' % (xml_escape(activity.actor),
                            xml_escape(activity.content),
                            xml_escape(entity.absolute_url()),
                            self._cw.format_date(activity.date, time=True)))