From ee0d1ce71d1f4883aecc426595ac86322a91260e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 18 Dec 2013 22:44:25 -0500 Subject: Move template and user retrieval to page class Signed-off-by: Simo Sorce --- src/util/page.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/util/page.py') diff --git a/src/util/page.py b/src/util/page.py index 4236e9f..15cbed0 100755 --- a/src/util/page.py +++ b/src/util/page.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from util import user import cherrypy def protect(): @@ -31,10 +32,12 @@ def protect(): class Page(object): def __init__(self, template_env): self._env = template_env + self.basepath = cherrypy.config.get('base.mount', "") self.username = None def __call__(self, *args, **kwargs): self.username = cherrypy.session.get('user', None) + self.user = user.User(self.username) if len(args) > 0: op = getattr(self, args[0], None) @@ -47,6 +50,10 @@ class Page(object): return self.default(*args, **kwargs) + def _template(self, *args, **kwargs): + t = self._env.get_template(args[0]) + return t.render(basepath=self.basepath, user=self.user, **kwargs) + def default(self, *args, **kwargs): raise cherrypy.HTTPError(404) -- cgit