Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bewype/flask/controllers/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bewype/flask/controllers/__init__.py')
-rw-r--r--bewype/flask/controllers/__init__.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/bewype/flask/controllers/__init__.py b/bewype/flask/controllers/__init__.py
new file mode 100644
index 0000000..067687f
--- /dev/null
+++ b/bewype/flask/controllers/__init__.py
@@ -0,0 +1,46 @@
+# (C) Copyright 2010 Bewype <http://www.bewype.org>
+
+# python import
+import logging, os
+
+# peak import
+from peak.util.imports import importString
+
+# bewype-flask import
+from bewype.flask import app
+
+# get application logger
+logger = logging.getLogger('NutriWeb')
+
+
+def init_controllers(namespace="bewype.flask.controllers"):
+ """Here we init all the controllers of the bewype namespace before running
+ the app.
+ """
+ # controllers name space
+ _controllers_package = importString(namespace)
+ # controllers all paths
+ _controllers_paths = _controllers_package.__path__
+ # ...
+ for _p in _controllers_paths:
+ for _f in os.listdir(_p):
+ # simple check
+ if '__init__.' in _f\
+ or os.path.splitext(_f)[-1] != '.py':
+ continue
+ # do init
+ else:
+ _controller_name = os.path.splitext(_f)[0]
+ _c = importString("%s.%s" % (namespace, _controller_name))
+ # prepare module name - custom bewype
+ _m_name = 'module_%s' % _controller_name
+ # module check
+ if hasattr(_c, _m_name):
+ # get module
+ _m = getattr(_c, _m_name)
+ _controller_name
+ # get templates search path
+ _search_path = _m.jinja_loader.searchpath
+ # update jinja loader templates search path
+ app.jinja_loader.searchpath.extend(_search_path)
+