--- a/web/views/basecontrollers.py Tue Sep 15 16:00:03 2009 +0200
+++ b/web/views/basecontrollers.py Tue Sep 15 16:02:17 2009 +0200
@@ -11,6 +11,7 @@
__docformat__ = "restructuredtext en"
from smtplib import SMTP
+import datetime
import simplejson
@@ -181,48 +182,54 @@
break
return (foreid, ex.errors)
+
def _validate_form(req, vreg):
# XXX should use the `RemoteCallFailed` mechanism
try:
ctrl = vreg['controllers'].select('edit', req=req)
except NoSelectableObject:
- return (False, {None: req._('not authorized')})
+ return (False, {None: req._('not authorized')}, None)
try:
ctrl.publish(None)
except ValidationError, ex:
- return (False, _validation_error(req, ex))
+ return (False, _validation_error(req, ex), ctrl._edited_entity)
except Redirect, ex:
+ if ctrl._edited_entity:
+ ctrl._edited_entity.complete()
try:
req.cnx.commit() # ValidationError may be raise on commit
except ValidationError, ex:
- return (False, _validation_error(req, ex))
+ return (False, _validation_error(req, ex), ctrl._edited_entity)
else:
- return (True, ex.location)
+ return (True, ex.location, ctrl._edited_entity)
except Exception, ex:
req.cnx.rollback()
req.exception('unexpected error while validating form')
- return (False, req._(str(ex).decode('utf-8')))
- return (False, '???')
+ return (False, req._(str(ex).decode('utf-8')), ctrl._edited_entity)
+ return (False, '???', None)
class FormValidatorController(Controller):
id = 'validateform'
- def response(self, domid, status, args):
+ def response(self, domid, status, args, entity):
+ callback = str(self.req.form.get('__onsuccess', 'null'))
+ errback = str(self.req.form.get('__onfailure', 'null'))
self.req.set_content_type('text/html')
- jsargs = simplejson.dumps( (status, args) )
+ jsargs = simplejson.dumps((status, args, entity), cls=CubicWebJsonEncoder)
return """<script type="text/javascript">
- window.parent.handleFormValidationResponse('%s', null, null, %s);
-</script>""" % (domid, jsargs)
+ wp = window.parent;
+ window.parent.handleFormValidationResponse('%s', %s, %s, %s);
+</script>""" % (domid, callback, errback, jsargs)
def publish(self, rset=None):
self.req.json_request = True
# XXX unclear why we have a separated controller here vs
# js_validate_form on the json controller
- status, args = _validate_form(self.req, self.vreg)
+ status, args, entity = _validate_form(self.req, self.vreg)
domid = self.req.form.get('__domid', 'entityForm').encode(
self.req.encoding)
- return self.response(domid, status, args)
+ return self.response(domid, status, args, entity)
class JSonController(Controller):