Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
activitystream
Commits
76cb4680f2af
Commit
ff745c14
authored
Aug 05, 2011
by
Sylvain Thénault
Browse files
fix patches repo mess
parent
df393d72f0d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
astreampart.diff
deleted
100644 → 0
View file @
df393d72
#
HG changeset patch
#
User Sylvain Thénault <sylvain.thenault@logilab.fr>
#
Parent ec728e052d43c4ef34ba62fbbdfa4e53e5c559b3
propose a more flexible implementation
diff --git a/entities.py b/entities.py
--- a/entities.py
+++ b/entities.py
@@ -11,45 +11,93 @@
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb-astream adapters"""
-"""cubicweb-astream entity's classes"""
from cubicweb.selectors import is_instance
from cubicweb.view import EntityAdapter
+from cubicweb.appobject import AppObject
class IActivityStreamAdapter(EntityAdapter):
__regid__ = 'IActivityStream'
@property
- def rql(self):
- raise NotImplementedError()
+ def astream_rql(self):
+ """return a RQL query to get the whole activity stream of the adapted
+ entity.
+
+ In this query, %(x)s will refer to the eid of the adapted entity. The
+ returned query is expected to select:
+
+ 1. the eid of the activity
+ 2. its date
+ 3. the actor of the activity
+ 4. some content.
+
+ and to be ordered on date (descending)
+ """
+ rqls = []
+ for part in self._cw.vreg['astream'].possible_objects(
+ self._cw, entity=self.entity):
+ rqls += part.astream_rqls
+ assert rqls, 'no activity stream for %s' % self.entity
+ if len(rqls) > 1:
+ rql = ' UNION '.join('(%s)' % rql for rql in rqls)
+ else:
+ rql = rqls[0]
+ return 'Any X,XD,XA,XC ORDERBY XD DESC WITH X,XD,XA,XC BEING (%s)' % rql
+
+
+class ActivityStreamPart(AppObject):
+ __registry__ = 'astream'
+
+ @property
+ def astream_rqls(self):
+ """return a list of RQL queries to get some path of the activity stream
+ of the adapted entity.
+
+ In each query, %(x)s will refer to the eid of the adapted entity. The
+ returned query is expected to select:
+
+ 1. the eid of the activity
+ 2. its date
+ 3. the actor of the activity
+ 4. some content.
+
+ and should not be ordered.
+ """
+ raise NotImplementedError
+
+
+class StatefulAStreamPart(ActivityStreamPart):
+ __select__ = adaptable('IWorkflowable')
+ __regid__ = 'stateful'
+ astream_rqls = (
+ 'Any TI,TICD,U,TIC WHERE TI is TrInfo, TI wf_info_for X, X eid %(x)s,'
+ 'TI creation_date TICD, TI created_by U?, TI comment TIC',)
+
class IActivityStreamItemAdapter(EntityAdapter):
__regid__ = 'IActivityStreamItem'
-
- @property
- def content(self):
- raise NotImplementedError()
-
- @property
- def date(self):
- raise NotImplementedError()
-
-class AnyAStreamItemAdapter(IActivityStreamItemAdapter):
__select__ = is_instance('Any')
@property
def content(self):
return u'%s %s added' % (self.entity.e_schema, self.entity.dc_title())
@property
def date(self):
return self.entity.creation_date
-class TrinfoAStreamItemAdapter(AnyAStreamItemAdapter):
+ @property
+ def actor(self):
+ return self.entity.dc_creator()
+
+
+class TrinfoAStreamItemAdapter(IActivityStreamItemAdapter):
__select__ = is_instance('TrInfo')
@property
def content(self):
return (u'%s %s transition from state %s to state %s with comment %s'
diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -2,30 +2,30 @@
from cubicweb.selectors import is_instan
from cubicweb.view import EntityView
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').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.astream.css')
entity = self.cw_rset.get_entity(row, col)
- ablock = entity.dc_creator()
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>' % (ablock, activity.content,
- entity.absolute_url(), activity.date))
-
-
+ u'</div>' % (activity.actor, activity.content,
+ entity.absolute_url(),
+ self._cw.format_date(activity.date, time=True)))
series
deleted
100644 → 0
View file @
df393d72
astreampart.diff
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment