Simple way to display IMAP errors:

* raise a specific exception in the imap connector,
 * Add a simple middleware to catch this exception and return a specific response that will be correctly displayed by the webmail.

see #127
This commit is contained in:
Antoine Nguyen
2011-03-28 17:12:12 +02:00
parent 2535bca0fc
commit 53f1cb5899
7 changed files with 68 additions and 28 deletions
+6 -1
View File
@@ -74,7 +74,9 @@ def getctx(status, level=1, callback=None, **kwargs):
ctx[kw] = v
return ctx
def ajax_response(request, status="ok", url="", ajaxnav=False, template=None, **kwargs):
def ajax_response(request, status="ok", error=None,
url="", ajaxnav=False, norefresh=False,
template=None, **kwargs):
"""Ajax response shortcut
Simple shortcut that sends an JSON response. If a template is
@@ -95,10 +97,13 @@ def ajax_response(request, status="ok", url="", ajaxnav=False, template=None, **
else:
content = ""
jsonctx = {"status" : status, "content" : content}
if error is not None:
jsonctx["error"] = error
if ajaxnav:
jsonctx["ajaxnav"] = True
if url != "":
jsonctx["url"] = url
jsonctx["norefresh"] = norefresh
return HttpResponse(simplejson.dumps(jsonctx), mimetype="application/json")
def decode(s, encodings=('utf8', 'latin1', 'windows-1252', 'ascii'), charset=None):