]> git.ipfire.org Git - ipfire.org.git/commitdiff
i-use: Return an empty image if an error was raised.
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 16 Jan 2011 11:53:29 +0000 (12:53 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 16 Jan 2011 11:53:29 +0000 (12:53 +0100)
www/templates/i-use/errors/IPFire-Banner1-Bronze.png [new file with mode: 0644]
www/templates/i-use/errors/IPFire-Banner1-Gold.png [new file with mode: 0644]
www/templates/i-use/errors/IPFire-Banner1-Silver.png [new file with mode: 0644]
www/webapp/handlers_iuse.py

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 (file)
index 0000000..52ee919
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 (file)
index 0000000..9a0c8f8
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 (file)
index 0000000..ebf9a50
Binary files /dev/null and b/www/templates/i-use/errors/IPFire-Banner1-Silver.png differ
index e0b003a69668ffaa523ad9d0804796838fbaf457..5d3c83c0cfbea5f3d913fe5308634ba3af914bc0 100644 (file)
@@ -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