From: Michael Tremer Date: Tue, 28 Apr 2015 08:57:15 +0000 (+0200) Subject: i-use: Fix error images when the profile is disabled or not found X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d7bebd28bb664196159be5462d74e349d9c4716d;p=ipfire.org.git i-use: Fix error images when the profile is disabled or not found --- diff --git a/webapp/backend/fireinfo.py b/webapp/backend/fireinfo.py index a1942822..b4b74248 100644 --- a/webapp/backend/fireinfo.py +++ b/webapp/backend/fireinfo.py @@ -1504,6 +1504,14 @@ class Fireinfo(Object): if res: return Profile(self.backend, res.id, res) + def get_profile_with_data(self, public_id, when=None): + res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \ + SELECT * FROM profiles JOIN fireinfo_profiles ON profiles.id = fireinfo_profiles.id \ + WHERE public_id = %s ORDER BY time_updated DESC LIMIT 1", when, public_id) + + if res: + return Profile(self.backend, res.id, res) + def get_profiles(self, public_id): res = self.db.query("SELECT * FROM fireinfo_profiles \ WHERE public_id = %s ORDER BY time_created DESC", public_id) diff --git a/webapp/handlers_iuse.py b/webapp/handlers_iuse.py index fe7f26ed..b9355245 100644 --- a/webapp/handlers_iuse.py +++ b/webapp/handlers_iuse.py @@ -50,14 +50,14 @@ class IUseImage(BaseHandler): else: logging.info("Rendering new image for profile: %s" % profile_id) + profile = self.fireinfo.get_profile_with_data(profile_id, when=when) + if not profile: + raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id) + image_cls = self.iuse.get_imagetype(image_id) if not image_cls: raise tornado.web.HTTPError(404, "Image class is unknown: %s" % image_id) - profile = self.fireinfo.get_profile(profile_id, when=when) - if not profile: - raise tornado.web.HTTPError(404, "Profile '%s' was not found." % profile_id) - # Render the image image = image_cls(self.backend, self, profile).to_string() @@ -66,4 +66,3 @@ class IUseImage(BaseHandler): self.set_header("Content-Type", "image/png") self.write(image) -