[views] cleanup, be less heavy with self.w ...
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 11 Feb 2009 15:59:40 +0100
changeset 602 1454282a8b45
parent 582 0260b3b71d71
child 603 18c6c31bbaf4
[views] cleanup, be less heavy with self.w ...
web/views/management.py
--- a/web/views/management.py	Wed Feb 11 15:20:49 2009 +0100
+++ b/web/views/management.py	Wed Feb 11 15:59:40 2009 +0100
@@ -23,7 +23,7 @@
 from cubicweb.web.form import FormMixIn
 
 _ = unicode
-            
+
 def begin_form(w, entity, redirectvid, redirectpath=None, msg=None):
     w(u'<form method="post" action="%s">\n' % entity.req.build_url('edit'))
     w(u'<fieldset>\n')
@@ -42,10 +42,10 @@
     """display security information for a given entity"""
     id = 'security'
     title = _('security')
-        
+
     def cell_call(self, row, col):
-        self.req.add_js('cubicweb.edition.js')            
-        self.req.add_css('cubicweb.acl.css')            
+        self.req.add_js('cubicweb.edition.js')
+        self.req.add_css('cubicweb.acl.css')
         entity = self.entity(row, col)
         w = self.w
         _ = self.req._
@@ -90,7 +90,7 @@
             w(u'<td>%s</td>' % u'<br/>'.join(expr.expression for expr in rqlexprs))
             w(u'</tr>\n')
         w(u'</table>')
-        
+
     def owned_by_edit_form(self, entity):
         self.w('<h3>%s</h3>' % self.req._('ownership'))
         begin_form(self.w, entity, 'security', msg= _('ownerships have been changed'))
@@ -169,7 +169,7 @@
         wdg = newperm.get_widget('label')
         w(u'<td>%s</td>\n' % wdg.edit_render(newperm))
         wdg = newperm.get_widget('require_group')
-        w(u'<td>%s</td>\n' % wdg.edit_render(newperm))            
+        w(u'<td>%s</td>\n' % wdg.edit_render(newperm))
         w(u'<td>%s</td></tr>\n' % self.button_ok())
         w(u'</table>')
         w(u'</fieldset></form>\n')
@@ -178,12 +178,12 @@
         return (u'<input class="validateButton" type="submit" name="submit" value="%s"/>'
                 % self.req._(stdmsgs.BUTTON_OK))
 
-        
+
 class ErrorView(AnyRsetView):
     """default view when no result has been found"""
     __selectors__ = (yes,)
     id = 'error'
-    
+
     def page_title(self):
         """returns a title according to the result set - used for the
         title in the HTML header
@@ -192,11 +192,11 @@
 
     def call(self):
         req = self.req.reset_headers()
-        _ = req._
+        _ = req._; w = self.w
         ex = req.data.get('ex')#_("unable to find exception information"))
         excinfo = req.data.get('excinfo')
         title = _('an error occured')
-        self.w(u'<h2>%s</h2>' % title)
+        w(u'<h2>%s</h2>' % title)
         if 'errmsg' in req.data:
             ex = req.data['errmsg']
             exclass = None
@@ -205,53 +205,53 @@
             ex = exc_message(ex, req.encoding)
         if excinfo is not None and self.config['print-traceback']:
             if exclass is None:
-                self.w(u'<div class="tb">%s</div>'
+                w(u'<div class="tb">%s</div>'
                        % html_escape(ex).replace("\n","<br />"))
             else:
-                self.w(u'<div class="tb">%s: %s</div>'
+                w(u'<div class="tb">%s: %s</div>'
                        % (exclass, html_escape(ex).replace("\n","<br />")))
-            self.w(u'<hr />')
-            self.w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, ''))
+            w(u'<hr />')
+            w(u'<div class="tb">%s</div>' % html_traceback(excinfo, ex, ''))
         else:
-            self.w(u'<div class="tb">%s</div>' % (html_escape(ex).replace("\n","<br />")))
+            w(u'<div class="tb">%s</div>' % (html_escape(ex).replace("\n","<br />")))
         # if excinfo is not None, it's probably not a bug
         if excinfo is None:
             return
         vcconf = self.config.vc_config()
-        self.w(u"<div>")
+        w(u"<div>")
         eversion = vcconf.get('cubicweb', _('no version information'))
         # NOTE: tuple wrapping needed since eversion is itself a tuple
-        self.w(u"<b>CubicWeb version:</b> %s<br/>\n" % (eversion,))
+        w(u"<b>CubicWeb version:</b> %s<br/>\n" % (eversion,))
         for pkg in self.config.cubes():
             pkgversion = vcconf.get(pkg, _('no version information'))
-            self.w(u"<b>Package %s version:</b> %s<br/>\n" % (pkg, pkgversion))
-        self.w(u"</div>")
+            w(u"<b>Package %s version:</b> %s<br/>\n" % (pkg, pkgversion))
+        w(u"</div>")
         # creates a bug submission link if SUBMIT_URL is set
         submiturl = self.config['submit-url']
         if submiturl:
             binfo = text_error_description(ex, excinfo, req, eversion,
                                            [(pkg, vcconf.get(pkg, _('no version information')))
                                             for pkg in self.config.cubes()])
-            self.w(u'<form action="%s" method="post">\n' % html_escape(submiturl))
-            self.w(u'<fieldset>\n')
-            self.w(u'<textarea class="hidden" name="description">%s</textarea>' % html_escape(binfo))
-            self.w(u'<input type="hidden" name="description_format" value="text/rest"/>')
-            self.w(u'<input type="hidden" name="__bugreporting" value="1"/>')
-            self.w(u'<input type="submit" value="%s"/>' % _('Submit bug report'))
-            self.w(u'</fieldset>\n')
-            self.w(u'</form>\n')
+            w(u'<form action="%s" method="post">\n' % html_escape(submiturl))
+            w(u'<fieldset>\n')
+            w(u'<textarea class="hidden" name="description">%s</textarea>' % html_escape(binfo))
+            w(u'<input type="hidden" name="description_format" value="text/rest"/>')
+            w(u'<input type="hidden" name="__bugreporting" value="1"/>')
+            w(u'<input type="submit" value="%s"/>' % _('Submit bug report'))
+            w(u'</fieldset>\n')
+            w(u'</form>\n')
         submitmail = self.config['submit-mail']
         if submitmail:
             binfo = text_error_description(ex, excinfo, req, eversion,
                                            [(pkg, vcconf.get(pkg, _('no version information')))
                                             for pkg in self.config.cubes()])
-            self.w(u'<form action="%s" method="post">\n' % req.build_url('reportbug'))
-            self.w(u'<fieldset>\n')
-            self.w(u'<input type="hidden" name="description" value="%s"/>' % html_escape(binfo))
-            self.w(u'<input type="hidden" name="__bugreporting" value="1"/>')
-            self.w(u'<input type="submit" value="%s"/>' % _('Submit bug report by mail'))
-            self.w(u'</fieldset>\n')
-            self.w(u'</form>\n')
+            w(u'<form action="%s" method="post">\n' % req.build_url('reportbug'))
+            w(u'<fieldset>\n')
+            w(u'<input type="hidden" name="description" value="%s"/>' % html_escape(binfo))
+            w(u'<input type="hidden" name="__bugreporting" value="1"/>')
+            w(u'<input type="submit" value="%s"/>' % _('Submit bug report by mail'))
+            w(u'</fieldset>\n')
+            w(u'</form>\n')
 
 
 def exc_message(ex, encoding):
@@ -262,7 +262,7 @@
             return unicode(str(ex), encoding, 'replace')
         except:
             return unicode(repr(ex), encoding, 'replace')
-    
+
 def text_error_description(ex, excinfo, req, eversion, cubes):
     binfo = rest_traceback(excinfo, html_escape(ex))
     binfo += u'\n\n:URL: %s\n' % req.url()
@@ -290,14 +290,14 @@
     title = _('site configuration')
     require_groups = ('managers',)
     category = 'startupview'
-    
+
     def linkable(self):
         return True
-    
+
     def url(self):
         """return the url associated with this view. We can omit rql here"""
         return self.build_url('view', vid=self.id)
-    
+
     def call(self, **kwargs):
         """The default view representing the application's index"""
         self.req.add_js('cubicweb.edition.js')
@@ -322,7 +322,7 @@
         for group, objects in groupedopts.items():
             for oid, keys in objects.items():
                 groupedopts[group][oid] = self.form(keys, True)
-        
+
         w = self.w
         req = self.req
         _ = req._
@@ -352,21 +352,21 @@
                 w(form)
                 w(u'</fieldset>')
             w(u'</div>')
-            
-                
+
+
 
     @property
     @cached
     def eprops_rset(self):
         return self.req.execute('Any P,K,V WHERE P is EProperty, P pkey K, P value V, NOT P for_user U')
-    
+
     @property
     def defined_keys(self):
         values = {}
         for i, entity in enumerate(self.eprops_rset.entities()):
             values[entity.pkey] = i
         return values
-    
+
     def entity_for_key(self, key):
         values = self.defined_keys
         if key in values:
@@ -391,11 +391,11 @@
             w(u'<input type="hidden" name="__redirectparams" value="%s"/>\n'
               % html_escape(params))
         w(u'<input type="hidden" name="__redirectpath" value="%s"/>\n' % path)
-        #w(u'<input type="hidden" name="__redirectrql" value=""/>\n') 
+        #w(u'<input type="hidden" name="__redirectrql" value=""/>\n')
         w(u'<input type="hidden" name="__message" value="%s"/>\n'
           % self.req._('changes applied'))
         w(u'<table><tr><td>\n')
-       
+
         w(u'<table>\n')
         for key in keys:
             w(u'<tr>\n')
@@ -409,7 +409,7 @@
         w(u'</fieldset>\n')
         w(u'</form>\n')
         return stream.getvalue()
-        
+
     def form_row(self, w, key, splitlabel):
         entity = self.entity_for_key(key)
         eid = entity.eid
@@ -434,10 +434,10 @@
         w(u'<input type="hidden" name="%s" value="%s"/>' % (eid_param('pkey', eid), key))
         w(u'<input type="hidden" name="%s" value="%s"/>' % (eid_param('edits-pkey', eid), ''))
 
-        
+
 class EpropertiesForm(SystemEpropertiesForm):
     id = 'epropertiesform'
-    title = _('preferences')    
+    title = _('preferences')
     require_groups = ('users', 'managers') # we don't want guests to be able to come here
     __selectors__ = chainfirst(none_rset,
                                chainall(one_line_rset, accept_rset)),
@@ -449,7 +449,7 @@
             row = 0
         score = super(EpropertiesForm, cls).accept_rset(req, rset, row, col)
         # check current user is the rset user or he is in the managers group
-        if score and (req.user.eid == rset[row][col or 0] 
+        if score and (req.user.eid == rset[row][col or 0]
                       or req.user.matching_groups('managers')):
             return score
         return 0
@@ -459,7 +459,7 @@
         if self.rset is None:
             return self.req.user
         return self.rset.get_entity(self.row or 0, self.col or 0)
-    
+
     @property
     @cached
     def eprops_rset(self):
@@ -476,9 +476,9 @@
               % (eid_param('edits-for_user', eid), INTERNAL_FIELD_VALUE))
             w(u'<input type="hidden" name="%s" value="%s"/>'
               % (eid_param('for_user', eid), self.user.eid))
-    
-                   
-    
+
+
+
 
 class ProcessInformationView(StartupView):
     id = 'info'