# HG changeset patch # User Sylvain Thénault <sylvain.thenault@logilab.fr> # Date 1295270056 -3600 # Mon Jan 17 14:14:16 2011 +0100 # Branch stable # Node ID 4766735fe03e9e92d5cd717ad9cc9cb4d4008c54 # Parent a78e7ba718a2a6708c05e65b2d1b61167cb4d327 cw 3.10 api update diff --git a/views.py b/views.py --- a/views.py +++ b/views.py @@ -273,19 +273,20 @@ # contextual components ######################################################## -class CommentSectionVComponent(component.EntityVComponent): +class CommentSectionVComponent(component.EntityCtxComponent): """a component to display a <div> html section including comments related to an object """ __regid__ = 'commentsection' - __select__ = ((component.EntityVComponent.__select__ | match_kwargs('entity')) + __select__ = ((component.EntityCtxComponent.__select__ | match_kwargs('entity')) & relation_possible('comments', 'object', 'Comment')) context = 'navcontentbottom' - def entity_call(self, entity, view=None): + def render_body(self, w): req = self._cw req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') ) + entity = self.entity addcomment = self._cw.vreg['actions'].select_or_none( 'reply_comment', req, entity=entity, rset=entity.cw_rset, row=entity.cw_row, col=entity.cw_col) @@ -298,17 +299,17 @@ rset = None if not (rset or addcomment): return - self.w(u'<div id="%s" class="%s" cubicweb:rooteid="%s">' % ( - self.div_id(), self.div_class(), entity.eid)) + w(u'<div id="%s" class="%s" cubicweb:rooteid="%s">' % ( + self.domid, self.cssclass, entity.eid)) if rset.rowcount: - self.w(u'<h4>%s</h4>' % (req._('Comment_plural'))) - self.w(u'<ul class="comment">') + w(u'<h4>%s</h4>' % (req._('Comment_plural'))) + w(u'<ul class="comment">') for i in xrange(rset.rowcount): - self.wview('tree', rset, row=i) - self.w(u'</ul>') - self.w(u'</div>') + wview('tree', rset, row=i) + w(u'</ul>') + w(u'</div>') if addcomment is not None: - self.w(u'<div id="comment%sHolder"></div>' % entity.eid) + w(u'<div id="comment%sHolder"></div>' % entity.eid) params = self.cw_extra_kwargs.copy() params.pop('view', None) params.pop('context', None) @@ -318,15 +319,15 @@ params['etype'] = entity.__regid__ url = req.ajax_replace_url( 'comment%sHolder' % entity.eid, vid='addcommentform', **params) - self.w(u' (<a href="%s">%s</a>)' % (xml_escape(url), req._(addcomment.title))) + w(u' (<a href="%s">%s</a>)' % (xml_escape(url), req._(addcomment.title))) -class UserLatestCommentsSection(component.EntityVComponent): +class UserLatestCommentsSection(component.EntityCtxComponent): """a section to display latest comments by a user""" - __select__ = component.EntityVComponent.__select__ & is_instance('CWUser') + __select__ = component.EntityCtxComponent.__select__ & is_instance('CWUser') __regid__ = 'latestcomments' - def cell_call(self, row, col, view=None): + def render_body(self, w): user = self.cw_rset.get_entity(row, col) maxrelated = self._cw.property_value('navigation.related-limit') + 1 rset = self._cw.execute( @@ -335,15 +336,15 @@ 'C created_by U, U eid %%(u)s' % maxrelated, {'u': user.eid}) if rset: - self.w(u'<div class="section">') - self.w(u'<h4>%s</h4>\n' % self._cw._('Latest comments').capitalize()) - self.wview('table', rset, - headers=[_('about'), _('on date'), - _('comment content')], - cellvids={0: 'commentroot', - 2: 'commentsummary', - }) - self.w(u'</div>') + w(u'<div class="section">') + w(u'<h4>%s</h4>\n' % self._cw._('Latest comments').capitalize()) + self.view('table', rset, w=w, + headers=[_('about'), _('on date'), + _('comment content')], + cellvids={0: 'commentroot', + 2: 'commentsummary', + }) + w(u'</div>') # adapters #####################################################################