__init__.py 2.23 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
Ossi Laine's avatar
Ossi Laine committed
13
from flask_cors import CORS, cross_origin
Timo Heikkilä's avatar
Timo Heikkilä committed
14
15

app = Flask(__name__)
root's avatar
root committed
16

Ossi Laine's avatar
Ossi Laine committed
17
CORS(app)
18
# CORS(app, resources={r"/*": {"cors_allowed_origins":"*"} } )
19

Timo Heikkilä's avatar
Timo Heikkilä committed
20
21
#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
22
23
babel = Babel(app)

Timo Heikkilä's avatar
Timo Heikkilä committed
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
@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
54

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

Timo Heikkilä's avatar
Timo Heikkilä committed
68
"""
Timo Heikkilä's avatar
Timo Heikkilä committed
69
70


71

Timo Heikkilä's avatar
Timo Heikkilä committed
72
73
74
75
76
77
78
79
80
#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'

81
82
83
84
85
# Run flask app with socketIO
socketio = SocketIO(app, cors_allowed_origins="*")
# socketio = SocketIO()
socketio.init_app(app)

86
87
88
89
90
91
92
93
# 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
94
95
96
97

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

98
app.jinja_env.auto_reload = True
Timo Heikkilä's avatar
Timo Heikkilä committed
99
100

from app import routes, models