SARBase/app.py

62 lines
1.6 KiB
Python
Raw Normal View History

2023-11-16 14:08:08 +00:00
import os
from flask import Flask, redirect, url_for, request, session
2023-10-30 14:48:00 +00:00
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from flask_babel import Babel
from sqlalchemy import MetaData
convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}
metadata = MetaData(naming_convention=convention)
2023-10-30 14:48:00 +00:00
def get_locale():
return session.get('language', request.accept_languages.best_match(['en', 'ru', 'et', 'lv', 'fi']))
2023-10-29 12:55:30 +00:00
app = Flask(__name__)
2023-10-30 14:48:00 +00:00
app.config['SECRET_KEY'] = 'secret_key'
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite3'
2023-11-16 14:08:08 +00:00
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp'
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp')
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
babel= Babel(app)
babel.init_app(app, locale_selector=get_locale)
db = SQLAlchemy(app, metadata=metadata)
2023-11-01 18:46:27 +00:00
migrate = Migrate(app, db)
2023-10-30 14:48:00 +00:00
login_manager = LoginManager(app)
2023-10-29 12:55:30 +00:00
2023-10-30 14:48:00 +00:00
import models
import admin
import login
import sar_calls
import dashboard
2023-10-29 12:55:30 +00:00
2023-11-01 18:46:27 +00:00
2023-10-29 12:55:30 +00:00
@app.route('/')
def hello_world(): # put application's code here
2023-11-01 18:46:27 +00:00
return redirect(url_for('dashboard'))
2023-10-29 12:55:30 +00:00
@app.route('/set_language/<lang_code>')
def set_language(lang_code):
session['language'] = lang_code
return redirect(request.referrer or url_for('dashboard'))
2023-10-29 12:55:30 +00:00
if __name__ == '__main__':
app.run()