__init__.py 2.06 KB
Newer Older
1
2
3
4
5

import pymysql

from flask import Flask, request, session, flash

Timo Heikkilä's avatar
Timo Heikkilä committed
6
7
8
9
10
from flask_bootstrap import Bootstrap
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_babel import Babel
11
from flask_socketio import SocketIO
12
from config import Config
Timo Heikkilä's avatar
Timo Heikkilä committed
13
14

app = Flask(__name__)
15

Timo Heikkilä's avatar
Timo Heikkilä committed
16
17
#app.config['BABEL_DEFAULT_LOCALE'] = 'fin'
#app.config['BABEL_TRANSLATION_DIRECTORIES'] ='C:/Users/Timo/git/pet-rating/app/translations'
Timo Heikkilä's avatar
Timo Heikkilä committed
18
19
babel = Babel(app)

Timo Heikkilä's avatar
Timo Heikkilä committed
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
@babel.localeselector
def get_locale():
    if request.args.get('lang'):

        session['lang'] = request.args.get('lang')
        
        if session['lang'] == 'en':
            session['language'] = 'English'

        if session['lang'] == 'fi':
            session['language'] = 'Finnish'

        if session['lang'] == 'fa':
            session['language'] = 'Persian'

        if session['lang'] == 'el':
            session['language'] = 'Greek'
            
        if session['lang'] == 'it':
            session['language'] = 'Italian'
    
        if session['lang'] == 'zh':
            session['language'] = 'Chinese'
    
    return session.get('lang', 'en')


"""
@babel.localeselector
def get_locale():
Timo Heikkilä's avatar
Timo Heikkilä committed
50

Timo Heikkilä's avatar
Timo Heikkilä committed
51
52
53
54
55
56
57
58
59
    if session:
        
        return 'fi'
        
    else:
        
        return 'en'
"""
"""
Timo Heikkilä's avatar
Timo Heikkilä committed
60
61
@babel.localeselector
def get_locale():
Timo Heikkilä's avatar
Timo Heikkilä committed
62
63
    return request.accept_languages.best_match(app.config['LANGUAGES'])
"""
Timo Heikkilä's avatar
Timo Heikkilä committed
64
65


66
67
68
69
# Run flask app with socketIO
socketio = SocketIO()
socketio.init_app(app)

Timo Heikkilä's avatar
Timo Heikkilä committed
70
71
72
73
74
75
76
77
78
#mariabd mysql portti 3306 tarkista?

Bootstrap(app)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'

79
80
81
82
83
84
85
86
# Register blueprints
from .task.views import task_blueprint
from .experiment.views import experiment_blueprint
from .create.views import create_blueprint

app.register_blueprint(task_blueprint)
app.register_blueprint(experiment_blueprint)
app.register_blueprint(create_blueprint)
Timo Heikkilä's avatar
Timo Heikkilä committed
87
88
89
90

app.secret_key = 'random string'
"""app.secret_key = os.urandom(24)"""

91
app.jinja_env.auto_reload = True
Timo Heikkilä's avatar
Timo Heikkilä committed
92
93

from app import routes, models