# HG changeset patch
# User sylvain.thenault@logilab.fr
# Date 1231865966 -3600
#      Tue Jan 13 17:59:26 2009 +0100
# Node ID 380ac8079ae3d486f98d448acba6302195aba54f
# Parent  4c96b71b1c1b4a6e529b534210e4cac527c47476
minor refactoring, use optional relation to get creator

diff --git a/views.py b/views.py
--- a/views.py
+++ b/views.py
@@ -237,15 +237,6 @@
         req = self.req
         req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') )
         eid = self.rset[0][0]
-        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'
-        rset = req.execute(rql, {'x': eid}, 'x')
         self.w(u'<div id="%s" class="%s" cubicweb:rooteid="%s">' % (
             self.div_id(), self.div_class(), eid))
         action = self.vreg.select_action('reply_comment', req, self.rset, row=0)
@@ -257,7 +248,19 @@
                 req.add_js('fckeditor.js')
                 req.fckeditor_config()
         else:
-            reply = u''
+            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'
+        from cubicweb.server import set_debug
+        set_debug(True)
+        rset = req.execute(rql, {'x': eid}, 'x')
+        set_debug(False)
         if rset.rowcount:
             self.w(u'<h4>%s</h4>%s' % (req._('Comment_plural'), reply))
             self.w(u'<div id="comment%sHolder"></div>' % eid)
@@ -265,10 +268,9 @@
             for i in xrange(rset.rowcount):
                 self.wview('tree', rset, row=i, full=True)
             self.w(u'</ul>')
-        else:
+        elif reply:
             self.w(reply)
-            if reply:
-                self.w(u'<div id="comment%sHolder"></div>' % eid)
+            self.w(u'<div id="comment%sHolder"></div>' % eid)
         self.w(u'</div>')
 
 baseviews.PRIMARY_SKIP_RELS.add('comments') # displayed by the above component