75 lines
1.8 KiB
Python
75 lines
1.8 KiB
Python
|
from flask import Flask, render_template, request, g, Response, redirect, url_for
|
||
|
from flask.ext.login import LoginManager, current_user
|
||
|
from jinja2 import FileSystemLoader, ChoiceLoader
|
||
|
|
||
|
import sys
|
||
|
import os
|
||
|
import locale
|
||
|
|
||
|
from fosspay.config import _cfg, _cfgi
|
||
|
from fosspay.database import db, init_db
|
||
|
from fosspay.objects import User
|
||
|
from fosspay.common import *
|
||
|
from fosspay.network import *
|
||
|
|
||
|
from fosspay.blueprints.html import html
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
app.secret_key = _cfg("secret-key")
|
||
|
app.jinja_env.cache = None
|
||
|
init_db()
|
||
|
login_manager = LoginManager()
|
||
|
login_manager.init_app(app)
|
||
|
|
||
|
app.jinja_loader = ChoiceLoader([
|
||
|
FileSystemLoader("overrides"),
|
||
|
FileSystemLoader("templates"),
|
||
|
])
|
||
|
|
||
|
@login_manager.user_loader
|
||
|
def load_user(email):
|
||
|
return User.query.filter(User.email == email).first()
|
||
|
|
||
|
login_manager.anonymous_user = lambda: None
|
||
|
|
||
|
app.register_blueprint(html)
|
||
|
|
||
|
try:
|
||
|
locale.setlocale(locale.LC_ALL, 'en_US')
|
||
|
except:
|
||
|
pass
|
||
|
|
||
|
if not app.debug:
|
||
|
@app.errorhandler(500)
|
||
|
def handle_500(e):
|
||
|
# shit
|
||
|
try:
|
||
|
db.rollback()
|
||
|
db.close()
|
||
|
except:
|
||
|
# shit shit
|
||
|
print("We're very borked, letting init system kick us back up")
|
||
|
sys.exit(1)
|
||
|
return render_template("internal_error.html"), 500
|
||
|
|
||
|
@app.errorhandler(404)
|
||
|
def handle_404(e):
|
||
|
return render_template("not_found.html"), 404
|
||
|
|
||
|
@app.context_processor
|
||
|
def inject():
|
||
|
return {
|
||
|
'root': _cfg("protocol") + "://" + _cfg("domain"),
|
||
|
'domain': _cfg("domain"),
|
||
|
'protocol': _cfg("protocol"),
|
||
|
'len': len,
|
||
|
'any': any,
|
||
|
'request': request,
|
||
|
'locale': locale,
|
||
|
'url_for': url_for,
|
||
|
'file_link': file_link,
|
||
|
'user': current_user,
|
||
|
'_cfg': _cfg,
|
||
|
'debug': app.debug
|
||
|
}
|