--- a/web/request.py Fri Jul 03 16:50:13 2009 +0200
+++ b/web/request.py Fri Jul 03 17:57:19 2009 +0200
@@ -61,6 +61,7 @@
class CubicWebRequestBase(DBAPIRequest):
"""abstract HTTP request, should be extended according to the HTTP backend"""
+ json_request = False # to be set to True by json controllers
def __init__(self, vreg, https, form=None):
super(CubicWebRequestBase, self).__init__(vreg)
--- a/web/views/basecontrollers.py Fri Jul 03 16:50:13 2009 +0200
+++ b/web/views/basecontrollers.py Fri Jul 03 17:57:19 2009 +0200
@@ -196,7 +196,7 @@
except NoSelectableObject:
return (False, {None: req._('not authorized')})
try:
- ctrl.publish(None, fromjson=True)
+ ctrl.publish(None)
except ValidationError, ex:
req.cnx.rollback()
return (False, _validation_error(req, ex))
@@ -219,6 +219,7 @@
id = 'validateform'
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)
@@ -243,6 +244,7 @@
note: it's the responsability of js_* methods to set the correct
response content type
"""
+ self.req.json_request = True
self.req.pageid = self.req.form.get('pageid')
try:
fname = self.req.form['fname']
--- a/web/views/editcontroller.py Fri Jul 03 16:50:13 2009 +0200
+++ b/web/views/editcontroller.py Fri Jul 03 17:57:19 2009 +0200
@@ -25,9 +25,8 @@
class EditController(ViewController):
id = 'edit'
- def publish(self, rset=None, fromjson=False):
+ def publish(self, rset=None):
"""edit / create / copy / delete entity / relations"""
- self.fromjson = fromjson
for key in self.req.form:
# There should be 0 or 1 action
if key.startswith('__action_'):
@@ -115,7 +114,7 @@
except ValidationError, ex:
# ex.entity may be an int or an entity instance
self._to_create[formparams['eid']] = ex.entity
- if self.fromjson:
+ if self.req.json_request: # XXX (syt) why?
ex.entity = formparams['eid']
raise
self._to_create[formparams['eid']] = eid