]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/handlers_iuse.py
11 class IUseImage(base
.BaseHandler
):
14 def write_error(self
, status_code
, **kwargs
):
16 Select a random image from the errors directory
17 and return the content.
19 self
.set_expires(3600)
21 self
.set_header("Content-Type", "image/png")
23 template_path
= self
.application
.settings
.get("template_path", "")
24 template_path
= os
.path
.join(template_path
, "i-use", "errors")
26 images
= os
.listdir(template_path
)
28 image
= random
.choice(images
)
29 image
= os
.path
.join(template_path
, image
)
32 with
open(image
, "rb") as f
:
37 def get(self
, profile_id
, image_id
):
40 when
= self
.get_argument_date("when", None)
42 logging
.info("Rendering new image for profile: %s" % profile_id
)
44 profile
= self
.fireinfo
.get_profile_with_data(profile_id
, when
=when
)
46 raise tornado
.web
.HTTPError(404, "Profile '%s' was not found." % profile_id
)
48 image_cls
= self
.iuse
.get_imagetype(image_id
)
50 raise tornado
.web
.HTTPError(404, "Image class is unknown: %s" % image_id
)
53 image
= image_cls(self
.backend
, self
, profile
).to_string()
55 # Cache generate images for 3 hours
56 self
.set_expires(3600 * 3)
58 self
.set_header("Content-Type", "image/png")