flake8 uicfg
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 16 Nov 2016 15:55:35 +0100
changeset 11854 056de1196ef8
parent 11853 c71339453c1e
child 11855 e6cdc4d3add5
flake8 uicfg
cubicweb/web/views/uicfg.py
flake8-ok-files.txt
--- a/cubicweb/web/views/uicfg.py	Wed Nov 16 15:52:55 2016 +0100
+++ b/cubicweb/web/views/uicfg.py	Wed Nov 16 15:55:35 2016 +0100
@@ -54,9 +54,6 @@
    uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
 """
 
-
-from warnings import warn
-
 from six import string_types
 
 from cubicweb import neg_role
@@ -93,6 +90,7 @@
                     section = 'sideboxes'
             self.tag_relation((sschema, rschema, oschema, role), section)
 
+
 primaryview_section = PrimaryViewSectionRelationTags()
 
 
@@ -155,7 +153,7 @@
 # * 'hidden'
 # * 'subobject' (not displayed by default)
 
-class InitializableDict(dict): # XXX not a rtag. Turn into an appobject?
+class InitializableDict(dict):  # XXX not a rtag. Turn into an appobject?
     def __init__(self, *args, **kwargs):
         super(InitializableDict, self).__init__(*args, **kwargs)
         self.__defaults = dict(self)
@@ -174,12 +172,13 @@
             else:
                 self.setdefault(eschema, 'application')
 
+
 indexview_etype_section = InitializableDict(
     EmailAddress='subobject',
     Bookmark='system',
     # entity types in the 'system' table by default (managers only)
     CWUser='system', CWGroup='system',
-    )
+)
 
 
 # autoform.AutomaticEntityForm configuration ##################################
@@ -191,6 +190,7 @@
         result[formtype] = section
     return result
 
+
 def _card_and_comp(sschema, rschema, oschema, role):
     rdef = rschema.rdef(sschema, oschema)
     if role == 'subject':
@@ -201,6 +201,7 @@
         composed = not rschema.final and rdef.composite == 'subject'
     return card, composed
 
+
 class AutoformSectionRelationTags(RelationTagsSet):
     """autoform relations'section"""
     __regid__ = 'autoform_section'
@@ -237,26 +238,26 @@
             sectdict.setdefault('muledit', 'hidden')
             sectdict.setdefault('inlined', 'hidden')
         # ensure we have a tag for each form type
-        if not 'main' in sectdict:
+        if 'main' not in sectdict:
             if sschema.is_metadata(rschema):
                 sectdict['main'] = 'metadata'
             else:
                 card, composed = _card_and_comp(sschema, rschema, oschema, role)
                 if card in '1+':
                     sectdict['main'] = 'attributes'
-                    if not 'muledit' in sectdict:
+                    if 'muledit' not in sectdict:
                         sectdict['muledit'] = 'attributes'
                 elif rschema.final:
                     sectdict['main'] = 'attributes'
                 else:
                     sectdict['main'] = 'relations'
-        if not 'muledit' in sectdict:
+        if 'muledit' not in sectdict:
             sectdict['muledit'] = 'hidden'
             if sectdict['main'] == 'attributes':
                 card, composed = _card_and_comp(sschema, rschema, oschema, role)
                 if card in '1+' and not composed:
                     sectdict['muledit'] = 'attributes'
-        if not 'inlined' in sectdict:
+        if 'inlined' not in sectdict:
             sectdict['inlined'] = sectdict['main']
         # recompute formsections and set it to avoid recomputing
         for formtype, section in sectdict.items():
@@ -268,11 +269,11 @@
                 self.tag_relation(key, ftype, section)
             return
         assert formtype in self._allowed_form_types, \
-               'formtype should be in (%s), not %s' % (
-            ','.join(self._allowed_form_types), formtype)
+            'formtype should be in (%s), not %s' % (
+                ','.join(self._allowed_form_types), formtype)
         assert section in self._allowed_values[formtype], \
-               'section for %s should be in (%s), not %s' % (
-            formtype, ','.join(self._allowed_values[formtype]), section)
+            'section for %s should be in (%s), not %s' % (
+                formtype, ','.join(self._allowed_values[formtype]), section)
         rtags = self._tagdefs.setdefault(_ensure_str_key(key),
                                          self.tag_container_cls())
         # remove previous section for this form type if any
@@ -293,8 +294,8 @@
                 section, value = tag.split('_', 1)
                 rtags[section] = value
         cls = self.tag_container_cls
-        rtags = cls('_'.join([section,value])
-                    for section,value in rtags.items())
+        rtags = cls('_'.join([section, value])
+                    for section, value in rtags.items())
         return rtags
 
     def get(self, *key):
@@ -310,9 +311,10 @@
           bool telling if having local role is enough (strict = False) or not
         """
         tag = '%s_%s' % (formtype, section)
-        eschema  = entity.e_schema
+        eschema = entity.e_schema
         cw = entity._cw
-        permsoverrides = cw.vreg['uicfg'].select('autoform_permissions_overrides', cw, entity=entity)
+        permsoverrides = cw.vreg['uicfg'].select('autoform_permissions_overrides', cw,
+                                                 entity=entity)
         if entity.has_eid():
             eid = entity.eid
         else:
@@ -329,7 +331,7 @@
             for tschema in targetschemas:
                 # check section's tag first, potentially lower cost than
                 # checking permission which may imply rql queries
-                if not tag in self.etype_get(eschema, rschema, role, tschema):
+                if tag not in self.etype_get(eschema, rschema, role, tschema):
                     continue
                 rdef = rschema.role_rdef(eschema, tschema, role)
                 if rschema.final:
@@ -351,7 +353,8 @@
             # XXX tag allowing to hijack the permission machinery when
             # permission is not verifiable until the entity is actually
             # created...
-            if eid is None and '%s_on_new' % permission in permsoverrides.etype_get(eschema, rschema, role):
+            if eid is None and '%s_on_new' % permission in permsoverrides.etype_get(
+                    eschema, rschema, role):
                 yield (rschema, targetschemas, role)
                 continue
             if not rschema.final and role == 'subject':
@@ -481,6 +484,7 @@
         for attr in attrs:
             self.edit_as_attr(self, etype, attr, formtype='muledit')
 
+
 autoform_section = AutoformSectionRelationTags()
 
 
@@ -500,6 +504,7 @@
         """
         self._tag_etype_attr(etype, attr, '*', field)
 
+
 autoform_field = AutoformFieldTags()
 
 
@@ -561,6 +566,7 @@
 class AutoFormPermissionsOverrides(RelationTagsSet):
     __regid__ = 'autoform_permissions_overrides'
 
+
 autoform_permissions_overrides = AutoFormPermissionsOverrides()
 
 
@@ -616,12 +622,13 @@
                 edittarget = 'related' if composite else 'rtype'
                 self.tag_relation((sschema, rschema, oschema, role),
                                   {'edit_target': edittarget})
-        if not 'novalue_include_rtype' in values:
+        if 'novalue_include_rtype' not in values:
             showlabel = primaryview_display_ctrl.get(
                 sschema, rschema, oschema, role).get('showlabel', True)
             self.tag_relation((sschema, rschema, oschema, role),
                               {'novalue_include_rtype': not showlabel})
 
+
 reledit_ctrl = ReleditTags()
 
 
@@ -656,7 +663,8 @@
 
         :param etype: the entity type as a string
         :param attr: the name of the attribute or relation to hide
-        :param createdtype: the target type of the relation (optional, defaults to '*' (all possible types))
+        :param createdtype: the target type of the relation
+                            (optional, defaults to '*' (all possible types))
 
         `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
 
@@ -668,16 +676,17 @@
 
         :param etype: the entity type as a string
         :param attr: the name of the attribute or relation to hide
-        :param createdtype: the target type of the relation (optional, defaults to '*' (all possible types))
+        :param createdtype: the target type of the relation
+                            (optional, defaults to '*' (all possible types))
 
         `attr` can be a string or 2-tuple (relname, role_of_etype_in_the_relation)
         """
         self._tag_etype_attr(etype, attr, createdtype, False)
 
+
 actionbox_appearsin_addmenu = ActionBoxUicfg()
 
 
-
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__)
     indexview_etype_section.init(vreg.schema)
--- a/flake8-ok-files.txt	Wed Nov 16 15:52:55 2016 +0100
+++ b/flake8-ok-files.txt	Wed Nov 16 15:55:35 2016 +0100
@@ -82,6 +82,7 @@
 cubicweb/web/test/unittest_views_json.py
 cubicweb/web/views/json.py
 cubicweb/web/views/searchrestriction.py
+cubicweb/web/views/uicfg.py
 cubicweb/xy.py
 cubicweb/pyramid/auth.py
 cubicweb/pyramid/bwcompat.py