Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcfr/flask/_app.py
diff options
context:
space:
mode:
authorflorent <florent@toopy.org>2012-02-06 21:51:28 (GMT)
committer florent <florent@toopy.org>2012-02-06 21:51:28 (GMT)
commitb7d174099e53522ccdf20d0c6cd33e96784b099e (patch)
tree650860b2dbe7a171ceac41fdbe89ce38fb246875 /olpcfr/flask/_app.py
initial commitHEADmaster
Diffstat (limited to 'olpcfr/flask/_app.py')
-rw-r--r--olpcfr/flask/_app.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/olpcfr/flask/_app.py b/olpcfr/flask/_app.py
new file mode 100644
index 0000000..371fe59
--- /dev/null
+++ b/olpcfr/flask/_app.py
@@ -0,0 +1,60 @@
+# python import
+import os
+
+# common gettext import
+from gettext import gettext
+
+# olpcfr import
+from olpcfr import config
+
+# get APP_NAME or default name
+APP_NAME = config.Config().get('activity>name')
+APP_NAME = 'my_activity' if APP_NAME is None else APP_NAME
+
+# get app config values
+_debug = config.Config().get('server>debug')
+_key = config.Config().get('server>secret_key')
+_port = config.Config().get('server>port', type_=int)
+
+# sugar or debug root path factory
+try:
+ from sugar.activity import activity
+ BUNDLE = activity.get_bundle_path()
+ ROOT = activity.get_activity_root()
+except Exception, e:
+ BUNDLE = os.path.abspath(os.path.join(
+ os.path.dirname(__file__), '..', '..', '..'))
+ ROOT = BUNDLE
+
+
+try:
+ # flask import
+ import flask
+ # init app
+ app = flask.Flask(__name__)
+ app.debug = True if _debug is None else _debug
+ app.secret_key = 'NO_KEY_OOPS' if _key is None else _key
+ # override jinja template path
+ app.jinja_loader.searchpath = [os.path.join(BUNDLE, 'templates')]
+ # init static folder path
+ from werkzeug import SharedDataMiddleware
+ app.wsgi_app = SharedDataMiddleware(app.wsgi_app,
+ {'/static': os.path.join(BUNDLE, 'static')})
+except Exception, e:
+ app = None
+
+
+def run_app():
+ """run method to trigger at from python class.
+ """
+ if app:
+ app.run(port=_port)
+ else:
+ pass
+
+
+def render(template, **context):
+ """Crappy hack for gettext issue in templates!
+ """
+ context['_'] = gettext
+ return flask.render_template(template, **context)