[etwist] nicer, thouhg really not perferct) request max size exceeded support of json/frame posts
--- a/etwist/server.py Tue Apr 20 09:58:28 2010 +0200
+++ b/etwist/server.py Tue Apr 20 10:00:36 2010 +0200
@@ -25,6 +25,8 @@
from twisted.web import static, resource
from twisted.web.server import NOT_DONE_YET
+from simplejson import dumps
+
from logilab.common.decorators import monkeypatch
from cubicweb import AuthenticationError, ConfigurationError, CW_EVENT_MANAGER
@@ -297,17 +299,30 @@
headers=request.headers_out)
+JSON_PATHS = set(('json',))
+FRAME_POST_PATHS = set(('validateform',))
+
orig_gotLength = http.Request.gotLength
@monkeypatch(http.Request)
def gotLength(self, length):
orig_gotLength(self, length)
if length > MAX_POST_LENGTH: # length is 0 on GET
+ path = self.channel._path.split('?', 1)[0].rstrip('/').rsplit('/', 1)[-1]
self.clientproto = 'HTTP/1.1' # not yet initialized
self.channel.persistent = 0 # force connection close on cleanup
- body = ("<html><head><title>Processing Failed</title></head><body>"
- "<b>request max size exceeded</b></body></html>")
self.setResponseCode(http.BAD_REQUEST)
- self.setHeader('content-type',"text/html")
+ if path in JSON_PATHS: # XXX better json path detection
+ self.setHeader('content-type',"application/json")
+ body = dumps({'reason': 'request max size exceeded'})
+ elif path in FRAME_POST_PATHS: # XXX better frame post path detection
+ self.setHeader('content-type',"text/html")
+ body = ('<script type="text/javascript">'
+ 'window.parent.handleFormValidationResponse(null, null, null, %s, null);'
+ '</script>' % dumps( (False, 'request max size exceeded', None) ))
+ else:
+ self.setHeader('content-type',"text/html")
+ body = ("<html><head><title>Processing Failed</title></head><body>"
+ "<b>request max size exceeded</b></body></html>")
self.setHeader('content-length', str(len(body)))
self.write(body)
# see request.finish(). Done here since we get error due to not full
--- a/web/data/cubicweb.edition.js Tue Apr 20 09:58:28 2010 +0200
+++ b/web/data/cubicweb.edition.js Tue Apr 20 10:00:36 2010 +0200
@@ -321,9 +321,15 @@
}
function _clearPreviousErrors(formid) {
- jQuery('#' + formid + 'ErrorMessage').remove();
- jQuery('#' + formid + ' span.errorMsg').remove();
- jQuery('#' + formid + ' .error').removeClass('error');
+ // on some case (eg max request size exceeded, we don't know the formid
+ if (formid) {
+ jQuery('#' + formid + 'ErrorMessage').remove();
+ jQuery('#' + formid + ' span.errorMsg').remove();
+ jQuery('#' + formid + ' .error').removeClass('error');
+ } else {
+ jQuery('span.errorMsg').remove();
+ jQuery('.error').removeClass('error');
+ }
}
function _displayValidationerrors(formid, eid, errors) {
@@ -405,7 +411,12 @@
/* unfreeze form buttons when the validation process is over*/
function unfreezeFormButtons(formid) {
jQuery('#progress').hide();
- jQuery('#' + formid + ' .validateButton').removeAttr('disabled');
+ // on some case (eg max request size exceeded, we don't know the formid
+ if (formid) {
+ jQuery('#' + formid + ' .validateButton').removeAttr('disabled');
+ } else {
+ jQuery('.validateButton').removeAttr('disabled');
+ }
return true;
}