This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
M2OLA/backend/app/core.py

46 lines
1014 B
Python
Raw Normal View History

2017-01-20 14:07:59 +01:00
import importlib
2017-01-20 17:04:12 +01:00
from datetime import timedelta
2017-03-07 06:03:48 +01:00
from flask_cas import CAS
2017-01-23 12:26:07 +01:00
from app.config import Config
2017-03-07 06:03:48 +01:00
from flask import Flask, session, redirect
2017-01-20 17:04:12 +01:00
from flask_restful import Api
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData
2017-01-20 14:07:59 +01:00
from sqlalchemy import create_engine
from sqlalchemy.ext.automap import automap_base
2017-01-20 17:04:12 +01:00
# initialization Flask
app = Flask(__name__)
app.config.from_object(Config.ACTIVE_CONFIG)
app.permanent_session_lifetime = \
timedelta(
minutes=app.config['SESSION_VALIDITY_DURATION_WITHOUT_ACTIVITY_MIN']
)
@app.before_request
def before_request():
session.modified = True
2017-01-20 17:04:12 +01:00
# SQLAlchemy
db = SQLAlchemy(app)
2017-01-20 14:07:59 +01:00
Base = automap_base()
engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])
Base.prepare(engine, reflect=True)
meta = MetaData(engine, True)
2017-01-20 17:04:12 +01:00
# RestFul Flask
api = Api(app)
2017-03-07 06:03:48 +01:00
# Cas Flask
cas = CAS(app)
@app.route('/redirect')
def after_login():
return redirect("/api/login")
2017-01-20 17:04:12 +01:00
# import api resources
importlib.import_module("app.urls")