SARBase/app.py

69 lines
1.8 KiB
Python
Raw Permalink 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
2023-11-18 19:34:23 +00:00
#from flask_debugtoolbar import DebugToolbarExtension
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', 'ee', 'lv', 'fi','se','lt']))
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'
2023-11-16 14:08:08 +00:00
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', 'mysql+mysqlconnector://sarbaseuser:password@localhost/sarbaseapp')
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
app.config['MAX_CONTENT_LENGTH'] = 128 * 1024 * 1024
if os.environ.get('DOCKER_ENV') == 'true':
app.config['STORAGE_DIR'] = '/storage'
else:
app.config['STORAGE_DIR'] = './storage'
2023-11-18 19:34:23 +00:00
#app.debug = True
#toolbar = DebugToolbarExtension(app)
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 sar_call_details
2023-10-30 14:48:00 +00:00
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-19 21:08:19 +00:00
return redirect(url_for('list_sar'))
2023-10-29 12:55:30 +00:00
@app.route('/set_language/<lang_code>')
def set_language(lang_code):
session['language'] = lang_code
2023-11-23 09:08:14 +00:00
return redirect(request.referrer or url_for('list_sar'))
2023-10-29 12:55:30 +00:00
if __name__ == '__main__':
app.run()