TG-103 Amélioration structure du projet
This commit is contained in:
parent
c62f0766f5
commit
3ac6092187
3
.gitignore
vendored
3
.gitignore
vendored
@ -29,3 +29,6 @@ pip-selfcheck.json
|
|||||||
htmlcov/
|
htmlcov/
|
||||||
.coverage
|
.coverage
|
||||||
coverage.xml
|
coverage.xml
|
||||||
|
|
||||||
|
#Config files
|
||||||
|
config.py
|
||||||
|
@ -35,22 +35,15 @@ Installer les dépendances via pip pour les tests :
|
|||||||
|
|
||||||
### Fichier Configuration
|
### Fichier Configuration
|
||||||
|
|
||||||
Dans app/config.py:
|
Copier le fichier app/config.py.example en app/config.py et configurer avec vos parametres
|
||||||
* Configuration les paramètres de la base de données
|
|
||||||
* Changer la SECRET_KEY en production
|
|
||||||
|
|
||||||
### Init App
|
Principalement:
|
||||||
|
* Configuration des paramètres de la base de données
|
||||||
|
* Changement de la SECRET_KEY en production
|
||||||
|
|
||||||
First you need to create the db and seed it with an admin user (admin@admin.com/admin).
|
|
||||||
|
|
||||||
Migration database is handle via flask-migrate using alembic.
|
### Init db
|
||||||
See command available :
|
Installez la dernière version de MariaDB.
|
||||||
```
|
|
||||||
python manage.py db
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Init db
|
|
||||||
Installez la dernière version de MariaDB:
|
|
||||||
|
|
||||||
Lancer le script :
|
Lancer le script :
|
||||||
```
|
```
|
||||||
|
@ -15,4 +15,4 @@ class SomeApi(Resource):
|
|||||||
return {'somedelete': 'somedeletedata'}, 204
|
return {'somedelete': 'somedeletedata'}, 204
|
||||||
|
|
||||||
def put(self, id=None):
|
def put(self, id=None):
|
||||||
return {'someput': 'someputdata'}, 204
|
return {'someput': 'someputdata'}, 201
|
||||||
|
@ -2,6 +2,19 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
ACTIVE_CONFIG = "app.config.Prod"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def configure_app(config="prod"):
|
||||||
|
if config.lower() == "prod":
|
||||||
|
Config.ACTIVE_CONFIG = 'app.config.Prod'
|
||||||
|
elif config.lower() == "debug":
|
||||||
|
Config.ACTIVE_CONFIG = 'app.config.Debug'
|
||||||
|
elif config.lower() == "test":
|
||||||
|
Config.ACTIVE_CONFIG = 'app.config.Test'
|
||||||
|
else:
|
||||||
|
raise Exception('{} n\'est pas configuration une configuration valide'.format(config))
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
TESTING = False
|
TESTING = False
|
||||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
@ -6,30 +6,21 @@ from flask_restful import Api
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
from app.config import Config
|
||||||
|
|
||||||
def configure_app(config="prod"):
|
|
||||||
if config.lower() == "debug":
|
|
||||||
app.config.from_object('app.config.Debug')
|
|
||||||
elif config.lower() == "test":
|
|
||||||
app.config.from_object('app.config.Test')
|
|
||||||
else:
|
|
||||||
app.config.from_object('app.config.Prod')
|
|
||||||
|
|
||||||
app.permanent_session_lifetime = \
|
|
||||||
timedelta(
|
|
||||||
minutes=app.config
|
|
||||||
['SESSION_VALIDITY_DURATION_WITHOUT_ACTIVITY_MIN']
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.before_request
|
|
||||||
def before_request():
|
|
||||||
session.modified = True
|
|
||||||
|
|
||||||
|
|
||||||
# initialization Flask
|
# initialization Flask
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
configure_app()
|
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
|
||||||
|
|
||||||
# SQLAlchemy
|
# SQLAlchemy
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from backend.app.core import Base
|
from app.core import Base
|
||||||
|
|
||||||
USER = Base.classes.user
|
USER = Base.classes.user
|
||||||
SETTINGS = Base.classes.settings
|
SETTINGS = Base.classes.settings
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from app.core import api
|
from app.core import api
|
||||||
|
from app.api.exampleapi import SomeApi
|
||||||
|
|
||||||
# Some Api resource
|
# Some Api resource
|
||||||
api.add_resource(api, '/api/someapi', '/api/someapi/<int:id>')
|
api.add_resource(SomeApi, '/api/someapi', '/api/someapi/<int:id>')
|
||||||
|
@ -7,7 +7,7 @@ import warnings
|
|||||||
from flask_script import Manager, Command
|
from flask_script import Manager, Command
|
||||||
from flask_script import prompt_bool
|
from flask_script import prompt_bool
|
||||||
|
|
||||||
from backend.app.core import configure_app
|
from app.config import Config
|
||||||
|
|
||||||
warnings.simplefilter('ignore')
|
warnings.simplefilter('ignore')
|
||||||
|
|
||||||
@ -18,14 +18,15 @@ group.add_argument("-t", "--test", action="store_true")
|
|||||||
args, _ = parser.parse_known_args()
|
args, _ = parser.parse_known_args()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
configure_app(config="debug")
|
Config.configure_app(config="debug")
|
||||||
if args.test:
|
elif args.test:
|
||||||
configure_app(config="test")
|
Config.configure_app(config="test")
|
||||||
|
else:
|
||||||
|
Config.configure_app(config="prod")
|
||||||
|
|
||||||
db = importlib.import_module("db", "backend.app.core")
|
core = importlib.import_module("app.core")
|
||||||
app = importlib.import_module("app", "backend.app.core")
|
|
||||||
|
|
||||||
manager = Manager(app)
|
manager = Manager(core.app)
|
||||||
manager.add_option("-d", "--debug",
|
manager.add_option("-d", "--debug",
|
||||||
action="store_true", dest="debug", required=False)
|
action="store_true", dest="debug", required=False)
|
||||||
manager.add_option("-t", "--test",
|
manager.add_option("-t", "--test",
|
||||||
@ -58,7 +59,7 @@ class CheckDB(Command):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print("List of parsed tables:")
|
print("List of parsed tables:")
|
||||||
print(db.metadata.tables.keys())
|
print(core.db.metadata.tables.keys())
|
||||||
|
|
||||||
|
|
||||||
manager.add_command('checkdb', CheckDB())
|
manager.add_command('checkdb', CheckDB())
|
||||||
@ -67,7 +68,7 @@ manager.add_command('checkdb', CheckDB())
|
|||||||
class RunTests(Command):
|
class RunTests(Command):
|
||||||
"""Seed the db """
|
"""Seed the db """
|
||||||
def run(self):
|
def run(self):
|
||||||
configure_app(config="test")
|
Config.configure_app(config="test")
|
||||||
os.system("python manage.py -t db downgrade base")
|
os.system("python manage.py -t db downgrade base")
|
||||||
os.system("python manage.py -t db upgrade")
|
os.system("python manage.py -t db upgrade")
|
||||||
test_loader = unittest.defaultTestLoader
|
test_loader = unittest.defaultTestLoader
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
flask < 0.13
|
flask < 0.13
|
||||||
flask-script < 2.1
|
flask-script < 2.1
|
||||||
flask-sqlalchemy < 2.2
|
flask-sqlalchemy < 2.2
|
||||||
flask-migrate < 2.1
|
|
||||||
flask-bootstrap < 3.4
|
|
||||||
flask-restful < 0.4
|
flask-restful < 0.4
|
||||||
passlib < 1.8
|
mysqlclient < 1.4
|
||||||
mysqlclient < 1.4
|
|
||||||
|
Reference in New Issue
Block a user