This commit is contained in:
Yûki VACHOT 2021-12-01 15:48:25 +01:00
parent 2e9fbf14e9
commit 42a80609ab
4 changed files with 64 additions and 16 deletions

26
app.py
View file

@ -1,15 +1,29 @@
import os import os
import sys
from flask import Flask from flask import Flask
from config import Config, DevelopmentConfig, TestingConfig, ProductionConfig from config import Config, DevelopmentConfig, StagingConfig, ProductionConfig
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
if __name__ == '__main__': if __name__ == '__main__':
app = Flask(__name__) app = Flask(__name__)
PORT = int(os.environ.get('PORT', 33507)) PORT = int(os.environ.get('PORT', 33507))
db = SQLAlchemy(app) db1 = SQLAlchemy(app)
db2 = SQLAlchemy(app)
app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY', 'secret_key') FLASK_ENV = os.environ.get('FLASK_ENV', None)
app.config.from_object(os.environ['APP_SETTINGS']) if FLASK_ENV == 'production':
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False DEBUG = ProductionConfig.DEBUG
app.run(host='0.0.0.0', port=PORT, debug=False) elif FLASK_ENV == 'stage':
DEBUG = StagingConfig.DEBUG
elif FLASK_ENV == 'development':
DEBUG = DevelopmentConfig.DEBUG
else:
sys.exit("Error FLASK_ENV")
if Config.SQLALCHEMY_DATABASE_URI_1 is None or Config.SQLALCHEMY_DATABASE_URI_2 is None:
sys.exit("Error SQLALCHEMY_DATABASE_URI_1 or/and SQLALCHEMY_DATABASE_URI_2")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = Config.SQLALCHEMY_TRACK_MODIFICATIONS
app.config['SECRET_KEY'] = Config.SECRET_KEY
app.run(host='0.0.0.0', port=PORT, debug=DEBUG)

View file

@ -6,15 +6,17 @@ class Config(object):
TESTING = False TESTING = False
CSRF_ENABLED = True CSRF_ENABLED = True
SECRET_KEY = os.environ.get('SECRET_KEY', None) SECRET_KEY = os.environ.get('SECRET_KEY', None)
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL', None) SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_DATABASE_URI_1 = os.environ.get('DATABASE_URL_1', None)
SQLALCHEMY_DATABASE_URI_2 = os.environ.get('DATABASE_URL_2', None)
class ProductionConfig(Config): class ProductionConfig(Config):
DEBUG = False DEBUG = False
class TestingConfig(Config): class StagingConfig(Config):
TESTING = True STAGING = True
class DevelopmentConfig(Config): class DevelopmentConfig(Config):

32
models/logs.model.py Normal file
View file

@ -0,0 +1,32 @@
from app import db2
class Logs(db2.Model):
__tablename__ = 'logs'
id = db2.Column(db2.Integer, primary_key=True)
date = db2.Column(db2.Date())
user = db2.Column(db2.String())
ip = db2.Column(db2.String())
table = db2.Column(db2.String())
action = db2.Column(db2.String())
status = db2.Column(db2.String())
def __init__(self, date, user, ip, table, action, status):
self.date = date
self.user = user
self.ip = ip
self.table = table
self.action = action
self.status = status
def __repr__(self):
return {
'id': self.id,
'date': self.date,
'user': self.user,
'ip': self.ip,
'table': self.table,
'action': self.action,
'status': self.status
}

View file

@ -1,14 +1,14 @@
from app import db from app import db1
class Users(db.Model): class Users(db1.Model):
__tablename__ = 'users' __tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True) id = db1.Column(db1.Integer, primary_key=True)
email = db.Column(db.String()) email = db1.Column(db1.String())
login = db.Column(db.String()) login = db1.Column(db1.String())
hashPass = db.Column(db.String()) hashPass = db1.Column(db1.String())
role = db.Column(db.String()) role = db1.Column(db1.String())
def __init__(self, email, login, hash_pass, role): def __init__(self, email, login, hash_pass, role):
self.email = email self.email = email