summaryrefslogtreecommitdiff
path: root/fbin/__init__.py
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2017-04-09 09:02:09 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2017-04-09 09:02:09 +0200
commitb36f9c05071ea549ed59e703270fcf223b60df03 (patch)
tree8992c6bcaa5b0d64cbd589588b2539523125548c /fbin/__init__.py
parentaf750a6598d53b8a5cb58092dd5b523ea7e967ca (diff)
Major rewrite to use jab/oauth.
Highlights: - Uses the oauth branch of jab. - Changed design to use bootstrap. - Some minor changes to functionality in file uploading and listing. - API is currently disabled and incomplete.
Diffstat (limited to 'fbin/__init__.py')
-rw-r--r--fbin/__init__.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/fbin/__init__.py b/fbin/__init__.py
new file mode 100644
index 0000000..bdeaa5d
--- /dev/null
+++ b/fbin/__init__.py
@@ -0,0 +1,39 @@
+from flask import Flask, url_for, Markup, request
+from flask_login import current_user
+from werkzeug.routing import BaseConverter
+
+app = Flask(__name__)
+app.config.from_pyfile('fbin.cfg')
+
+# Set up some custom converters. These are needed for file URLs to be properly parsed.
+
+class HashConverter(BaseConverter):
+ regex = r'\w+'
+
+class ExtensionConverter(BaseConverter):
+ regex = r'\.\w+'
+
+app.url_map.converters['hash'] = HashConverter
+app.url_map.converters['ext'] = ExtensionConverter
+
+@app.context_processor
+def context_processors():
+ def nav_html(view, name=None):
+ url = url_for(view)
+ if not name:
+ name = view.rsplit('.', 1)[-1].replace('_', ' ').capitalize()
+ if view == '.logout':
+ name += ' [{}]'.format(current_user.username)
+ return Markup('<li{}><a href="{}">{}</a></li>'.format(' class="active"' if url == request.path else '', url, name))
+ return {
+ 'nav_html': nav_html,
+ }
+
+with app.app_context():
+ # TODO: Enable API when done
+ from .fbin import app as fbin
+ #from .api import app as api
+ from .login import login_manager
+ app.register_blueprint(fbin)
+ #app.register_blueprint(api, url_prefix = '/api')
+ login_manager.init_app(app)