diff --git a/views.py b/views.py index 2ee5820ef5b9877fbbec426bee3769cce5714508_dmlld3MucHk=..3e9b0974739c89ba4eb8ce531849f3225d0d98f7_dmlld3MucHk= 100644 --- a/views.py +++ b/views.py @@ -1,7 +1,7 @@ """Specific views and actions for application using the Comment entity type :organization: Logilab -:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2003-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" @@ -9,6 +9,7 @@ from itertools import count from logilab.mtconverter import html_escape +from logilab.common.decorators import monkeypatch from simplejson import dumps @@ -12,5 +13,8 @@ from simplejson import dumps -from cubicweb.selectors import one_line_rset, but_etype, implements, has_permission +from cubicweb.selectors import (one_line_rset, but_etype, implements, + has_permission, relation_possible, yes) +from cubicweb.view import EntityView +from cubicweb.selectors import match_kwargs, accept from cubicweb.common.uilib import rql_for_eid, cut, safe_cut, ajax_replace_url @@ -16,3 +20,2 @@ from cubicweb.common.uilib import rql_for_eid, cut, safe_cut, ajax_replace_url -from cubicweb.common.view import EntityView from cubicweb.common.mixins import TreeViewMixIn @@ -18,6 +21,3 @@ from cubicweb.common.mixins import TreeViewMixIn -from cubicweb.common.selectors import (match_kwargs, - accept) - from cubicweb.web import stdmsgs from cubicweb.web.action import (LinkToEntityAction, Action) @@ -22,9 +22,11 @@ from cubicweb.web import stdmsgs from cubicweb.web.action import (LinkToEntityAction, Action) -from cubicweb.web.views import baseviews +from cubicweb.web.views import baseviews, baseforms +from cubicweb.web.component import EntityVComponent +from cubicweb.web.views.basecontrollers import JSonController _ = unicode # comment views ############################################################### class CommentPrimaryView(baseviews.PrimaryView): @@ -25,10 +27,10 @@ _ = unicode # comment views ############################################################### class CommentPrimaryView(baseviews.PrimaryView): - accepts = ('Comment',) + __select__ = implements('Comment') def cell_call(self, row, col): self.req.add_css('cubes.comment.css') @@ -61,7 +63,7 @@ class CommentSecondaryView(baseviews.SecondaryView): - accepts = ('Comment',) + __select__ = implements('Comment') def cell_call(self, row, col, **kwargs): entity = self.entity(row, col) @@ -81,6 +83,4 @@ class CommentTreeItemView(baseviews.ListItemView): - - accepts = ('Comment',) id = 'treeitem' @@ -86,4 +86,5 @@ id = 'treeitem' + __select__ = implements('Comment') def cell_call(self, row, col, **kwargs): _ = self.req._ @@ -123,7 +124,7 @@ class CommentThreadView(TreeViewMixIn, baseviews.ListView): """a recursive tree view""" - accepts = ('Comment',) + __select__ = implements('Comment') title = _('thread view') def open_item(self, entity): @@ -132,7 +133,5 @@ # comment edition views ####################################################### -from cubicweb.web.views import baseforms - class InlineCommentView(EntityView): id = 'inlinecomment' @@ -137,6 +136,6 @@ class InlineCommentView(EntityView): id = 'inlinecomment' - __selectors__ = (yes,) # explicit call when it makes sense, + __select__ = yes() # explicit call when it makes sense def cell_call(self, row, col): entity = self.entity(row, col) @@ -145,7 +144,7 @@ class InlineCommentForm(baseforms.CreationForm): id = 'inlinecommentform' - __selectors__ = (match_kwargs('commented'),) # explicit call when it makes sense, + __select__ = match_kwargs('commented') # explicit call when it makes sense title = None # hidden @@ -219,10 +218,8 @@ # comment component ########################################################### -from cubicweb.web.component import EntityVComponent - class CommentSectionVComponent(EntityVComponent): """a component to display a <div> html section including comments related to an object """ id = 'commentsection' @@ -224,11 +221,10 @@ class CommentSectionVComponent(EntityVComponent): """a component to display a <div> html section including comments related to an object """ id = 'commentsection' - etype = 'Comment' - rtype = 'comments' - target = 'subject' + __select__ = EntityVComponent.__select__ & relation_possible('comments', 'object', 'Comment') + context = 'navcontentbottom' def cell_call(self, row, col, view=None, orderby='diem'): @@ -270,7 +266,8 @@ baseviews.PRIMARY_SKIP_RELS.add('comments') # displayed by the above component + # comment actions ############################################################# class ReplyCommentAction(LinkToEntityAction): id = 'reply_comment' @@ -273,8 +270,8 @@ # comment actions ############################################################# class ReplyCommentAction(LinkToEntityAction): id = 'reply_comment' - __selectors__ = LinkToEntityAction + (implements('Comments'),) + __select__ = LinkToEntityAction.__select__ & implements('Comments') etype = 'Comment' rtype = 'comments' @@ -297,7 +294,7 @@ class AddCommentAction(LinkToEntityAction): """add comment is like reply for everything but Comment""" id = 'reply_comment' - __selectors__ = LinkToEntityAction + (implements('Any'), but_etype('Comment'),) + __select__ = LinkToEntityAction.__select__ & but_etype('Comment') etype = 'Comment' rtype = 'comments' @@ -310,7 +307,7 @@ class EditCommentAction(Action): id = 'edit_comment' - __selectors__ = (one_line_rset, implements('Comment'), has_permission('update')) + __select__ = one_line_rset() & implements('Comment') & has_permission('update') title = _('edit comment') category = 'hidden' @@ -319,5 +316,6 @@ def url(self): return self.build_url(rql=self.rset.printable_rql(), vid='edition') + # add some comments related methods to the Jsoncontroller ##################### @@ -322,9 +320,8 @@ # add some comments related methods to the Jsoncontroller ##################### -from cubicweb.web.views.basecontrollers import JSonController - +@monkeypatch(JSonController) def js_add_comment(self, commented, text, format): rql = 'INSERT Comment C: C content %(text)s, C content_format %(format)s, C comments X WHERE X eid %(x)s' rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : commented}, 'x') return u'' @@ -326,12 +323,11 @@ def js_add_comment(self, commented, text, format): rql = 'INSERT Comment C: C content %(text)s, C content_format %(format)s, C comments X WHERE X eid %(x)s' rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : commented}, 'x') return u'' -JSonController.js_add_comment = js_add_comment - +@monkeypatch(JSonController) def js_edit_comment(self, comment, text, format): rql = 'SET C content %(text)s, C content_format %(format)s WHERE C eid %(x)s' rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : comment}, 'x') return u'' @@ -333,6 +329,5 @@ def js_edit_comment(self, comment, text, format): rql = 'SET C content %(text)s, C content_format %(format)s WHERE C eid %(x)s' rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : comment}, 'x') return u'' -JSonController.js_edit_comment = js_edit_comment