]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/handlers_iuse.py
Fix typo so images from the "i-use" service get delivered with a correct mime type.
[people/shoehn/ipfire.org.git] / www / webapp / handlers_iuse.py
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):
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)
22
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)
27
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()
34
35 # Save the image to the memcache for 15 minutes
36 self.memcached.set(mem_id, image, 15*60)
37
38 self.set_header("Content-Type", "image/png")
39 self.write(image)
40