cleanup
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 21 Dec 2009 19:52:21 +0100
changeset 4160 3fbdeef9a610
parent 4159 6b2b20c73d59
child 4161 4273f5094651
cleanup
web/formfields.py
web/formwidgets.py
web/views/autoform.py
web/views/editcontroller.py
web/views/editforms.py
--- a/web/formfields.py	Mon Dec 21 19:45:24 2009 +0100
+++ b/web/formfields.py	Mon Dec 21 19:52:21 2009 +0100
@@ -13,6 +13,7 @@
 from logilab.mtconverter import xml_escape
 from logilab.common.decorators import cached
 
+from yams.schema import KNOWN_METAATTRIBUTES
 from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
                               FormatConstraint)
 
@@ -570,6 +571,7 @@
     def process_form_value(self, form):
         return int(Field.process_form_value(self, form))
 
+
 class BooleanField(Field):
     widget = Radio
 
@@ -581,6 +583,7 @@
     def process_form_value(self, form):
         return bool(Field.process_form_value(self, form))
 
+
 class FloatField(IntField):
     def format_single_value(self, req, value):
         formatstr = req.property_value('ui.float-format')
@@ -594,6 +597,7 @@
     def process_form_value(self, form):
         return float(Field.process_form_value(self, form))
 
+
 class DateField(StringField):
     format_prop = 'ui.date-format'
     widget = DateTimePicker
@@ -613,6 +617,7 @@
             date = form.parse_date(wdgdate, 'Date')
         return date
 
+
 class DateTimeField(DateField):
     format_prop = 'ui.datetime-format'
 
@@ -625,6 +630,7 @@
             date = form.parse_datetime(date, 'Datetime')
         return date
 
+
 class TimeField(DateField):
     format_prop = 'ui.time-format'
     widget = TextInput
@@ -639,16 +645,6 @@
         return time
 
 class RelationField(Field):
-    # XXX (syt): iirc, we originaly don't sort relation vocabulary since we want
-    # to let entity.unrelated_rql control this, usually to get most recently
-    # modified entities in the select box instead of by alphabetical order. Now,
-    # we first use unrelated_rql to get the vocabulary, which may be limited
-    # (hence we get the latest modified entities) and we can sort here for
-    # better readability
-    #
-    # def __init__(self, **kwargs):
-    #     kwargs.setdefault('sort', False)
-    #     super(RelationField, self).__init__(**kwargs)
 
     @staticmethod
     def fromcardinality(card, **kwargs):
@@ -657,7 +653,6 @@
 
     def vocabulary(self, form):
         entity = form.edited_entity
-        req = entity._cw
         # first see if its specified by __linkto form parameters
         linkedto = entity.linked_to(self.name, self.role)
         if linkedto:
@@ -767,7 +762,7 @@
                     kwargs['max_length'] = cstr.max
             return StringField(**kwargs)
         if fieldclass is FileField:
-            for metadata in ('format', 'encoding', 'name'):
+            for metadata in KNOWN_METAATTRIBUTES:
                 metaschema = eschema.has_metadata(rschema, metadata)
                 if metaschema is not None:
                     kwargs['%s_field' % metadata] = guess_field(eschema, metaschema,
--- a/web/formwidgets.py	Mon Dec 21 19:45:24 2009 +0100
+++ b/web/formwidgets.py	Mon Dec 21 19:52:21 2009 +0100
@@ -10,11 +10,12 @@
 from datetime import date
 from warnings import warn
 
+from logilab.mtconverter import xml_escape
+from logilab.common.deprecation import deprecated
+
 from cubicweb import tags, uilib
 from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE, ProcessFormError
 
-from logilab.mtconverter import xml_escape
-
 class FieldWidget(object):
     """abstract widget class"""
     # javascript / css files required by the widget
@@ -125,6 +126,7 @@
             return passwd1.encode('utf-8')
         raise ProcessFormError(form._cw._("password and confirmation don't match"))
 
+
 class PasswordSingleInput(Input):
     """<input type='password'> without a confirmation field"""
     type = 'password'
@@ -135,6 +137,7 @@
             return value.encode('utf-8')
         return value
 
+
 class FileInput(Input):
     """<input type='file'>"""
     type = 'file'
--- a/web/views/autoform.py	Mon Dec 21 19:45:24 2009 +0100
+++ b/web/views/autoform.py	Mon Dec 21 19:52:21 2009 +0100
@@ -5,6 +5,7 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+
 __docformat__ = "restructuredtext en"
 _ = unicode
 
@@ -318,7 +319,7 @@
         by default true if there is no related entity or if the relation has
         multiple cardinality
         """
-        return not existant or card in '+*'
+        return not existant or card in '+*' # XXX add target type permisssions
 
     def should_hide_add_new_relation_link(self, rschema, card):
         """return true if once an inlined creation form is added, the 'add new'
--- a/web/views/editcontroller.py	Mon Dec 21 19:45:24 2009 +0100
+++ b/web/views/editcontroller.py	Mon Dec 21 19:52:21 2009 +0100
@@ -7,9 +7,9 @@
 """
 __docformat__ = "restructuredtext en"
 
-from decimal import Decimal
+from rql.utils import rqlvar_maker
 
-from rql.utils import rqlvar_maker
+from logilab.common.textutils import splitstrip
 
 from cubicweb import Binary, ValidationError, typed_eid
 from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, NothingToEdit, ProcessFormError
@@ -17,11 +17,6 @@
 from cubicweb.web.views.basecontrollers import ViewController
 
 
-class ToDoLater(Exception):
-    """exception used in the edit controller to indicate that a relation
-    can't be handled right now and have to be handled later
-    """
-
 class RqlQuery(object):
     def __init__(self):
         self.edited = []
@@ -48,6 +43,7 @@
         self.kwargs[var] = eid
         return rql
 
+
 class EditController(ViewController):
     __regid__ = 'edit'
 
--- a/web/views/editforms.py	Mon Dec 21 19:45:24 2009 +0100
+++ b/web/views/editforms.py	Mon Dec 21 19:52:21 2009 +0100
@@ -253,6 +253,7 @@
         form.event_args = event_args
         return form
 
+
 class DummyForm(object):
     __slots__ = ('event_args',)
     def form_render(self, **_args):
@@ -264,6 +265,7 @@
     def field_by_name(self, rtype, role):
         return None
 
+
 class AutoClickAndEditFormView(ClickAndEditFormView):
     """same as ClickAndEditFormView but checking if the view *should* be applied
     by checking uicfg configuration and composite relation property.
@@ -296,6 +298,7 @@
     def _build_renderer(self, entity, rtype, role):
         pass
 
+
 class EditionFormView(FormViewMixIn, EntityView):
     """display primary entity edition form"""
     __regid__ = 'edition'