Add common way to add a subtree to a page
[cascardo/ipsilon.git] / ipsilon / util / page.py
index 56a6463..7727dda 100755 (executable)
@@ -21,6 +21,17 @@ from ipsilon.util.user import UserSession
 import cherrypy
 
 
+def admin_protect(fn):
+
+    def check(*args, **kwargs):
+        if UserSession().get_user().is_admin:
+            return fn(*args, **kwargs)
+
+        raise cherrypy.HTTPError(403)
+
+    return check
+
+
 def protect():
     UserSession().remote_login()
 
@@ -69,4 +80,10 @@ class Page(object):
     def default(self, *args, **kwargs):
         raise cherrypy.HTTPError(404)
 
+    def add_subtree(self, name, page):
+        self.__dict__[name] = page
+
+    def del_subtree(self, name):
+        del self.__dict__[name]
+
     exposed = True