X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Futil%2Fpage.py;h=213f945f4394f4ba9cae435620a751c1caa0c07b;hp=aad91fcee2752090b514c9576df1a6b344a11eb8;hb=fe50fd3423969fca640cc35b32678bab5fd491cb;hpb=ae738cc3987a281386ed928f9131cf7a7dbdda64 diff --git a/ipsilon/util/page.py b/ipsilon/util/page.py index aad91fc..213f945 100755 --- a/ipsilon/util/page.py +++ b/ipsilon/util/page.py @@ -17,7 +17,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from ipsilon.util.log import Log from ipsilon.util.user import UserSession +from ipsilon.util.trans import Transaction from urllib import unquote import cherrypy @@ -33,7 +35,7 @@ def admin_protect(fn): return check -class Page(object): +class Page(Log): def __init__(self, site, form=False): if 'template_env' not in site: raise ValueError('Missing template environment') @@ -41,6 +43,8 @@ class Page(object): self.basepath = cherrypy.config.get('base.mount', "") self.user = None self._is_form_page = form + self.default_headers = dict() + self.auth_protect = False def _compare_urls(self, url1, url2): u1 = unquote(url1) @@ -51,11 +55,16 @@ class Page(object): def __call__(self, *args, **kwargs): # pylint: disable=star-args + cherrypy.response.headers.update(self.default_headers) + self.user = UserSession().get_user() + if self.auth_protect and self.user.is_anonymous: + raise cherrypy.HTTPError(401) + if len(args) > 0: op = getattr(self, args[0], None) - if callable(op) and getattr(self, args[0]+'.exposed', None): + if callable(op) and getattr(op, 'public_function', None): return op(*args[1:], **kwargs) else: if self._is_form_page: @@ -96,12 +105,8 @@ class Page(object): m.update(kwargs) return t.render(**m) - def _debug(self, fact): - if cherrypy.config.get('debug', False): - cherrypy.log(fact) - def default(self, *args, **kwargs): - raise cherrypy.HTTPError(404) + raise cherrypy.NotFound() def add_subtree(self, name, page): self.__dict__[name] = page @@ -109,4 +114,11 @@ class Page(object): def del_subtree(self, name): del self.__dict__[name] + def get_valid_transaction(self, provider, **kwargs): + try: + return Transaction(provider, **kwargs) + except ValueError: + msg = 'Transaction expired, or cookies not available' + raise cherrypy.HTTPError(401, msg) + exposed = True