]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/handlers_iuse.py
fireinfo: Add new image.
[people/shoehn/ipfire.org.git] / www / webapp / handlers_iuse.py
1 #!/usr/bin/python
2
3 import logging
4 import tornado.web
5
6 from handlers_base import *
7 import backend
8
9 class IUseImage(BaseHandler):
10 @property
11 def iuse(self):
12 return backend.IUse()
13
14 @property
15 def stasy(self):
16 return backend.Stasy()
17
18 def get(self, profile_id, image_id):
19 image = None
20 # Try to get the image from memcache. If we have a cache miss we
21 # build a new one.
22 mem_id = "iuse-%s-%s-%s" % (profile_id, image_id, self.locale.code)
23
24 cache = self.get_argument("cache", "true")
25 if cache == "true":
26 image = self.memcached.get(mem_id)
27
28 if image:
29 logging.debug("Got image from cache for profile: %s" % profile_id)
30 else:
31 logging.info("Rendering new image for profile: %s" % profile_id)
32
33 image_cls = self.iuse.get_imagetype(image_id)
34 if not image_cls:
35 raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id)
36
37 profile = self.stasy.get_profile(profile_id)
38 if not profile:
39 raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id)
40
41 # Render the image
42 image = image_cls(self, profile).to_string()
43
44 # Save the image to the memcache for 15 minutes
45 self.memcached.set(mem_id, image, 15*60)
46
47 self.set_header("Content-Type", "image/png")
48 self.write(image)
49