-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (59 loc) · 2.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from flask import Flask, session, g, request, redirect
from flask.ext.babel import Babel
from models.database import db_session
from social_auth import social_auth
from routes.site import site
from routes.articles import articles
from routes.questions import questions
from routes.topics import topics
from routes.api_articles import api_articles
from routes.api_tags import api_tags
from routes.api_users import api_users
from routes.api_questions import api_questions
from routes.api_topics import api_topics
from models import User
from jinja import filters
from werkzeug.contrib.fixers import ProxyFix
import config
app = Flask(__name__)
app.secret_key = config.SECRET
app.wsgi_app = ProxyFix(app.wsgi_app)
app.config.from_object(config)
# Babel Setup
babel = Babel(app)
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(config.LANGUAGES.keys())
app.register_blueprint(social_auth)
app.register_blueprint(site)
app.register_blueprint(articles)
app.register_blueprint(questions)
app.register_blueprint(topics)
app.register_blueprint(api_articles, url_prefix="/api")
app.register_blueprint(api_tags, url_prefix="/api")
app.register_blueprint(api_users, url_prefix="/api")
app.register_blueprint(api_questions, url_prefix="/api")
app.register_blueprint(api_topics, url_prefix="/api")
@app.before_request
def before_request():
if 'user_id' in session:
user = User.find_by_pk(int(session['user_id']))
g.user = user
if user.is_banned:
return user.ban_reason
else:
g.user = None
@app.teardown_appcontext
def shutdown_session(exception=None):
db_session.remove()
# Setup Jinja
app.jinja_env.filters['static'] = filters.static
app.jinja_env.filters['to_json'] = filters.to_json
app.jinja_env.filters['construct_title'] = filters.construct_title
@app.context_processor
def setup_env_detect():
def is_env(env):
return env == config.ENV
return {'is_env': is_env}
if __name__ == '__main__':
app.run(host='127.0.0.1', port=3000, debug=True)