From: Michael Tremer Date: Sun, 16 Jan 2011 11:53:29 +0000 (+0100) Subject: i-use: Return an empty image if an error was raised. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8478c5e46d019ab6c923f22076249080f7d25b3;p=ipfire.org.git i-use: Return an empty image if an error was raised. --- diff --git a/www/templates/i-use/errors/IPFire-Banner1-Bronze.png b/www/templates/i-use/errors/IPFire-Banner1-Bronze.png new file mode 100644 index 00000000..52ee9198 Binary files /dev/null and b/www/templates/i-use/errors/IPFire-Banner1-Bronze.png differ diff --git a/www/templates/i-use/errors/IPFire-Banner1-Gold.png b/www/templates/i-use/errors/IPFire-Banner1-Gold.png new file mode 100644 index 00000000..9a0c8f8d Binary files /dev/null and b/www/templates/i-use/errors/IPFire-Banner1-Gold.png differ diff --git a/www/templates/i-use/errors/IPFire-Banner1-Silver.png b/www/templates/i-use/errors/IPFire-Banner1-Silver.png new file mode 100644 index 00000000..ebf9a502 Binary files /dev/null and b/www/templates/i-use/errors/IPFire-Banner1-Silver.png differ diff --git a/www/webapp/handlers_iuse.py b/www/webapp/handlers_iuse.py index e0b003a6..5d3c83c0 100644 --- a/www/webapp/handlers_iuse.py +++ b/www/webapp/handlers_iuse.py @@ -1,6 +1,8 @@ #!/usr/bin/python import logging +import os +import random import tornado.web from handlers_base import * @@ -15,6 +17,24 @@ class IUseImage(BaseHandler): def stasy(self): return backend.Stasy() + def get_error_html(self, status_code, **kwargs): + """ + Select a random image from the errors directory + and return the content. + """ + self.set_header("Content-Type", "image/png") + + template_path = self.application.settings.get("template_path", "") + template_path = os.path.join(template_path, "i-use", "errors") + + images = os.listdir(template_path) + if images: + image = random.choice(images) + image = os.path.join(template_path, image) + + with open(image, "rb") as f: + return f.read() + def get(self, profile_id, image_id): image = None # Try to get the image from memcache. If we have a cache miss we