]>
Commit | Line | Data |
---|---|---|
c37ec602 MT |
1 | #!/usr/bin/python |
2 | ||
3 | import tornado.web | |
4 | ||
5 | from handlers_base import * | |
6 | import backend | |
7 | ||
8 | class IUseImage(BaseHandler): | |
9 | @property | |
10 | def iuse(self): | |
11 | return backend.IUse() | |
12 | ||
13 | @property | |
14 | def stasy(self): | |
15 | return backend.Stasy() | |
16 | ||
17 | def get(self, profile_id, image_id): | |
b3250465 MT |
18 | # Try to get the image from memcache. If we have a cache miss we |
19 | # build a new one. | |
20 | mem_id = "iuse-%s-%s" % (profile_id, image_id) | |
21 | image = self.memcached.get(mem_id) | |
c37ec602 | 22 | |
b3250465 MT |
23 | if not image: |
24 | image_cls = self.iuse.get_imagetype(image_id) | |
25 | if not image_cls: | |
26 | raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id) | |
c37ec602 | 27 | |
b3250465 MT |
28 | profile = self.stasy.get_profile(profile_id) |
29 | if not profile: | |
30 | raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id) | |
31 | ||
32 | # Render the image | |
33 | image = image_cls(profile).to_string() | |
c37ec602 | 34 | |
b3250465 MT |
35 | # Save the image to the memcache for 15 minutes |
36 | self.memcached.set(mem_id, image, 15*60) | |
c37ec602 | 37 | |
192f0bdf | 38 | self.set_header("Content-Type", "image/png") |
b3250465 | 39 | self.write(image) |
c37ec602 | 40 |