-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path__init__.py
More file actions
42 lines (31 loc) · 1.16 KB
/
__init__.py
File metadata and controls
42 lines (31 loc) · 1.16 KB
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
import os
from flask_babel import Babel
from flask_flatpages import FlatPages
from flask_wtf.csrf import CSRFProtect
from flask import Flask, g, request
from .apps import flatpages, typus_web
site = Flask(__name__)
site.config.from_object(os.environ['SITE_CONFIG'])
site.register_blueprint(typus_web.bp, url_prefix='/typus')
site.register_blueprint(flatpages.bp)
pages = FlatPages(site)
babel = Babel(site)
csrf = CSRFProtect(site)
# Fucking Jesus fuck! I'm not able to pass a class based view
# since it has an endpoint which is not equal to views's name!
# And I can't use a decorator because of relative fucking imports!
# See the form, it has to exempt csrf too.
# Who the hell had invented this?
csrf.exempt('website.apps.typus_web.views.api_view')
@babel.localeselector
def get_locale():
supported_locals = site.config['BABEL_SUPPORTED_LOCALES']
lang = request.args.get('lang')
if lang and lang in supported_locals:
return lang
fallback = site.config['BABEL_DEFAULT_LOCALE']
return request.accept_languages.best_match(supported_locals) or fallback
@site.before_request
def before_request():
g.pages = pages
g.locale = get_locale()