pep8 bits

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset2dafcdd19c99
branchdefault
phasepublic
hiddenno
parent revision#9b8dcde03499 [i18n] enhance text formats french translation
child revision#97bb66a6809c [migration] add rollback when replace_eid_sequence_with_eid_numrange fails, #4483a4cc197f [devtools/testlib] Conditionally by-pass logilab-common's TestCase.__call__ method, #8bad8fd44e34 [datafeed] attempt to acquire synchronization lock even when force is given, #d09fc5c6bb68 [datafeed] attempt to acquire synchronization lock even when force is given, #bd5ea6c74d85 [web/application] fix query log handling on python3, #c74906f1b167 [tox] Generate test environments for Python 2.7 and 3.4, #499410b147d6 [notification] avoid using InternalManager when we've got a CWUser, #a1ccb934f361 [test] Make sure that newcube command test produces expected files, #afc5853e9d52 [tox] Generate test environments for Python 2.7 and 3.4, #421520f4d516 [server] remove some pre 3.10 compat, #f69791ba1454 [datafeed] attempt to acquire synchronization lock even when force is given, #3ac128b70e61 [test] Make sure that newcube command test produces expected files
files modified by this revision
cubicweb/web/formfields.py
cubicweb/web/views/forms.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1455181431 -3600
# Thu Feb 11 10:03:51 2016 +0100
# Node ID 2dafcdd19c9918f6d0bde86b6afdcaf07c1722b3
# Parent 9b8dcde034998c904c60e6867c4faea15fe5c5b0
pep8 bits

diff --git a/cubicweb/web/formfields.py b/cubicweb/web/formfields.py
@@ -61,11 +61,10 @@
1  .. autofunction:: cubicweb.web.formfields.guess_field
2 
3  """
4  __docformat__ = "restructuredtext en"
5 
6 -from warnings import warn
7  from datetime import datetime, timedelta
8 
9  from six import PY2, text_type, string_types
10 
11  from logilab.mtconverter import xml_escape
@@ -77,40 +76,43 @@
12  from yams.schema import KNOWN_METAATTRIBUTES, role_name
13  from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
14                                FormatConstraint)
15 
16  from cubicweb import Binary, tags, uilib, neg_role
17 -from cubicweb.utils import support_args
18 -from cubicweb.web import INTERNAL_FIELD_VALUE, ProcessFormError, eid_param, \
19 -     formwidgets as fw
20 +from cubicweb.web import (INTERNAL_FIELD_VALUE, ProcessFormError, eid_param,
21 +                          formwidgets as fw)
22  from cubicweb.web.views import uicfg
23 
24 +
25  class UnmodifiedField(Exception):
26      """raise this when a field has not actually been edited and you want to skip
27      it
28      """
29 
30 +
31  def normalize_filename(filename):
32      return filename.split('\\')[-1]
33 
34 +
35  def vocab_sort(vocab):
36      """sort vocabulary, considering option groups"""
37      result = []
38      partresult = []
39      for label, value in vocab:
40 -        if value is None: # opt group start
41 +        if value is None:  # opt group start
42              if partresult:
43                  result += sorted(partresult)
44                  partresult = []
45 -            result.append( (label, value) )
46 +            result.append((label, value))
47          else:
48 -            partresult.append( (label, value) )
49 +            partresult.append((label, value))
50      result += sorted(partresult)
51      return result
52 
53  _MARKER = nullobject()
54 
55 +
56  class Field(object):
57      """This class is the abstract base class for all fields. It hold a bunch
58      of attributes which may be used for fine control of the behaviour of a
59      concrete field.
60 
@@ -478,11 +480,11 @@
61          widget = self.get_widget(form)
62          value = widget.process_field_data(form, self)
63          return self._ensure_correctly_typed(form, value)
64 
65      def _ensure_correctly_typed(self, form, value):
66 -        """widget might to return date as a correctly formatted string or as
67 +        """widget might return e.g. a date as a correctly formatted string or as
68          correctly typed objects, but process_for_value must return a typed value.
69          Override this method to type the value if necessary
70          """
71          return value or None
72 
diff --git a/cubicweb/web/views/forms.py b/cubicweb/web/views/forms.py
@@ -310,11 +310,11 @@
73          called.
74          """
75          try:
76              return super(EntityFieldsForm, cls_or_self).field_by_name(name, role)
77          except form.FieldNotFound:
78 -            if eschema is None or role is None or not name in eschema.schema:
79 +            if eschema is None or role is None or name not in eschema.schema:
80                  raise
81              rschema = eschema.schema.rschema(name)
82              # XXX use a sample target type. Document this.
83              tschemas = rschema.targets(eschema, role)
84              fieldcls = cls_or_self.uicfg_aff.etype_get(
@@ -323,11 +323,11 @@
85                  eschema, rschema, role, tschemas[0])
86              if kwargs is None:
87                  kwargs = {}
88              if fieldcls:
89                  if not isinstance(fieldcls, type):
90 -                    return fieldcls # already and instance
91 +                    return fieldcls  # already and instance
92                  return fieldcls(name=name, role=role, eidparam=True, **kwargs)
93              if isinstance(cls_or_self, type):
94                  req = None
95              else:
96                  req = cls_or_self._cw