]>
Commit | Line | Data |
---|---|---|
c37ec602 MT |
1 | #!/usr/bin/python |
2 | ||
abc3bb31 | 3 | import logging |
c37ec602 MT |
4 | import tornado.web |
5 | ||
124a8404 | 6 | from . import base |
c37ec602 | 7 | |
395c1ac0 | 8 | class ImageHandler(base.BaseHandler): |
30bb04e2 | 9 | def write_error(self, status_code, **kwargs): |
e8478c5e MT |
10 | """ |
11 | Select a random image from the errors directory | |
12 | and return the content. | |
13 | """ | |
5eac92f1 MT |
14 | self.set_expires(3600) |
15 | ||
395c1ac0 MT |
16 | # Redirect to static image |
17 | self.redirect(self.static_url("img/iuse-not-found.png")) | |
e8478c5e | 18 | |
c37ec602 | 19 | def get(self, profile_id, image_id): |
6ec867f2 MT |
20 | when = self.get_argument_date("when", None) |
21 | ||
5eac92f1 MT |
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) | |
d7bebd28 | 25 | |
395c1ac0 MT |
26 | logging.info("Rendering new image for profile: %s" % profile_id) |
27 | ||
5eac92f1 MT |
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) | |
c37ec602 | 31 | |
5eac92f1 MT |
32 | # Render the image |
33 | image = image_cls(self.backend, self, profile).to_string() | |
c37ec602 | 34 | |
5eac92f1 MT |
35 | # Cache generate images for 3 hours |
36 | self.set_expires(3600 * 3) | |
c37ec602 | 37 | |
192f0bdf | 38 | self.set_header("Content-Type", "image/png") |
b3250465 | 39 | self.write(image) |