[mq]: fix_for_forms
authorArthur Lutz <arthur.lutz@logilab.fr>
Thu, 10 Dec 2009 18:00:15 +0100
changeset 4110 8728d8c95985
parent 4109 841bc459d5e8
child 4135 cb0d0bf255f7
[mq]: fix_for_forms
web/formfields.py
web/views/autoform.py
web/views/editcontroller.py
--- a/web/formfields.py	Thu Dec 10 17:59:32 2009 +0100
+++ b/web/formfields.py	Thu Dec 10 18:00:15 2009 +0100
@@ -565,6 +565,15 @@
     def format_single_value(self, req, value):
         return value
 
+    def process_form_value(self, form):
+        """process posted form and return correctly typed value"""
+        widget = self.get_widget(form)
+        value = widget.process_field_data(form, self)
+        if value is None:
+            return ()
+        elif not isinstance(value, list):
+            return (value,)
+        return value
 
 class CompoundField(Field):
     def __init__(self, fields, *args, **kwargs):
--- a/web/views/autoform.py	Thu Dec 10 17:59:32 2009 +0100
+++ b/web/views/autoform.py	Thu Dec 10 18:00:15 2009 +0100
@@ -408,3 +408,5 @@
     def etype_relation_field(etype, rtype, role='subject'):
         eschema = vreg.schema.eschema(etype)
         return AutomaticEntityForm.field_by_name(rtype, role, eschema)
+
+    vreg.register_all(globals().values(), __name__)
--- a/web/views/editcontroller.py	Thu Dec 10 17:59:32 2009 +0100
+++ b/web/views/editcontroller.py	Thu Dec 10 18:00:15 2009 +0100
@@ -226,14 +226,17 @@
     def handle_inlined_relation(self, form, field, entity, rqlquery):
         """handle edition for the (rschema, x) relation of the given entity
         """
-        origvalues = set(row[0] for row in entity.related(field.name, field.role))
+        if entity.has_eid():
+            origvalues = set(row[0] for row in entity.related(field.name, field.role))
+        else:
+            origvalues = set()
         values  = self._relation_values(form, field, entity)
         if values is None or values == origvalues:
             return # not edited / not modified / to do later
         attr = field.name
         if values:
             rqlquery.kwargs[attr] = iter(values).next()
-            rqlquery.edition.append('X %s %s' % (attr, attr.upper()))
+            rqlquery.edited.append('X %s %s' % (attr, attr.upper()))
             rqlquery.restrictions.append('%s eid %%(%s)s' % (attr.upper(), attr))
         elif entity.has_eid():
             self.relations_rql += self.handle_relation(form, field, entity)
@@ -241,7 +244,10 @@
     def handle_relation(self, form, field, entity, late=False):
         """handle edition for the (rschema, x) relation of the given entity
         """
-        origvalues = set(row[0] for row in entity.related(field.name, field.role))
+        if entity.has_eid():
+            origvalues = set(row[0] for row in entity.related(field.name, field.role))
+        else:
+            origvalues = set()
         values  = self._relation_values(form, field, entity, late)
         if values is None or values == origvalues:
             return # not edited / not modified / to do later