Use transactions throughout the code
[cascardo/ipsilon.git] / ipsilon / providers / common.py
index 865cb77..b1968f4 100755 (executable)
@@ -42,6 +42,11 @@ class ProviderBase(PluginObject):
         self.path = path
         self.tree = None
 
+    def on_enable(self):
+        # this one does nothing
+        # derived classes can override with custom behavior
+        return
+
     def get_tree(self, site):
         raise NotImplementedError
 
@@ -82,6 +87,8 @@ class ProviderBase(PluginObject):
 
         self.set_config_value('enabled', '1')
         self.save_plugin_config(FACILITY)
+
+        self.on_enable()
         self._debug('IdP Provider enabled: %s' % self.name)
 
     def disable(self, site):
@@ -111,7 +118,13 @@ class ProviderPageBase(Page):
         raise cherrypy.HTTPError(501)
 
     def root(self, *args, **kwargs):
-        op = getattr(self, cherrypy.request.method, self.GET)
+        method = cherrypy.request.method
+
+        preop = getattr(self, 'pre_%s' % method, None)
+        if preop and callable(preop):
+            preop(*args, **kwargs)
+
+        op = getattr(self, method, self.GET)
         if callable(op):
             return op(*args, **kwargs)
         else: