46 |
46 |
47 def session_key(self): |
47 def session_key(self): |
48 """return the key that may be used to store / retreive data about a |
48 """return the key that may be used to store / retreive data about a |
49 previous post which failed because of a validation error |
49 previous post which failed because of a validation error |
50 """ |
50 """ |
51 |
|
52 def __init__(self, req, rset, **kwargs): |
|
53 super(FormMixIn, self).__init__(req, rset, **kwargs) |
|
54 self.restore_previous_post(self.session_key()) |
|
55 try: |
51 try: |
56 return self.force_session_key |
52 return self.force_session_key |
57 except AttributeError: |
53 except AttributeError: |
58 return '%s#%s' % (self.req.url(), self.domid) |
54 return '%s#%s' % (self.req.url(), self.domid) |
59 |
55 |
63 # no more available), they have to be deleted by application's publish |
59 # no more available), they have to be deleted by application's publish |
64 # method on successful commit |
60 # method on successful commit |
65 forminfo = self.req.get_session_data(sessionkey, pop=True) |
61 forminfo = self.req.get_session_data(sessionkey, pop=True) |
66 if forminfo: |
62 if forminfo: |
67 # XXX remove req.data assigment once cw.web.widget is killed |
63 # XXX remove req.data assigment once cw.web.widget is killed |
68 self.req.data['formvalues'] = self.form_previous_values = forminfo['values'] |
64 self.req.data['formvalues'] = self._form_previous_values = forminfo['values'] |
69 self.req.data['formerrors'] = self.form_valerror = forminfo['errors'] |
65 self.req.data['formerrors'] = self._form_valerror = forminfo['errors'] |
70 self.req.data['displayederrors'] = self.form_displayed_errors = set() |
66 self.req.data['displayederrors'] = self.form_displayed_errors = set() |
71 # if some validation error occured on entity creation, we have to |
67 # if some validation error occured on entity creation, we have to |
72 # get the original variable name from its attributed eid |
68 # get the original variable name from its attributed eid |
73 foreid = self.form_valerror.entity |
69 foreid = self.form_valerror.entity |
74 for var, eid in forminfo['eidmap'].items(): |
70 for var, eid in forminfo['eidmap'].items(): |
76 self.form_valerror.eid = var |
72 self.form_valerror.eid = var |
77 break |
73 break |
78 else: |
74 else: |
79 self.form_valerror.eid = foreid |
75 self.form_valerror.eid = foreid |
80 else: |
76 else: |
81 self.form_previous_values = {} |
77 self._form_previous_values = {} |
82 self.form_valerror = None |
78 self._form_valerror = None |
|
79 |
|
80 @property |
|
81 def form_previous_values(self): |
|
82 if self.parent_form is None: |
|
83 return self._form_previous_values |
|
84 return self.parent_form.form_previous_values |
|
85 |
|
86 @property |
|
87 def form_valerror(self): |
|
88 if self.parent_form is None: |
|
89 return self._form_valerror |
|
90 return self.parent_form.form_valerror |
83 |
91 |
84 # XXX deprecated with new form system. Should disappear |
92 # XXX deprecated with new form system. Should disappear |
85 |
93 |
86 domid = 'entityForm' |
94 domid = 'entityForm' |
87 category = 'form' |
95 category = 'form' |