[form] cache field value in form.formvalues using (field, form) key since in some case the same field instance may be shared accross multiple forms, which may share the formvalues dict in case of sub-forms stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 23 Feb 2010 12:51:20 +0100
branchstable
changeset 4661 87672c718c3c
parent 4660 21ed77792c33
child 4662 79c0788ba7f6
[form] cache field value in form.formvalues using (field, form) key since in some case the same field instance may be shared accross multiple forms, which may share the formvalues dict in case of sub-forms
web/formfields.py
--- a/web/formfields.py	Tue Feb 23 12:49:37 2010 +0100
+++ b/web/formfields.py	Tue Feb 23 12:51:20 2010 +0100
@@ -352,9 +352,9 @@
     def process_form_value(self, form):
         """process posted form and return correctly typed value"""
         try:
-            return form.formvalues[self]
+            return form.formvalues[(self, form)]
         except KeyError:
-            value = form.formvalues[self] = self._process_form_value(form)
+            value = form.formvalues[(self, form)] = self._process_form_value(form)
             return value
 
     def _process_form_value(self, form):
@@ -600,7 +600,7 @@
             if data:
                 encoding = self.encoding(form)
                 try:
-                    form.formvalues[self] = unicode(data.getvalue(), encoding)
+                    form.formvalues[(self, form)] = unicode(data.getvalue(), encoding)
                 except UnicodeError:
                     pass
                 else:
@@ -820,7 +820,7 @@
             for field in form.root_form.fields_by_name('__linkto'):
                 if field.value in searchedvalues:
                     form.root_form.remove_field(field)
-            form.formvalues[self] = value
+            form.formvalues[(self, form)] = value
 
     def format_single_value(self, req, value):
         return value
@@ -828,13 +828,13 @@
     def process_form_value(self, form):
         """process posted form and return correctly typed value"""
         try:
-            return form.formvalues[self]
+            return form.formvalues[(self, form)]
         except KeyError:
             value = self._process_form_value(form)
             # if value is None, there are some remaining pending fields, we'll
             # have to recompute this later -> don't cache in formvalues
             if value is not None:
-                form.formvalues[self] = value
+                form.formvalues[(self, form)] = value
             return value
 
     def _process_form_value(self, form):