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

lint cleanup

parent f1010c58ee2b
No related branches found
No related tags found
No related merge requests found
"""Comment notification hooks """Comment notification hooks
: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"
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
return '%s %s %s' % (self.req._('new comment for'), return '%s %s %s' % (self.req._('new comment for'),
root.dc_type(), root.dc_type(),
root.dc_title()) root.dc_title())
def cell_call(self, row, col=0, **kwargs): def cell_call(self, row, col=0, **kwargs):
self.row, self.col = row, col self.row, self.col = row, col
try: try:
...@@ -29,5 +29,4 @@ ...@@ -29,5 +29,4 @@
row=row, col=col) row=row, col=col)
except RegistryException: except RegistryException:
return return
entity = self.entity(row, col)
return view.dispatch(row=row, col=col, w=self.w, **kwargs) return view.dispatch(row=row, col=col, w=self.w, **kwargs)
...@@ -14,5 +14,6 @@ ...@@ -14,5 +14,6 @@
from simplejson import dumps from simplejson import dumps
from cubicweb.selectors import (one_line_rset, but_etype, implements, from cubicweb.selectors import (one_line_rset, but_etype, implements,
has_permission, relation_possible, yes) has_permission, relation_possible, yes,
match_kwargs)
from cubicweb.view import EntityView from cubicweb.view import EntityView
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
from cubicweb.view import EntityView 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
from cubicweb.common.mixins import TreeViewMixIn from cubicweb.common.mixins import TreeViewMixIn
from cubicweb.web import stdmsgs, uicfg from cubicweb.web import stdmsgs, uicfg
from cubicweb.web.action import LinkToEntityAction, Action from cubicweb.web.action import LinkToEntityAction, Action
from cubicweb.web.form import FormViewMixIn from cubicweb.web.form import FormViewMixIn
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
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.mixins import TreeViewMixIn from cubicweb.common.mixins import TreeViewMixIn
from cubicweb.web import stdmsgs, uicfg from cubicweb.web import stdmsgs, uicfg
from cubicweb.web.action import LinkToEntityAction, Action from cubicweb.web.action import LinkToEntityAction, Action
from cubicweb.web.form import FormViewMixIn from cubicweb.web.form import FormViewMixIn
from cubicweb.web.formwidgets import Button
from cubicweb.web.views import baseviews from cubicweb.web.views import baseviews
from cubicweb.web.component import EntityVComponent from cubicweb.web.component import EntityVComponent
from cubicweb.web.views.basecontrollers import JSonController from cubicweb.web.views.basecontrollers import JSonController
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
# don't include responses in this view, since the comment section # don't include responses in this view, since the comment section
# component will display them # component will display them
self.w(u'</div>\n') self.w(u'</div>\n')
self.w(u'<div class="commentBody">%s</div>\n' % entity.printable_value('content')) self.w(u'<div class="commentBody">%s</div>\n'
% entity.printable_value('content'))
# XXX attribute generated_by added by email component # XXX attribute generated_by added by email component
if hasattr(self, 'generated_by') and self.generated_by: if hasattr(self, 'generated_by') and self.generated_by:
...@@ -61,8 +63,9 @@ ...@@ -61,8 +63,9 @@
# XXX attribute generated_by added by email component # XXX attribute generated_by added by email component
if hasattr(self, 'generated_by') and self.generated_by: if hasattr(self, 'generated_by') and self.generated_by:
origlink = '<a href="%s">%s</a>' % (self.generated_by[0].absolute_url(), gen = self.generated_by[0]
self.generated_by[0].dc_type().lower()) link = '<a href="%s">%s</a>' % (gen.absolute_url(),
txt = self.req._('this comment has been generated from this %s') % origlink gen.dc_type().lower())
txt = self.req._('this comment has been generated from this %s') % link
self.w(u'<div class="commentBottom">%s</div>\n' % txt) self.w(u'<div class="commentBottom">%s</div>\n' % txt)
self.w(u'</div>\n') self.w(u'</div>\n')
...@@ -80,8 +83,8 @@ ...@@ -80,8 +83,8 @@
maxsize = maxsize - len(str(root.eid)) maxsize = maxsize - len(str(root.eid))
content = entity.printable_value('content', format='text/plain') content = entity.printable_value('content', format='text/plain')
content = html_escape(cut(content, maxsize)) content = html_escape(cut(content, maxsize))
self.w(u'<a href="%s">#%s <i>%s</i></a>\n' % (html_escape(entity.absolute_url()), self.w(u'<a href="%s">#%s <i>%s</i></a>\n' % (
entity.eid, content)) html_escape(entity.absolute_url()), entity.eid, content))
class CommentOneLineView(CommentSecondaryView): class CommentOneLineView(CommentSecondaryView):
...@@ -97,7 +100,6 @@ ...@@ -97,7 +100,6 @@
self.req.add_js('cubicweb.ajax.js') self.req.add_js('cubicweb.ajax.js')
self.req.add_css('cubes.comment.css') self.req.add_css('cubes.comment.css')
entity = self.entity(row, col) entity = self.entity(row, col)
diem = self.format_date(entity.creation_date)
action = self.vreg.select_action('reply_comment', self.req, self.rset, action = self.vreg.select_action('reply_comment', self.req, self.rset,
row=row) row=row)
editaction = self.vreg.select_action('edit_comment', self.req, self.rset, editaction = self.vreg.select_action('edit_comment', self.req, self.rset,
...@@ -107,9 +109,10 @@ ...@@ -107,9 +109,10 @@
else: else:
url = ajax_replace_url('comment%sHolder' % entity.eid, url = ajax_replace_url('comment%sHolder' % entity.eid,
rql_for_eid(entity.eid), 'inlinecomment') rql_for_eid(entity.eid), 'inlinecomment')
reply = ' | <a href="%s">%s</a>' % (html_escape(url), _(action.title)) reply = ' | <a href="%s">%s</a>' % (html_escape(url),
_(action.title))
if editaction is None: if editaction is None:
edit = u'' edit = u''
else: else:
url = ajax_replace_url('comment%s' % entity.eid, url = ajax_replace_url('comment%s' % entity.eid,
rql_for_eid(entity.eid), 'editcomment') rql_for_eid(entity.eid), 'editcomment')
...@@ -111,9 +114,10 @@ ...@@ -111,9 +114,10 @@
if editaction is None: if editaction is None:
edit = u'' edit = u''
else: else:
url = ajax_replace_url('comment%s' % entity.eid, url = ajax_replace_url('comment%s' % entity.eid,
rql_for_eid(entity.eid), 'editcomment') rql_for_eid(entity.eid), 'editcomment')
edit = ' | <a href="%s">%s</a>' % (html_escape(url), _(editaction.title)) edit = ' | <a href="%s">%s</a>' % (html_escape(url),
_(editaction.title))
text = entity.printable_value('content') text = entity.printable_value('content')
if not kwargs.get('full'): if not kwargs.get('full'):
maxsize = self.req.property_value('navigation.short-line-size') maxsize = self.req.property_value('navigation.short-line-size')
...@@ -122,7 +126,8 @@ ...@@ -122,7 +126,8 @@
self.w(self.format_date(entity.creation_date)) self.w(self.format_date(entity.creation_date))
if entity.creator: if entity.creator:
authorlink = entity.creator.view('oneline') authorlink = entity.creator.view('oneline')
self.w(u', %s <span class="author">%s</span> \n' % (_('written by'), authorlink,)) self.w(u', %s <span class="author">%s</span> \n' % (_('written by'),
authorlink,))
self.w(u'<span class="replyto"> %s </span>' % reply) self.w(u'<span class="replyto"> %s </span>' % reply)
self.w(u'<span class="replyto"> %s </span>' % edit) self.w(u'<span class="replyto"> %s </span>' % edit)
self.w(u'</div>\n') self.w(u'</div>\n')
...@@ -153,6 +158,7 @@ ...@@ -153,6 +158,7 @@
class InlineCommentForm(FormViewMixIn, EntityView): class InlineCommentForm(FormViewMixIn, EntityView):
id = 'inlinecommentform' id = 'inlinecommentform'
__select__ = match_kwargs('commented') # explicit call when it makes sense __select__ = match_kwargs('commented') # explicit call when it makes sense
jsfunc = "processComment(%s, '%s')"
def call(self, commented): def call(self, commented):
self.initialize_varmaker() self.initialize_varmaker()
...@@ -163,7 +169,7 @@ ...@@ -163,7 +169,7 @@
def comment_form(self, commented, newcomment=None): def comment_form(self, commented, newcomment=None):
self.req.add_js('cubes.comment.js') self.req.add_js('cubes.comment.js')
if newcomment is None: if newcomment is None:
newcomment = comment newcomment = commented
# hack to avoid tabindex conflicts caused by Ajax requests # hack to avoid tabindex conflicts caused by Ajax requests
self.req.next_tabindex = count(20).next self.req.next_tabindex = count(20).next
jseid = dumps(commented.eid) jseid = dumps(commented.eid)
...@@ -167,10 +173,11 @@ ...@@ -167,10 +173,11 @@
# hack to avoid tabindex conflicts caused by Ajax requests # hack to avoid tabindex conflicts caused by Ajax requests
self.req.next_tabindex = count(20).next self.req.next_tabindex = count(20).next
jseid = dumps(commented.eid) jseid = dumps(commented.eid)
buttons = [Button(onclick="processComment(%s, 'add_comment')" % jseid), buttons = [Button(onclick=self.jsfunc % (jseid, 'add_comment')),
Button(stdmsgs.BUTTON_CANCEL, onclick="processComment(%s, '')" % jseid)] Button(stdmsgs.BUTTON_CANCEL,
onclick=self.jsfunc % (jseid, ''))]
form = self.vreg.select_object('forms', 'edition', self.req, form = self.vreg.select_object('forms', 'edition', self.req,
entity=newcomment, entity=newcomment,
form_buttons=buttons, form_buttons=buttons,
attrcategories=('primary',)) attrcategories=('primary',))
self.w(u'<div id="comment%sSlot">%s</div>' % ( self.w(u'<div id="comment%sSlot">%s</div>' % (
...@@ -172,9 +179,9 @@ ...@@ -172,9 +179,9 @@
form = self.vreg.select_object('forms', 'edition', self.req, form = self.vreg.select_object('forms', 'edition', self.req,
entity=newcomment, entity=newcomment,
form_buttons=buttons, form_buttons=buttons,
attrcategories=('primary',)) attrcategories=('primary',))
self.w(u'<div id="comment%sSlot">%s</div>' % ( self.w(u'<div id="comment%sSlot">%s</div>' % (
commented.eid, form.form_render(display_relations_form=False)) commented.eid, form.form_render(display_relations_form=False)))
class InlineEditCommentForm(InlineCommentForm): class InlineEditCommentForm(InlineCommentForm):
...@@ -192,7 +199,8 @@ ...@@ -192,7 +199,8 @@
related to an object related to an object
""" """
id = 'commentsection' id = 'commentsection'
__select__ = EntityVComponent.__select__ & relation_possible('comments', 'object', 'Comment') __select__ = (EntityVComponent.__select__
& relation_possible('comments', 'object', 'Comment'))
context = 'navcontentbottom' context = 'navcontentbottom'
...@@ -196,7 +204,7 @@ ...@@ -196,7 +204,7 @@
context = 'navcontentbottom' context = 'navcontentbottom'
def cell_call(self, row, col, view=None, orderby='diem'): def cell_call(self, row, col, view=None):
req = self.req req = self.req
req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') ) req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') )
eid = self.rset[row][col] eid = self.rset[row][col]
...@@ -204,9 +212,10 @@ ...@@ -204,9 +212,10 @@
self.div_id(), self.div_class(), eid)) self.div_id(), self.div_class(), eid))
action = self.vreg.select_action('reply_comment', req, self.rset, row=0) action = self.vreg.select_action('reply_comment', req, self.rset, row=0)
if action is not None: if action is not None:
url = ajax_replace_url('comment%sHolder' % eid, rql_for_eid(eid), 'inlinecomment') url = ajax_replace_url('comment%sHolder' % eid, rql_for_eid(eid),
'inlinecomment')
reply = u' (<a href="%s">%s</a>)' % (url, req._(action.title)) reply = u' (<a href="%s">%s</a>)' % (url, req._(action.title))
if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html': if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html':
req.fckeditor_config() req.fckeditor_config()
else: else:
reply = u'' reply = u''
...@@ -208,16 +217,11 @@ ...@@ -208,16 +217,11 @@
reply = u' (<a href="%s">%s</a>)' % (url, req._(action.title)) reply = u' (<a href="%s">%s</a>)' % (url, req._(action.title))
if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html': if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html':
req.fckeditor_config() req.fckeditor_config()
else: else:
reply = u'' reply = u''
if orderby == 'author': rql = u'Any C,CD,CC,CCF,U,UL,US,UF ORDERBY CD WHERE C is Comment, '\
rql = u'Any C,CD,CC,CCF,U,UL,US,UF ORDERBY UL WHERE C is Comment, '\ 'C comments X, C creation_date CD, C content CC, C content_format CCF, ' \
'C comments X, C creation_date CD, C content CC, C content_format CCF, ' \ 'C created_by U?, U login UL, U firstname UF, U surname US, X eid %(x)s'
'C created_by U?, U login UL, U firstname UF, U surname US, X eid %(x)s'
else: # orderby == 'diem'
rql = u'Any C,CD,CC,CCF,U,UL,US,UF ORDERBY CD WHERE C is Comment, '\
'C comments X, C creation_date CD, C content CC, C content_format CCF, ' \
'C created_by U?, U login UL, U firstname UF, U surname US, X eid %(x)s'
rset = req.execute(rql, {'x': eid}, 'x') rset = req.execute(rql, {'x': eid}, 'x')
if rset.rowcount: if rset.rowcount:
self.w(u'<h4>%s</h4>%s' % (req._('Comment_plural'), reply)) self.w(u'<h4>%s</h4>%s' % (req._('Comment_plural'), reply))
...@@ -288,9 +292,9 @@ ...@@ -288,9 +292,9 @@
@monkeypatch(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' self.req.execute('INSERT Comment C: C comments X, C content %(text)s, '
rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : commented}, 'x') 'C content_format %(format)s WHERE X eid %(x)s',
return u'' {'format' : format, 'text' : text, 'x' : commented}, 'x')
@monkeypatch(JSonController) @monkeypatch(JSonController)
def js_edit_comment(self, comment, text, format): def js_edit_comment(self, comment, text, format):
...@@ -294,7 +298,7 @@ ...@@ -294,7 +298,7 @@
@monkeypatch(JSonController) @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' self.req.execute('SET C content %(text)s, C content_format %(format)s '
rset = self.req.execute(rql, {'format' : format, 'text' : text, 'x' : comment}, 'x') 'WHERE C eid %(x)s',
return u'' {'format' : format, 'text' : text, 'x' : comment}, 'x')
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