# HG changeset patch # User Arthur Lutz # Date 1260464415 -3600 # Node ID 8728d8c95985388c0f6d4034bf9340caa194b639 # Parent 841bc459d5e86a297469d896f9c150ecdea64348 [mq]: fix_for_forms diff -r 841bc459d5e8 -r 8728d8c95985 web/formfields.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): diff -r 841bc459d5e8 -r 8728d8c95985 web/views/autoform.py --- 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__) diff -r 841bc459d5e8 -r 8728d8c95985 web/views/editcontroller.py --- 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