From 928f8e81598a4613ad42e5c125e130fe943ccc10 Mon Sep 17 00:00:00 2001 From: amandine-sahl Date: Thu, 30 Mar 2023 16:47:14 +0200 Subject: [PATCH 1/2] Add current parameters --- app/modules/oeasc/chasse/api.py | 11 ++++------- app/modules/oeasc/chasse/repositories.py | 6 ++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/modules/oeasc/chasse/api.py b/app/modules/oeasc/chasse/api.py index eca6a527..80fc84b9 100644 --- a/app/modules/oeasc/chasse/api.py +++ b/app/modules/oeasc/chasse/api.py @@ -161,15 +161,12 @@ def api_chasse_ods(): template_path = ROOT_DIR / "app/templates/ods/template_bilan_chasse.ods" output_path = ROOT_DIR / "static/export/test.ods" + nom_saison = request.args.get("saison", "current") + + data = get_data_all_especes_export_ods(nom_saison) - data = get_data_all_especes_export_ods("2021-2022") - # return jsonify(data) - # data = { - # "nom_saison": "2021-2022", - # "nom_espece": "Chevreuil" - # } output_path.parent.mkdir(parents=True, exist_ok=True) t = Template(template_path, output_path) t.render(data) - return send_file(output_path) + return send_file(output_path, as_attachment=True, attachment_filename=f"bilan_chasse_{nom_saison}.ods") diff --git a/app/modules/oeasc/chasse/repositories.py b/app/modules/oeasc/chasse/repositories.py index 0f74152c..511485b0 100644 --- a/app/modules/oeasc/chasse/repositories.py +++ b/app/modules/oeasc/chasse/repositories.py @@ -738,6 +738,12 @@ def get_data_export_ods(nom_saison, nom_espece): def get_data_all_especes_export_ods(nom_saison): + if nom_saison == "current": + nom_saison = ( + DB.session.query(TSaisons.nom_saison) + .filter(TSaisons.current == True) + .one()[0] + ) data = {"nom_saison": nom_saison, "especes": []} for nom_espece in ["Cerf", "Chevreuil", "Mouflon"]: data["especes"].append(get_data_export_ods(nom_saison, nom_espece)) From e13c7555179afd5fe2d453a88c2c763bd54e49f3 Mon Sep 17 00:00:00 2001 From: amandine-sahl Date: Thu, 30 Mar 2023 16:51:00 +0200 Subject: [PATCH 2/2] Black --- app/modules/oeasc/chasse/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/modules/oeasc/chasse/api.py b/app/modules/oeasc/chasse/api.py index 80fc84b9..48bfbd21 100644 --- a/app/modules/oeasc/chasse/api.py +++ b/app/modules/oeasc/chasse/api.py @@ -169,4 +169,8 @@ def api_chasse_ods(): t = Template(template_path, output_path) t.render(data) - return send_file(output_path, as_attachment=True, attachment_filename=f"bilan_chasse_{nom_saison}.ods") + return send_file( + output_path, + as_attachment=True, + attachment_filename=f"bilan_chasse_{nom_saison}.ods", + )