fix previous post values handling (eg on validation error) for sub-forms stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 27 Nov 2009 09:15:30 +0100
branchstable
changeset 3923 be05eeeb2db1
parent 3922 69020a7c234a
child 3924 4347654979e8
fix previous post values handling (eg on validation error) for sub-forms
web/form.py
web/views/forms.py
--- a/web/form.py	Fri Nov 27 09:14:31 2009 +0100
+++ b/web/form.py	Fri Nov 27 09:15:30 2009 +0100
@@ -48,10 +48,6 @@
         """return the key that may be used to store / retreive data about a
         previous post which failed because of a validation error
         """
-
-    def __init__(self, req, rset, **kwargs):
-        super(FormMixIn, self).__init__(req, rset, **kwargs)
-        self.restore_previous_post(self.session_key())
         try:
             return self.force_session_key
         except AttributeError:
@@ -65,8 +61,8 @@
         forminfo = self.req.get_session_data(sessionkey, pop=True)
         if forminfo:
             # XXX remove req.data assigment once cw.web.widget is killed
-            self.req.data['formvalues'] = self.form_previous_values = forminfo['values']
-            self.req.data['formerrors'] = self.form_valerror = forminfo['errors']
+            self.req.data['formvalues'] = self._form_previous_values = forminfo['values']
+            self.req.data['formerrors'] = self._form_valerror = forminfo['errors']
             self.req.data['displayederrors'] = self.form_displayed_errors = set()
             # if some validation error occured on entity creation, we have to
             # get the original variable name from its attributed eid
@@ -78,8 +74,20 @@
             else:
                 self.form_valerror.eid = foreid
         else:
-            self.form_previous_values = {}
-            self.form_valerror = None
+            self._form_previous_values = {}
+            self._form_valerror = None
+
+    @property
+    def form_previous_values(self):
+        if self.parent_form is None:
+            return self._form_previous_values
+        return self.parent_form.form_previous_values
+
+    @property
+    def form_valerror(self):
+        if self.parent_form is None:
+            return self._form_valerror
+        return self.parent_form.form_valerror
 
     # XXX deprecated with new form system. Should disappear
 
--- a/web/views/forms.py	Fri Nov 27 09:14:31 2009 +0100
+++ b/web/views/forms.py	Fri Nov 27 09:15:30 2009 +0100
@@ -89,6 +89,8 @@
         if mainform:
             self.form_add_hidden('__errorurl', self.session_key())
             self.form_add_hidden('__domid', self.domid)
+            self.restore_previous_post(self.session_key())
+
         # XXX why do we need two different variables (mainform and copy_nav_params ?)
         if self.copy_nav_params:
             for param in NAV_FORM_PARAMETERS: