From bb30f0a6e8e954b2f14f89acffa50236ee5958ea Mon Sep 17 00:00:00 2001 From: shlurbee Date: Fri, 27 Apr 2012 15:29:04 -0700 Subject: [PATCH] Show error message on large image upload Previously if you attempted to upload a header with file size > 500kB, the operation failed silently and the "uploading" message never went away. Now an error message is displayed saying the image was too large. --- r2/r2/config/middleware.py | 12 +++++++++++- r2/r2/lib/strings.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/r2/r2/config/middleware.py b/r2/r2/config/middleware.py index 34270d1a0..f026c91b0 100644 --- a/r2/r2/config/middleware.py +++ b/r2/r2/config/middleware.py @@ -462,9 +462,19 @@ class LimitUploadSize(object): return r(environ, start_response) if cl_int > self.max_size: + from r2.lib.strings import string_dict + error_msg = string_dict['css_validator_messages']['max_size'] % dict(max_size = self.max_size/1024) r = Response() r.status_code = 413 - r.content = 'request entity too large' + r.content = ("" + "" + "you shouldn\'t be here") return r(environ, start_response) return self.app(environ, start_response) diff --git a/r2/r2/lib/strings.py b/r2/r2/lib/strings.py index 9dca10223..463fc5a89 100644 --- a/r2/r2/lib/strings.py +++ b/r2/r2/lib/strings.py @@ -118,6 +118,7 @@ string_dict = dict( invalid_property = _('"%(cssprop)s" is not a valid CSS property'), invalid_val_for_prop = _('"%(cssvalue)s" is not a valid value for CSS property "%(cssprop)s"'), too_big = _('too big. keep it under %(max_size)dkb'), + max_size = _('max size: %(max_size)dkB'), syntax_error = _('syntax error: "%(syntaxerror)s"'), no_imports = _('@imports are not allowed'), invalid_property_list = _('invalid CSS property list "%(proplist)s"'),