make it easy to change response of FormValidatorController
authorFlorent <florent@secondweb.fr>
Tue, 28 Jul 2009 22:22:08 +0200
changeset 2557 200985d3258d
parent 2556 4608d259c3db
child 2558 81c8b5312f9c
make it easy to change response of FormValidatorController
web/views/basecontrollers.py
--- a/web/views/basecontrollers.py	Tue Jul 07 13:57:26 2009 +0200
+++ b/web/views/basecontrollers.py	Tue Jul 28 22:22:08 2009 +0200
@@ -221,18 +221,21 @@
 class FormValidatorController(Controller):
     id = 'validateform'
 
+    def response(self, domid, status, args):
+        self.req.set_content_type('text/html')
+        jsargs = simplejson.dumps( (status, args) )
+        return """<script type="text/javascript">
+ window.parent.handleFormValidationResponse('%s', null, null, %s);
+</script>""" %  (domid, 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)
-        self.req.set_content_type('text/html')
-        jsarg = simplejson.dumps( (status, args) )
         domid = self.req.form.get('__domid', 'entityForm').encode(
             self.req.encoding)
-        return """<script type="text/javascript">
- window.parent.handleFormValidationResponse('%s', null, null, %s);
-</script>""" %  (domid, simplejson.dumps( (status, args) ))
+        return self.response(domid, status, args)
 
 
 class JSonController(Controller):