pylint cleanup tls-sprint
authorsylvain.thenault@logilab.fr
Thu, 26 Mar 2009 19:00:20 +0100
branchtls-sprint
changeset 1149 1e19b6ef53a1
parent 1148 55a8238f8f7c
child 1150 2d1b721fded9
pylint cleanup
entities/__init__.py
vregistry.py
web/box.py
web/facet.py
web/httpcache.py
web/views/basetemplates.py
web/views/calendar.py
web/views/editviews.py
web/views/eproperties.py
web/views/massmailing.py
web/views/wdoc.py
web/webconfig.py
--- a/entities/__init__.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/entities/__init__.py	Thu Mar 26 19:00:20 2009 +0100
@@ -310,6 +310,7 @@
             tschema = rschema.subjects(cls.e_schema)[0]
             wdg = widget(cls.vreg, tschema, rschema, cls, 'object')
         return wdg
+    
     def relations_by_category(self, categories=None, permission=None):
         if categories is not None:
             if not isinstance(categories, (list, tuple, set, frozenset)):
--- a/vregistry.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/vregistry.py	Thu Mar 26 19:00:20 2009 +0100
@@ -303,14 +303,16 @@
                 winners.append(vobject)
         if not winners:
             raise NoSelectableObject('args: %s\nkwargs: %s %s'
-                                     % (args, kwargs.keys(), [repr(v) for v in vobjects]))
+                                     % (args, kwargs.keys(),
+                                        [repr(v) for v in vobjects]))
         if len(winners) > 1:
             if self.config.mode == 'installed':
                 self.error('select ambiguity, args: %s\nkwargs: %s %s',
                            args, kwargs.keys(), [repr(v) for v in winners])
             else:
                 raise Exception('select ambiguity, args: %s\nkwargs: %s %s'
-                                % (args, kwargs.keys(), [repr(v) for v in winners]))
+                                % (args, kwargs.keys(),
+                                   [repr(v) for v in winners]))
         winner = winners[0]
         # return the result of the .selected method of the vobject
         return winner.selected(*args, **kwargs)
--- a/web/box.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/box.py	Thu Mar 26 19:00:20 2009 +0100
@@ -6,10 +6,9 @@
 """
 __docformat__ = "restructuredtext en"
 
-from logilab.common.decorators import cached
 from logilab.mtconverter import html_escape
 
-from cubicweb import Unauthorized, role as get_role
+from cubicweb import Unauthorized, role as get_role, target as get_target
 from cubicweb.selectors import (one_line_rset,  primary_view,
                                 match_context_prop, partial_has_related_entities,
                                 accepts_compat, has_relation_compat,
@@ -179,18 +178,12 @@
 
     def div_id(self):
         return self.id
-
-    @cached
-    def xtarget(self):
-        if self.target == 'subject':
-            return 'object', 'subject'
-        return 'subject', 'object'
         
     def box_item(self, entity, etarget, rql, label):
         """builds HTML link to edit relation between `entity` and `etarget`
         """
-        x, target = self.xtarget()
-        args = {x[0] : entity.eid, target[0] : etarget.eid}
+        role, target = get_role(self), get_target(self)
+        args = {role[0] : entity.eid, target[0] : etarget.eid}
         url = self.user_rql_callback((rql, args))
         # for each target, provide a link to edit the relation
         label = u'[<a href="%s">%s</a>] %s' % (url, label,
@@ -217,10 +210,9 @@
         if etype is not defined on the Box's class, the default
         behaviour is to use the entity's appropraite vocabulary function
         """
-        x, target = self.xtarget()
         # use entity.unrelated if we've been asked for a particular etype
         if hasattr(self, 'etype'):
-            return entity.unrelated(self.rtype, self.etype, x).entities()
+            return entity.unrelated(self.rtype, self.etype, get_role(self)).entities()
         # in other cases, use vocabulary functions
         entities = []
         for _, eid in entity.vocabulary(self.rtype, x):
@@ -230,6 +222,5 @@
         return entities
         
     def related_entities(self, entity):
-        x, target = self.xtarget()
-        return entity.related(self.rtype, x, entities=True)
+        return entity.related(self.rtype, get_role(self), entities=True)
 
--- a/web/facet.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/facet.py	Thu Mar 26 19:00:20 2009 +0100
@@ -118,12 +118,17 @@
     return None
 
 def _add_rtype_relation(rqlst, mainvar, rtype, role):
+    """add a relation relying `mainvar` to entities linked by the `rtype`
+    relation (where `mainvar` has `role`)
+
+    return the inserted variable for linked entities.
+    """
     newvar = rqlst.make_variable()
     if role == 'object':
-        rel = rqlst.add_relation(newvar, rtype, mainvar)
+        rqlst.add_relation(newvar, rtype, mainvar)
     else:
-        rel = rqlst.add_relation(mainvar, rtype, newvar)
-    return newvar, rel
+        rqlst.add_relation(mainvar, rtype, newvar)
+    return newvar
 
 def _prepare_vocabulary_rqlst(rqlst, mainvar, rtype, role):
     """prepare a syntax tree to generate a filter vocabulary rql using the given
@@ -133,11 +138,11 @@
     * add the new variable to GROUPBY clause if necessary
     * add the new variable to the selection
     """
-    newvar, rel = _add_rtype_relation(rqlst, mainvar, rtype, role)
+    newvar = _add_rtype_relation(rqlst, mainvar, rtype, role)
     if rqlst.groupby:
         rqlst.add_group_var(newvar)
     rqlst.add_selected(newvar)
-    return newvar, rel
+    return newvar
 
 def _remove_relation(rqlst, rel, var):
     """remove a constraint relation from the syntax tree"""
@@ -170,10 +175,10 @@
                                 sortfuncname=None, sortasc=True):
     """modify a syntax tree to retrieve only relevant attribute `attr` of `var`"""
     _cleanup_rqlst(rqlst, mainvar)
-    var, mainrel = _prepare_vocabulary_rqlst(rqlst, mainvar, rtype, role)
+    var = _prepare_vocabulary_rqlst(rqlst, mainvar, rtype, role)
     # not found, create one
     attrvar = rqlst.make_variable()
-    attrrel = rqlst.add_relation(var, attrname, attrvar)
+    rqlst.add_relation(var, attrname, attrvar)
     # if query is grouped, we have to add the attribute variable
     if rqlst.groupby:
         if not attrvar in rqlst.groupby:
@@ -410,7 +415,7 @@
         if not value:
             return
         mainvar = self.filtered_variable
-        restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role)[0]
+        restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role)
         if isinstance(value, basestring):
             # only one value selected
             self.rqlst.add_eid_restriction(restrvar, value)
@@ -424,7 +429,7 @@
             # multiple values with AND operator
             self.rqlst.add_eid_restriction(restrvar, value.pop())
             while value:
-                restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role)[0]
+                restrvar = _add_rtype_relation(self.rqlst, mainvar, self.rtype, self.role)
                 self.rqlst.add_eid_restriction(restrvar, value.pop())
 
 
@@ -442,7 +447,7 @@
         try:
             mainvar = self.filtered_variable
             _cleanup_rqlst(rqlst, mainvar)
-            newvar, rel = _prepare_vocabulary_rqlst(rqlst, mainvar, self.rtype, self.role)
+            newvar = _prepare_vocabulary_rqlst(rqlst, mainvar, self.rtype, self.role)
             _set_orderby(rqlst, newvar, self.sortasc, self.sortfunc)
             try:
                 rset = self.rqlexec(rqlst.as_string(), self.rset.args, self.rset.cachekey)
--- a/web/httpcache.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/httpcache.py	Thu Mar 26 19:00:20 2009 +0100
@@ -92,11 +92,11 @@
 # monkey patching, so view doesn't depends on this module and we have all
 # http cache related logic here
 
-from cubicweb import view
+from cubicweb import view as viewmod
 
 def set_http_cache_headers(self):
     self.http_cache_manager(self).set_headers()
-view.View.set_http_cache_headers = set_http_cache_headers
+viewmod.View.set_http_cache_headers = set_http_cache_headers
 
 def last_modified(self):
     """return the date/time where this view should be considered as
@@ -118,15 +118,15 @@
         mtime = ctime
     # mtime = ctime will force page rerendering
     return mtime
-view.View.last_modified = last_modified
+viewmod.View.last_modified = last_modified
 
 # configure default caching
-view.View.http_cache_manager = NoHTTPCacheManager
+viewmod.View.http_cache_manager = NoHTTPCacheManager
 # max-age=0 to actually force revalidation when needed
-view.View.cache_max_age = 0
+viewmod.View.cache_max_age = 0
 
 
-view.EntityView.http_cache_manager = EntityHTTPCacheManager
+viewmod.EntityView.http_cache_manager = EntityHTTPCacheManager
 
-view.StartupView.http_cache_manager = MaxAgeHTTPCacheManager
-view.StartupView.cache_max_age = 60*60*2 # stay in http cache for 2 hours by default 
+viewmod.StartupView.http_cache_manager = MaxAgeHTTPCacheManager
+viewmod.StartupView.cache_max_age = 60*60*2 # stay in http cache for 2 hours by default 
--- a/web/views/basetemplates.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/basetemplates.py	Thu Mar 26 19:00:20 2009 +0100
@@ -23,7 +23,6 @@
         self.set_request_content_type()
         w = self.w
         self.write_doctype()
-        lang = self.req.lang
         self.template_header('text/html', self.req._('login_action'))
         w(u'<body>\n')
         self.content(w)
--- a/web/views/calendar.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/calendar.py	Thu Mar 26 19:00:20 2009 +0100
@@ -152,7 +152,6 @@
         lastday = last_day_of_month + timedelta(6 - last_day_of_month.weekday())
         month_dates = list(date_range(firstday, lastday))
         dates = {}
-        users = []
         task_max = 0
         for row in xrange(self.rset.rowcount):
             task = self.rset.get_entity(row, 0)
@@ -263,22 +262,22 @@
                                     year=nextdate.year, month=nextdate.month)
         return prevlink, nextlink
 
-    def _build_calendar_cell(self, date, rows, curdate):
+    def _build_calendar_cell(self, celldate, rows, curdate):
         curmonth = curdate.month
         classes = ""
-        if date.month != curmonth:
+        if celldate.month != curmonth:
             classes += " outOfRange"
-        if date == datetime.today():
+        if celldate == date.today():
             classes += " today"
         self.w(u'<td class="cell%s">' % classes)
         self.w(u'<div class="calCellTitle%s">' % classes)
-        self.w(u'<div class="day">%s</div>' % date.day)
+        self.w(u'<div class="day">%s</div>' % celldate.day)
         
         if len(self.rset.column_types(0)) == 1:
             etype = list(self.rset.column_types(0))[0]
             url = self.build_url(vid='creation', etype=etype,
                                  schedule=True,
-                                 start=self.format_date(date), stop=self.format_date(date),
+                                 start=self.format_date(celldate), stop=self.format_date(celldate),
                                  __redirectrql=self.rset.printable_rql(),
                                  __redirectparams=self.req.build_url_params(year=curdate.year, month=curmonth),
                                  __redirectvid=self.id
@@ -434,15 +433,6 @@
         self.w(u'<div id="coord"></div>')
         self.w(u'<div id="debug">&nbsp;</div>')
  
-    def _one_day_task(self, task):
-        """
-        Return true if the task is a "one day" task; ie it have a start and a stop the same day
-        """
-        if task.start and task.stop:
-            if task.start.isocalendar() ==  task.stop.isocalendar():
-                return True
-        return False
-        
     def _build_calendar_cell(self, date, task_descrs):
         inday_tasks = [t for t in task_descrs if t.is_one_day_task() and  t.in_working_hours()]
         wholeday_tasks = [t for t in task_descrs if not t.is_one_day_task()]
--- a/web/views/editviews.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/editviews.py	Thu Mar 26 19:00:20 2009 +0100
@@ -17,7 +17,7 @@
                                 match_search_state, match_form_params)
 from cubicweb.common.uilib import cut
 from cubicweb.web.views import linksearch_select_url
-from cubicweb.web.form import relation_id
+from cubicweb.web.views.editforms import relation_id
 from cubicweb.web.views.baseviews import FinalView
 
 _ = unicode
--- a/web/views/eproperties.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/eproperties.py	Thu Mar 26 19:00:20 2009 +0100
@@ -1,6 +1,5 @@
 """Specific views for EProperty
 
-
 :organization: Logilab
 :copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
@@ -190,7 +189,6 @@
 
     def form_row(self, w, key, splitlabel):
         entity = self.entity_for_key(key)
-        eid = entity.eid
         if splitlabel:
             w(u'<td class="label">%s</td>' % self.req._(key.split('.')[-1]))
         else:
--- a/web/views/massmailing.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/massmailing.py	Thu Mar 26 19:00:20 2009 +0100
@@ -88,7 +88,7 @@
 class MassMailingFormRenderer(FormRenderer):
     button_bar_class = u'toolbar'
     
-    def _render_fields(self, fields, w, form):
+    def _render_fields(self, fields, w, form, values):
         w(u'<table class="headersform">')
         for field in fields:
             if field.name == 'mailbody':
--- a/web/views/wdoc.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/views/wdoc.py	Thu Mar 26 19:00:20 2009 +0100
@@ -74,7 +74,7 @@
             build_toc_index(section, index)
     return index
     
-def title(node, lang):
+def title_for_lang(node, lang):
     for title in node.findall('title'):
         if title.attrib['{http://www.w3.org/XML/1998/namespace}lang'] == lang:
             return unicode(title.text)
@@ -107,7 +107,7 @@
         else:
             self.navigation_links(node)
             self.w(u'<div class="hr"></div>')
-            self.w(u'<h1>%s</h1>' % (title(node, self.req.lang)))            
+            self.w(u'<h1>%s</h1>' % (title_for_lang(node, self.req.lang)))            
         data = open(join(resourcedir, rid)).read()
         self.w(rest_publish(self, data))
         if node is not None:
@@ -141,7 +141,7 @@
         self.w(u'%s : ' % self.req._(msgid))
         self.w(u'<a href="%s">%s</a>' % (
             self.req.build_url('doc/'+node.attrib['resource']),
-            title(node, self.req.lang)))
+            title_for_lang(node, self.req.lang)))
         self.w(u'</span>\n')
         
     def subsections_links(self, node, first=True):
@@ -154,7 +154,7 @@
         for child in sub:
             self.w(u'<li><a href="%s">%s</a>' % (
                 self.req.build_url('doc/'+child.attrib['resource']),
-                title(child, self.req.lang)))
+                title_for_lang(child, self.req.lang)))
             self.subsections_links(child, False)
             self.w(u'</li>')
         self.w(u'</ul>\n')
--- a/web/webconfig.py	Thu Mar 26 18:59:56 2009 +0100
+++ b/web/webconfig.py	Thu Mar 26 19:00:20 2009 +0100
@@ -192,7 +192,7 @@
         try:
             cube = self.cubes()[0]
             cubeeid = self.cube_pkginfo(cube).cube_eid
-        except Exception, ex:
+        except Exception:
             return None
         if cubeeid:
             return 'http://intranet.logilab.fr/jpl/view?__linkto=concerns:%s:subject&etype=Ticket&type=bug&vid=creation' % cubeeid