From aecb547072de2c061d5f3274b8898cabb3bf0ff4 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Wed, 29 Sep 2021 11:00:03 +0200 Subject: [PATCH] ref #50 --- app/modules/oeasc/commands.py | 44 +++++++++++++++++++++++++ app/modules/oeasc/generic/repository.py | 12 +++---- server.py | 20 +++++------ 3 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 app/modules/oeasc/commands.py diff --git a/app/modules/oeasc/commands.py b/app/modules/oeasc/commands.py new file mode 100644 index 00000000..003e2969 --- /dev/null +++ b/app/modules/oeasc/commands.py @@ -0,0 +1,44 @@ +""" + module MODULES administration commands + + - create_schema : generate schema template + - sql_schema : generate schema sql + - test_schema : process tests on a specified schema +""" + +import click +import json +import time + +from flask.cli import AppGroup, with_appcontext + +from app.utils.env import DB + +from app.modules.oeasc.chasse.models import TRealisationsChasse + +from app.modules.oeasc.generic.repository import ( + get_objects_type, + get_object_type, + create_or_update_object_type, + delete_object_type, +) + + +@click.command('test_chasse_realisation') +@click.option('-m', '--module_code', 'module_code', default='test') +@click.option('-s', '--schema_name', 'schema_name', default='example') +@with_appcontext +def cmd_test_chasse_realisation(module_code, schema_name): + ''' + Commande de test sur un schema + ''' + + post_data = json.loads('{"id_realisation":null,"saison":{"id_saison":7,"nom_saison":"2020-2021","date_debut":"2020-09-02","date_fin":"2021-05-01","current":true,"commentaire":null},"attribution":{"id_attribution":4617,"id_type_bracelet":2,"id_saison":7,"numero_bracelet":"CEFF 3502","id_zone_cynegetique_affectee":4,"id_zone_indicative_affectee":33,"meta_create_date":"2021-08-23 14:53:47.912476","meta_update_date":null,"saison":{"id_saison":7,"nom_saison":"2020-2021","date_debut":"2020-09-02","date_fin":"2021-05-01","current":true,"commentaire":null},"zone_cynegetique_affectee":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}},"zone_indicative_affectee":{"id_zone_indicative":33,"code_zone_indicative":"6","nom_zone_indicative":"ACPNC - Mont Lozère Est - Gard","id_zone_cynegetique":4,"zone_cynegetique":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}}},"type_bracelet":{"id_type_bracelet":2,"id_espece":1,"code_type_bracelet":"CEFF","description_type_bracelet":"sexe : Femelle, Indéterminé, Mâle; classe age : Adulte, Indéterminé, Jeune, Sub adulte; espece : Cerf élaphe","espece":{"id_espece":1,"nom_espece":"Cerf","code_espece":"CF"}}},"auteur_tir":null,"auteur_constat":null,"zone_cynegetique_affectee":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}},"zone_cynegetique_realisee":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}},"zone_indicative_affectee":{"id_zone_indicative":33,"code_zone_indicative":"6","nom_zone_indicative":"ACPNC - Mont Lozère Est - Gard","id_zone_cynegetique":4,"zone_cynegetique":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}}},"zone_indicative_realisee":{"id_zone_indicative":33,"code_zone_indicative":"6","nom_zone_indicative":"ACPNC - Mont Lozère Est - Gard","id_zone_cynegetique":4,"zone_cynegetique":{"id_zone_cynegetique":4,"code_zone_cynegetique":"MTLO_E_30","nom_zone_cynegetique":"Mont Lozère est (Gard)","id_secteur":3,"secteur":{"id_secteur":3,"code_secteur":"MTLO","nom_secteur":"Mont Lozère"}}},"lieu_tir_synonyme":null,"date_exacte":null,"date_enreg":null,"mortalite_hors_pc":null,"parcelle_onf":null,"nomenclature_sexe":null,"nomenclature_classe_age":null,"nomenclature_mode_chasse":null,"poid_entier":null,"poid_vide":null,"poid_c_f_p":null,"long_mandibules_droite":null,"long_mandibules_gauche":null,"long_dagues_droite":null,"long_dagues_gauche":null,"cors_nb":null,"cors_commentaires":null,"gestation":null,"commentaires":null,"freeze":false,"id_zone_cynegetique_affectee":4,"id_zone_indicative_affectee":33}') + print('test') + create_or_update_object_type('chasse', 'realisation', None, post_data) + print('test ok') + +# liste des commande pour export dans blueprint.py +commands = [ + cmd_test_chasse_realisation, +] \ No newline at end of file diff --git a/app/modules/oeasc/generic/repository.py b/app/modules/oeasc/generic/repository.py index 63c495e8..2fc86825 100644 --- a/app/modules/oeasc/generic/repository.py +++ b/app/modules/oeasc/generic/repository.py @@ -244,15 +244,15 @@ def create_or_update_object_type(module_name, object_type, id_value, post_data): ''' (Model, _) = definitions.get_model(module_name, object_type) - res = None + res = ( + get_object_type(module_name, object_type, id_value) if id_value + else Model() + ) + + res.from_dict(post_data, True) if not id_value: - res = Model() DB.session.add(res) - else: - res = get_object_type(module_name, object_type, id_value) - - res.from_dict(post_data, True) DB.session.commit() diff --git a/server.py b/server.py index aa8575d7..90d9c9aa 100644 --- a/server.py +++ b/server.py @@ -12,7 +12,6 @@ from flask_cors import CORS - class ReverseProxied(object): def __init__(self, app_in, script_name=None, scheme=None, server=None): @@ -56,15 +55,6 @@ def __call__(self, environ, start_response): app.config['SQLALCHEMY_ECHO'] = True -# @app.route('/') -# def accueil(): -# return redirect("/front/", code=302) - -# @app.route('/front/') -# def front(): -# return send_from_directory("static/frontend/dist", 'index.html') - - @app.route('/oeasc/', defaults={'text':''}) @app.route('/oeasc/') def redirect_front(text): @@ -75,6 +65,8 @@ def redirect_front(text): def google(): return redirect(url_for('static', filename='google4b0945b8a2f6425f.html')) + + with app.app_context(): from app.modules.oeasc.user.mail import function_dict @@ -135,6 +127,12 @@ def after_login_method(response): from pypnnomenclature.routes import routes app.register_blueprint(routes, url_prefix='/api/nomenclatures') + print('uuuu') + from app.modules.oeasc.commands import commands + for cmd in commands: + app.cli.add_command(cmd) + + if __name__ == '__main__': app.run(debug=config.DEBUG, port=config.PORT) @@ -176,3 +174,5 @@ def cleanid(eval_ctx, value): s2 = s2.replace(".", "") s2 = s2.strip() return s2 + +