fix retreival of previously submitted error for entity forms tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 28 Apr 2009 19:09:37 +0200
branchtls-sprint
changeset 1519 5cfc5cc1dd20
parent 1518 8f4d2892e809
child 1521 973c5f1dfad4
fix retreival of previously submitted error for entity forms
web/form.py
--- a/web/form.py	Tue Apr 28 19:09:02 2009 +0200
+++ b/web/form.py	Tue Apr 28 19:09:37 2009 +0200
@@ -30,28 +30,6 @@
     http_cache_manager = NoHTTPCacheManager
     add_to_breadcrumbs = False
 
-    def __init__(self, req, rset, **kwargs):
-        super(FormViewMixIn, self).__init__(req, rset, **kwargs)
-        # get validation session data which may have been previously set.
-        # deleting validation errors here breaks form reloading (errors are
-        # no more available), they have to be deleted by application's publish
-        # method on successful commit
-        formurl = req.url()
-        forminfo = req.get_session_data(formurl)
-        if forminfo:
-            req.data['formvalues'] = forminfo['values']
-            req.data['formerrors'] = errex = forminfo['errors']
-            req.data['displayederrors'] = set()
-            # if some validation error occured on entity creation, we have to
-            # get the original variable name from its attributed eid
-            foreid = errex.entity
-            for var, eid in forminfo['eidmap'].items():
-                if foreid == eid:
-                    errex.eid = var
-                    break
-            else:
-                errex.eid = foreid
-
     def html_headers(self):
         """return a list of html headers (eg something to be inserted between
         <head> and </head> of the returned page
@@ -80,22 +58,13 @@
             self.req.set_page_data('rql_varmaker', varmaker)
         self.varmaker = varmaker
 
-    # XXX deprecated with new form system. Should disappear
-
-    domid = 'entityForm'
-    category = 'form'
-    controller = 'edit'
-    http_cache_manager = NoHTTPCacheManager
-    add_to_breadcrumbs = False
-
     def __init__(self, req, rset, **kwargs):
         super(FormMixIn, self).__init__(req, rset, **kwargs)
         # get validation session data which may have been previously set.
         # deleting validation errors here breaks form reloading (errors are
         # no more available), they have to be deleted by application's publish
         # method on successful commit
-        formurl = req.url()
-        forminfo = req.get_session_data(formurl)
+        forminfo = req.get_session_data(req.url())
         if forminfo:
             req.data['formvalues'] = forminfo['values']
             req.data['formerrors'] = errex = forminfo['errors']
@@ -110,6 +79,14 @@
             else:
                 errex.eid = foreid
 
+    # XXX deprecated with new form system. Should disappear
+
+    domid = 'entityForm'
+    category = 'form'
+    controller = 'edit'
+    http_cache_manager = NoHTTPCacheManager
+    add_to_breadcrumbs = False
+
     def html_headers(self):
         """return a list of html headers (eg something to be inserted between
         <head> and </head> of the returned page
@@ -371,10 +348,11 @@
         values found in 1. and 2. are expected te be already some 'display'
         value while those found in 3. and 4. are expected to be correctly typed.
         """
-        if field.name in self._previous_values:
-            value = self._previous_values[field.name]
-        elif field.name in self.req.form:
-            value = self.req.form[field.name]
+        qname = self.form_field_name(field)
+        if qname in self._previous_values:
+            value = self._previous_values[qname]
+        elif qname in self.req.form:
+            value = self.req.form[qname]
         else:
             if field.name in rendervalues:
                 value = rendervalues[field.name]
@@ -449,6 +427,9 @@
                 self.form_add_hidden('__linkto', linkto)
                 msg = '%s %s' % (msg, self.req._('and linked'))
             self.form_add_hidden('__message', msg)
+        # in case of direct instanciation
+        self.schema = self.edited_entity.schema
+        self.vreg = self.edited_entity.vreg
 
     def _errex_match_field(self, errex, field):
         """return true if the field has some error in given validation exception