Skip to content
Snippets Groups Projects
Commit 3e9b0974739c authored by sylvain thenault's avatar sylvain thenault
Browse files

3.2 update

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