refactor session_key (__errorurl) to handle cases where the form is generated throuhg an ajax call: in case of an entity form, return the entity's absolute url. Also allow to force session key value
--- a/web/form.py Fri Nov 27 09:10:40 2009 +0100
+++ b/web/form.py Fri Nov 27 09:14:31 2009 +0100
@@ -42,16 +42,20 @@
"""abstract form mix-in
XXX: you should inherit from this FIRST (obscure pb with super call)
"""
+ force_session_key = None
def session_key(self):
"""return the key that may be used to store / retreive data about a
previous post which failed because of a validation error
"""
- return '%s#%s' % (self.req.url(), self.domid)
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:
+ return '%s#%s' % (self.req.url(), self.domid)
def restore_previous_post(self, sessionkey):
# get validation session data which may have been previously set.
--- a/web/views/forms.py Fri Nov 27 09:10:40 2009 +0100
+++ b/web/views/forms.py Fri Nov 27 09:14:31 2009 +0100
@@ -276,6 +276,19 @@
if msg:
self.form_add_hidden('__message', msg)
+ def session_key(self):
+ """return the key that may be used to store / retreive data about a
+ previous post which failed because of a validation error
+ """
+ try:
+ return self.force_session_key
+ except AttributeError:
+ # XXX if this is a json request, suppose we should redirect to the
+ # entity primary view
+ if self.req.json_request:
+ return '%s#%s' % (self.edited_entity.absolute_url(), self.domid)
+ return '%s#%s' % (self.req.url(), self.domid)
+
def _field_has_error(self, field):
"""return true if the field has some error in given validation exception
"""