# HG changeset patch
# User sylvain.thenault@logilab.fr
# Date 1240423243 -7200
#      Wed Apr 22 20:00:43 2009 +0200
# Branch tls-sprint
# Node ID 7f7bbe35bfdb139e790943ce58fd950ffe4e1e78
# Parent  f1010c58ee2b9192ae5f16e71830ac8468502a80
lint cleanup

diff --git a/hooks.py b/hooks.py
--- a/hooks.py
+++ b/hooks.py
@@ -1,7 +1,7 @@
 """Comment notification hooks
 
 :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"
@@ -21,7 +21,7 @@
         return '%s %s %s' % (self.req._('new comment for'),
                              root.dc_type(),
                              root.dc_title())
-    
+
     def cell_call(self, row, col=0, **kwargs):
         self.row, self.col = row, col
         try:
@@ -29,5 +29,4 @@
                                          row=row, col=col)
         except RegistryException:
             return
-        entity = self.entity(row, col)
         return view.dispatch(row=row, col=col, w=self.w, **kwargs)
diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -14,14 +14,15 @@
 from simplejson import dumps
 
 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.selectors import match_kwargs, accept
 from cubicweb.common.uilib import rql_for_eid, cut, safe_cut, ajax_replace_url
 from cubicweb.common.mixins import TreeViewMixIn
 from cubicweb.web import stdmsgs, uicfg
 from cubicweb.web.action import LinkToEntityAction, Action
 from cubicweb.web.form import FormViewMixIn
+from cubicweb.web.formwidgets import Button
 from cubicweb.web.views import baseviews
 from cubicweb.web.component import EntityVComponent
 from cubicweb.web.views.basecontrollers import JSonController
@@ -57,12 +58,14 @@
         # don't include responses in this view, since the comment section
         # component will display them
         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
         if hasattr(self, 'generated_by') and self.generated_by:
-            origlink = '<a href="%s">%s</a>' % (self.generated_by[0].absolute_url(),
-                                                self.generated_by[0].dc_type().lower())
-            txt = self.req._('this comment has been generated from this %s') % origlink
+            gen = self.generated_by[0]
+            link = '<a href="%s">%s</a>' % (gen.absolute_url(),
+                                            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>\n')
 
@@ -80,8 +83,8 @@
         maxsize = maxsize - len(str(root.eid))
         content = entity.printable_value('content', format='text/plain')
         content = html_escape(cut(content, maxsize))
-        self.w(u'<a href="%s">#%s <i>%s</i></a>\n' % (html_escape(entity.absolute_url()),
-                                                      entity.eid, content))
+        self.w(u'<a href="%s">#%s <i>%s</i></a>\n' % (
+            html_escape(entity.absolute_url()), entity.eid, content))
 
 
 class CommentOneLineView(CommentSecondaryView):
@@ -97,7 +100,6 @@
         self.req.add_js('cubicweb.ajax.js')
         self.req.add_css('cubes.comment.css')
         entity = self.entity(row, col)
-        diem = self.format_date(entity.creation_date)
         action = self.vreg.select_action('reply_comment', self.req, self.rset,
                                          row=row)
         editaction = self.vreg.select_action('edit_comment', self.req, self.rset,
@@ -107,13 +109,15 @@
         else:
             url = ajax_replace_url('comment%sHolder' % entity.eid,
                                    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:
             edit = u''
         else:
             url = ajax_replace_url('comment%s' % entity.eid,
                                    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')
         if not kwargs.get('full'):
             maxsize = self.req.property_value('navigation.short-line-size')
@@ -122,7 +126,8 @@
         self.w(self.format_date(entity.creation_date))
         if entity.creator:
             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>' % edit)
         self.w(u'</div>\n')
@@ -153,6 +158,7 @@
 class InlineCommentForm(FormViewMixIn, EntityView):
     id = 'inlinecommentform'
     __select__ = match_kwargs('commented') # explicit call when it makes sense
+    jsfunc = "processComment(%s, '%s')"
 
     def call(self, commented):
         self.initialize_varmaker()
@@ -163,18 +169,19 @@
     def comment_form(self, commented, newcomment=None):
         self.req.add_js('cubes.comment.js')
         if newcomment is None:
-            newcomment = comment
+            newcomment = commented
         # hack to avoid tabindex conflicts caused by Ajax requests
         self.req.next_tabindex = count(20).next
         jseid = dumps(commented.eid)
-        buttons = [Button(onclick="processComment(%s, 'add_comment')" % jseid),
-                   Button(stdmsgs.BUTTON_CANCEL, onclick="processComment(%s, '')" % jseid)]
+        buttons = [Button(onclick=self.jsfunc % (jseid, 'add_comment')),
+                   Button(stdmsgs.BUTTON_CANCEL,
+                          onclick=self.jsfunc % (jseid, ''))]
         form = self.vreg.select_object('forms', 'edition', self.req,
                                        entity=newcomment,
                                        form_buttons=buttons,
                                        attrcategories=('primary',))
         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):
@@ -192,11 +199,12 @@
     related to an object
     """
     id = 'commentsection'
-    __select__ = EntityVComponent.__select__ & relation_possible('comments', 'object', 'Comment')
+    __select__ = (EntityVComponent.__select__
+                  & relation_possible('comments', 'object', 'Comment'))
 
     context = 'navcontentbottom'
 
-    def cell_call(self, row, col, view=None, orderby='diem'):
+    def cell_call(self, row, col, view=None):
         req = self.req
         req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') )
         eid = self.rset[row][col]
@@ -204,20 +212,16 @@
             self.div_id(), self.div_class(), eid))
         action = self.vreg.select_action('reply_comment', req, self.rset, row=0)
         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))
             if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html':
                 req.fckeditor_config()
         else:
             reply = u''
-        if orderby == 'author':
-            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 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'
+        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')
         if rset.rowcount:
             self.w(u'<h4>%s</h4>%s' % (req._('Comment_plural'), reply))
@@ -288,13 +292,13 @@
 
 @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''
+    self.req.execute('INSERT Comment C: C comments X, C content %(text)s, '
+                     'C content_format %(format)s  WHERE X eid %(x)s',
+                     {'format' : format, 'text' : text, 'x' : commented}, 'x')
 
 @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''
+    self.req.execute('SET C content %(text)s, C content_format %(format)s '
+                     'WHERE C eid %(x)s',
+                     {'format' : format, 'text' : text, 'x' : comment}, 'x')