52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import os
|
|
# from celery import Celery
|
|
from flask import Flask, render_template, g, session
|
|
from wotstats.database import db, migrate
|
|
from wotstats.openid import oid
|
|
from wotstats.pending_tasks import celery
|
|
from wotstats.views import *
|
|
|
|
|
|
def init_app():
|
|
app = Flask(__name__)
|
|
app.config.from_pyfile(os.getenv('WOTS_CONFIG', '../config_file.ini'))
|
|
|
|
oid.init_app(app)
|
|
db.init_app(app)
|
|
migrate.init_app(app, db)
|
|
|
|
init_celery(app)
|
|
|
|
# jwt = JWT(app, authenticate, identity)
|
|
|
|
app.register_blueprint(pages_home)
|
|
app.register_blueprint(pages_account)
|
|
app.register_blueprint(pages_technic)
|
|
app.register_blueprint(pages_achievements)
|
|
app.register_blueprint(pages_wallet)
|
|
app.register_blueprint(pages_rush)
|
|
|
|
@app.before_request
|
|
def lookup_current_user():
|
|
from wotstats.models import User
|
|
|
|
g.user = None
|
|
if 'openid' in session:
|
|
openid = session['openid']
|
|
g.user = User.query.filter_by(openid=openid).first()
|
|
|
|
return app, celery, db
|
|
|
|
|
|
def init_celery(app):
|
|
celery.conf.update(app.config.get_namespace('CELERY_'))
|
|
|
|
TaskBase = celery.Task
|
|
|
|
class ContextTask(TaskBase):
|
|
abstract = True
|
|
def __call__(self, *args, **kwargs):
|
|
with app.app_context():
|
|
return TaskBase.__call__(self, *args, **kwargs)
|
|
celery.Task = ContextTask
|
|
from wotstats import tasks
|