[forms] edited_entity must be set before calling session_key() stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 04 Jan 2010 18:58:35 +0100
branchstable
changeset 4206 cebdf8ee5ad7
parent 4205 4458c7cc193b
child 4207 0198acbae080
[forms] edited_entity must be set before calling session_key() EntityFieldsForm.__init__ calls FieldsForm.__init__ which in turn calls self.session_key(). self.session_key() uses self.edited_key to compute the correct session key. We thus need edited_entity to be set **before** calling super's __init__. The bug only occured when EntityFieldsForm was selected because of its one_line_rset() selector instead of match_kwargs('entity').
web/views/forms.py
--- a/web/views/forms.py	Wed Dec 23 13:05:53 2009 +0100
+++ b/web/views/forms.py	Mon Jan 04 18:58:35 2010 +0100
@@ -268,12 +268,15 @@
     internal_fields = FieldsForm.internal_fields + ('__type', 'eid', '__maineid')
     domid = 'entityForm'
 
-    def __init__(self, *args, **kwargs):
-        self.edited_entity = kwargs.pop('entity', None)
+    def __init__(self, req, rset=None, *args, **kwargs):
+        # entity was either explicitly specified or we have a one line rset
+        if 'entity' in kwargs:
+            self.edited_entity = kwargs.pop('entity')
+        else:
+            self.edited_entity = rset.get_entity(0, 0)
+            self.edited_entity.complete()
         msg = kwargs.pop('submitmsg', None)
-        super(EntityFieldsForm, self).__init__(*args, **kwargs)
-        if self.edited_entity is None:
-            self.edited_entity = self.complete_entity(self.row or 0, self.col or 0)
+        super(EntityFieldsForm, self).__init__(req, rset, *args, **kwargs)
         self.form_add_hidden('__type', eidparam=True)
         self.form_add_hidden('eid')
         if kwargs.get('mainform', True): # mainform default to true in parent