]> git.ipfire.org Git - ipfire.org.git/blob - src/web/iuse.py
Update Christman campaign copy
[ipfire.org.git] / src / web / iuse.py
1 #!/usr/bin/python
2
3 import logging
4 import tornado.web
5
6 from . import base
7
8 class ImageHandler(base.BaseHandler):
9 def write_error(self, status_code, **kwargs):
10 """
11 Select a random image from the errors directory
12 and return the content.
13 """
14 self.set_expires(3600)
15
16 # Redirect to static image
17 self.redirect(self.static_url("img/iuse-not-found.png"))
18
19 def get(self, profile_id, image_id):
20 when = self.get_argument_date("when", None)
21
22 profile = self.fireinfo.get_profile_with_data(profile_id, when=when)
23 if not profile:
24 raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id)
25
26 logging.info("Rendering new image for profile: %s" % profile_id)
27
28 image_cls = self.iuse.get_imagetype(image_id)
29 if not image_cls:
30 raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id)
31
32 # Render the image
33 image = image_cls(self.backend, self, profile).to_string()
34
35 # Cache generate images for 3 hours
36 self.set_expires(3600 * 3)
37
38 self.set_header("Content-Type", "image/png")
39 self.write(image)