3 # Copyright (C) 2013 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from ipsilon.util.user import UserSession
25 UserSession().remote_login()
29 def __init__(self, site):
30 if not 'template_env' in site:
31 raise ValueError('Missing template environment')
33 self.basepath = cherrypy.config.get('base.mount', "")
36 def __call__(self, *args, **kwargs):
37 # pylint: disable=star-args
38 self.user = UserSession().get_user()
41 op = getattr(self, args[0], None)
42 if callable(op) and getattr(self, args[0]+'.exposed', None):
43 return op(*args[1:], **kwargs)
45 op = getattr(self, 'root', None)
47 return op(*args, **kwargs)
49 return self.default(*args, **kwargs)
51 def _template(self, *args, **kwargs):
52 t = self._site['template_env'].get_template(args[0])
53 return t.render(basepath=self.basepath, user=self.user, **kwargs)
55 def default(self, *args, **kwargs):
56 raise cherrypy.HTTPError(404)