Skip to content

Commit

Permalink
linter backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Corny committed Apr 17, 2024
1 parent 1d6d396 commit 503152c
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 239 deletions.
15 changes: 6 additions & 9 deletions backend/gn_module_zh/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def get_zh(scope):
def get_all_zh(info_role, query, limit, page, orderby=None, order="asc"):
# try:
# Pour obtenir le nombre de résultat de la requete sans le LIMIT
nb_results_without_limit = (
DB.session.scalar(select(func.count()).select_from(query.subquery()))
nb_results_without_limit = DB.session.scalar(
select(func.count()).select_from(query.subquery())
)
user = info_role
user_cruved = get_user_cruved()
Expand Down Expand Up @@ -154,10 +154,7 @@ def get_all_zh(info_role, query, limit, page, orderby=None, order="asc"):

# Order by id because there can be ambiguity in order_by(col) depending
# on the column so add on order_by id makes it clearer
data = (
DB.session.scalars(query.order_by(TZH.id_zh).limit(limit).offset(page * limit))
.all()
)
data = DB.session.scalars(query.order_by(TZH.id_zh).limit(limit).offset(page * limit)).all()
is_ref_geo = check_ref_geo_schema()

featureCollection = []
Expand Down Expand Up @@ -773,9 +770,9 @@ def deleteOneZh(id_zh):
DB.session.execute(delete(CorZhRef).where(CorZhRef.id_zh == id_zh))

# delete criteres delim
id_lim_list = (
DB.session.execute(select(TZH.id_lim_list).where(TZH.id_zh == id_zh)).scalar_one()
)
id_lim_list = DB.session.execute(
select(TZH.id_lim_list).where(TZH.id_zh == id_zh)
).scalar_one()
DB.session.execute(delete(CorLimList).where(CorLimList.id_lim_list == id_lim_list))

# delete cor_zh_area
Expand Down
123 changes: 54 additions & 69 deletions backend/gn_module_zh/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,28 @@ def create_zh(form_data, info_role, zh_date, polygon, zh_area, ref_geo_referenti
post_cor_zh_area(
polygon,
new_zh.id_zh,
DB.session.execute(select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "COM"))
.scalar_one(),
DB.session.execute(
select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "COM")
).scalar_one(),
)
# fill cor_zh_area for departements
post_cor_zh_area(
polygon,
new_zh.id_zh,
DB.session.execute(select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "DEP"))
.scalar_one(),
DB.session.execute(
select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "DEP")
).scalar_one(),
)
# fill cor_zh_area for other geo referentials
for ref in ref_geo_referentiels:
post_cor_zh_area(
polygon,
new_zh.id_zh,
DB.session.execute(
select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == ref["type_code_ref_geo"])
)
.scalar_one(),
select(BibAreasTypes.id_type).where(
BibAreasTypes.type_code == ref["type_code_ref_geo"]
)
).scalar_one(),
)

# fill cor_zh_rb
Expand All @@ -118,14 +121,11 @@ def create_zh(form_data, info_role, zh_date, polygon, zh_area, ref_geo_referenti
new_zh.code = code.__repr__()
new_zh.ef_area = total_cover
# set default values
fct_delim_default_id = (
DB.session.execute(
select(DefaultsNomenclaturesValues.id_nomenclature).where(
DefaultsNomenclaturesValues.mnemonique_type == "CRIT_DEF_ESP_FCT"
)
fct_delim_default_id = DB.session.execute(
select(DefaultsNomenclaturesValues.id_nomenclature).where(
DefaultsNomenclaturesValues.mnemonique_type == "CRIT_DEF_ESP_FCT"
)
.scalar_one()
)
).scalar_one()

post_fct_delim(new_zh.id_zh, [fct_delim_default_id])

Expand Down Expand Up @@ -350,14 +350,16 @@ def update_cor_zh_area(polygon, id_zh, geo_refs):
post_cor_zh_area(
polygon,
id_zh,
DB.session.execute(select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "COM"))
.scalar_one(),
DB.session.execute(
select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "COM")
).scalar_one(),
)
post_cor_zh_area(
polygon,
id_zh,
DB.session.execute(select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "DEP"))
.scalar_one(),
DB.session.execute(
select(BibAreasTypes.id_type).where(BibAreasTypes.type_code == "DEP")
).scalar_one(),
)
# fill cor_zh_area for other geo referentials
for ref in geo_refs:
Expand All @@ -368,8 +370,7 @@ def update_cor_zh_area(polygon, id_zh, geo_refs):
select(BibAreasTypes.id_type).where(
BibAreasTypes.type_code == ref["type_code_ref_geo"]
)
)
.scalar_one(),
).scalar_one(),
)
except Exception as e:
if e.__class__.__name__ == "DataError":
Expand Down Expand Up @@ -776,8 +777,7 @@ def post_managements(id_zh, managements):
TManagementStructures.id_org == management["structure"],
)
)
)
.scalar_one(),
).scalar_one(),
plan_date=datetime.datetime.strptime(plan["plan_date"], "%d/%m/%Y"),
duration=plan["duration"],
remark=plan["remark"],
Expand Down Expand Up @@ -844,8 +844,7 @@ def post_protections(id_zh, protections):
select(CorProtectionLevelType.id_protection).where(
CorProtectionLevelType.id_protection_status == protection
)
)
.scalar_one(),
).scalar_one(),
id_zh=id_zh,
)
)
Expand Down Expand Up @@ -902,14 +901,11 @@ def update_urban_docs(id_zh, urban_docs):

def post_urban_docs(id_zh, urban_docs):
for urban_doc in urban_docs:
id_doc_type = (
DB.session.execute(
select(CorUrbanTypeRange.id_doc_type).where(
CorUrbanTypeRange.id_cor == urban_doc["id_urban_type"][0]["id_cor"]
)
id_doc_type = DB.session.execute(
select(CorUrbanTypeRange.id_doc_type).where(
CorUrbanTypeRange.id_cor == urban_doc["id_urban_type"][0]["id_cor"]
)
.scalar_one()
)
).scalar_one()
uuid_doc = uuid.uuid4()
DB.session.add(
TUrbanPlanningDocs(
Expand Down Expand Up @@ -967,31 +963,27 @@ def post_actions(id_zh, actions):

def post_file_info(id_zh, title, author, description, extension, media_path=None):
try:
unique_id_media = (
DB.session.execute(select(TZH.zh_uuid).where(TZH.id_zh == int(id_zh))).scalar_one()
)
unique_id_media = DB.session.execute(
select(TZH.zh_uuid).where(TZH.id_zh == int(id_zh))
).scalar_one()
uuid_attached_row = uuid.uuid4()
if extension == ".pdf":
mnemo = "PDF"
elif extension == ".csv":
mnemo = "Tableur"
else:
mnemo = "Photo"
id_nomenclature_media_type = (
DB.session.execute(select(TNomenclatures.id_nomenclature).where(TNomenclatures.mnemonique == mnemo))
.scalar_one()
)
id_table_location = (
DB.session.execute(
select(BibTablesLocation.id_table_location).where(
and_(
BibTablesLocation.schema_name == "pr_zh",
BibTablesLocation.table_name == "t_zh",
)
id_nomenclature_media_type = DB.session.execute(
select(TNomenclatures.id_nomenclature).where(TNomenclatures.mnemonique == mnemo)
).scalar_one()
id_table_location = DB.session.execute(
select(BibTablesLocation.id_table_location).where(
and_(
BibTablesLocation.schema_name == "pr_zh",
BibTablesLocation.table_name == "t_zh",
)
)
.scalar_one()
)
).scalar_one()
post_date = datetime.datetime.now()
DB.session.add(
TMedias(
Expand All @@ -1009,12 +1001,9 @@ def post_file_info(id_zh, title, author, description, extension, media_path=None
)
)
DB.session.commit()
id_media = (
DB.session.execute(
select(TMedias.id_media).where(TMedias.uuid_attached_row == uuid_attached_row)
)
.scalar_one()
)
id_media = DB.session.execute(
select(TMedias.id_media).where(TMedias.uuid_attached_row == uuid_attached_row)
).scalar_one()
return id_media
except Exception as e:
if e.__class__.__name__ == "DataError":
Expand All @@ -1028,21 +1017,18 @@ def post_file_info(id_zh, title, author, description, extension, media_path=None

def patch_file_info(id_zh, id_media, title, author, description):
try:
unique_id_media = (
DB.session.execute(select(TZH.zh_uuid).where(TZH.id_zh == int(id_zh))).scalar_one()
)
unique_id_media = DB.session.execute(
select(TZH.zh_uuid).where(TZH.id_zh == int(id_zh))
).scalar_one()
uuid_attached_row = uuid.uuid4()
id_table_location = (
DB.session.execute(
select(BibTablesLocation.id_table_location).where(
and_(
BibTablesLocation.schema_name == "pr_zh",
BibTablesLocation.table_name == "t_zh",
)
id_table_location = DB.session.execute(
select(BibTablesLocation.id_table_location).where(
and_(
BibTablesLocation.schema_name == "pr_zh",
BibTablesLocation.table_name == "t_zh",
)
)
.scalar_one()
)
).scalar_one()
post_date = datetime.datetime.now()
DB.session.execute(
update(TMedias)
Expand Down Expand Up @@ -1077,10 +1063,9 @@ def update_file_extension(id_media, extension):
mnemo = "Tableur"
else:
mnemo = "Photo"
id_nomenclature_media_type = (
DB.session.execute(select(TNomenclatures.id_nomenclature).where(TNomenclatures.mnemonique == mnemo))
.scalar_one()
)
id_nomenclature_media_type = DB.session.execute(
select(TNomenclatures.id_nomenclature).where(TNomenclatures.mnemonique == mnemo)
).scalar_one()
DB.session.execute(
update(TMedias)
.where(TMedias.id_media == id_media)
Expand Down
Loading

0 comments on commit 503152c

Please sign in to comment.