Skip to content

Commit

Permalink
test_black
Browse files Browse the repository at this point in the history
  • Loading branch information
joelclems committed Dec 11, 2023
1 parent c6a8f97 commit d349fcb
Show file tree
Hide file tree
Showing 43 changed files with 106 additions and 395 deletions.
16 changes: 3 additions & 13 deletions backend/gn_modulator/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def api_modules_config(config_path):
return txt, 500

return process_dict_path(
ModuleMethods.modules_config(),
config_path,
SchemaMethods.base_url() + "/config/",
ModuleMethods.modules_config(), config_path, SchemaMethods.base_url() + "/config/"
)


Expand Down Expand Up @@ -108,11 +106,7 @@ def api_layout(config_path):
layout_search_code=layout_search_code, as_dict=as_dict
)

return process_dict_path(
layout_out,
config_path,
SchemaMethods.base_url() + "/layouts/",
)
return process_dict_path(layout_out, config_path, SchemaMethods.base_url() + "/layouts/")


@blueprint.route("/schemas/<path:config_path>", methods=["GET"])
Expand All @@ -130,8 +124,4 @@ def api_schemas(config_path):
for schema_code in SchemaMethods.schema_codes()
}

return process_dict_path(
schemas,
config_path,
SchemaMethods.base_url() + "/schemas/",
)
return process_dict_path(schemas, config_path, SchemaMethods.base_url() + "/schemas/")
25 changes: 7 additions & 18 deletions backend/gn_modulator/definition/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ def load_definitions(cls, check_existing_definition=True):
# - dans ce cas c'est une partie du fichier de config,
# - par exemple
# - site-propertie.yml contient la clé 'properties' du dictionnaire de definition de site
for file in filter(
lambda f: (f.endswith(".yml") or f.endswith(".json")),
files,
):
for file in filter(lambda f: (f.endswith(".yml") or f.endswith(".json")), files):
file_path = Path(root) / file
cls.load_definition_file(
file_path, check_existing_definition=check_existing_definition
Expand Down Expand Up @@ -225,10 +222,7 @@ def set_cache(cls, definition_type, definition_code, definition, file_path):
if definition_type not in cls.definition_types():
cls.definition_types().append(definition_type)
set_global_cache([definition_type, definition_code, "definition"], definition)
set_global_cache(
[definition_type, definition_code, "file_path"],
file_path,
)
set_global_cache([definition_type, definition_code, "file_path"], file_path)

@classmethod
def local_check_definitions(cls):
Expand All @@ -238,8 +232,7 @@ def local_check_definitions(cls):

# pour chaque type de definition sauf reférence qui sont validée en amont
for definition_type in filter(
lambda x: x not in ["reference", "template", "use_template"],
cls.definition_types(),
lambda x: x not in ["reference", "template", "use_template"], cls.definition_types()
):
# pour
definition_codes = list(get_global_cache([definition_type], {}).keys())
Expand Down Expand Up @@ -349,10 +342,7 @@ def load_definition_file(cls, file_path, check_existing_definition=True):
)

@classmethod
def get_definition_type_and_code(
cls,
definition,
):
def get_definition_type_and_code(cls, definition):
"""
renvoie le type de definition et la clé pour le stockage dans le cache
lorsque l'on peut en trouver une pour le dictionnaire de definition
Expand Down Expand Up @@ -410,10 +400,9 @@ def global_check_definition(cls, definition_type, definition_code):
)

# dépendancies
dependencies = definition_type not in [
"template",
"use_template",
] and definition.get("dependencies")
dependencies = definition_type not in ["template", "use_template"] and definition.get(
"dependencies"
)
if dependencies:
definition_codes = cls.definition_codes_for_type(definition_type)
missing_dependencies = [
Expand Down
7 changes: 1 addition & 6 deletions backend/gn_modulator/imports/mixins/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,7 @@ def sql_nb_update(self):
# pour les relations n-n, ajout de with et join dans la requete
# les sous requete permettre d'agreger les clé étrangère dans des liste
# pour pouvoir comparer les valeurs des données et les valeurs existantes
relations_nn = list(
filter(
lambda x: self.Model().is_relation_n_n(x),
columns,
)
)
relations_nn = list(filter(lambda x: self.Model().is_relation_n_n(x), columns))
withs_rel = list(map(lambda x: self.update_count_with_rel(x), relations_nn))
joins_rel = list(map(lambda x: self.update_count_join_rel(x), relations_nn))

Expand Down
7 changes: 1 addition & 6 deletions backend/gn_modulator/imports/mixins/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ def process_step_raw_view(self):
# comptage et vérification de l'intégrité de la table
self.count_and_check_table("raw", dest_table)

def sql_raw_view(
self,
from_table,
dest_table,
limit=None,
):
def sql_raw_view(self, from_table, dest_table, limit=None):
"""
script de creation de la vue d'import 'raw'
"""
Expand Down
4 changes: 1 addition & 3 deletions backend/gn_modulator/imports/mixins/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def process_relation_n_n_data(self, relation_key):
keys = [self.Model().pk_field_name(), relation_Model.pk_field_name()]

sql_rel["insert"] = self.sql_insert(
tables_rel["process"],
keys=keys,
dest_table=dest_table,
tables_rel["process"], keys=keys, dest_table=dest_table
)

try:
Expand Down
10 changes: 2 additions & 8 deletions backend/gn_modulator/imports/mixins/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def sql_update(self, from_table):
map(
lambda x: x,
filter(
lambda x: self.Model().is_column(x) and x != self.id_digitiser_key(),
columns,
lambda x: self.Model().is_column(x) and x != self.id_digitiser_key(), columns
),
)
)
Expand All @@ -68,12 +67,7 @@ def sql_update(self, from_table):
# les condition d'update
# - pour toutes les colonnes v_set_keys
# on regarde si la données importée est distincte des données existante
v_update_condition = list(
map(
lambda x: f"(t.{x} IS DISTINCT FROM p.{x})",
v_column_keys,
)
)
v_update_condition = list(map(lambda x: f"(t.{x} IS DISTINCT FROM p.{x})", v_column_keys))

# texte sql pour l'instruction SET
txt_set_keys = ",\n ".join(v_set_keys)
Expand Down
3 changes: 1 addition & 2 deletions backend/gn_modulator/layout/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def get_layouts(cls, layout_search_code=None, layout_code=None, as_dict=False):

if layout_search_code:
layout_codes = filter(
lambda x: layout_search_code is None or layout_search_code in x,
layout_codes,
lambda x: layout_search_code is None or layout_search_code in x, layout_codes
)

if as_dict:
Expand Down
10 changes: 2 additions & 8 deletions backend/gn_modulator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
cor_module_groups = db.Table(
"cor_module_groupe",
db.Column(
"id_module",
db.Integer,
db.ForeignKey("gn_commons.t_modules.id_module"),
primary_key=True,
"id_module", db.Integer, db.ForeignKey("gn_commons.t_modules.id_module"), primary_key=True
),
db.Column(
"id_module_group",
Expand All @@ -22,10 +19,7 @@
cor_module_tags = db.Table(
"cor_module_tag",
db.Column(
"id_module",
db.Integer,
db.ForeignKey("gn_commons.t_modules.id_module"),
primary_key=True,
"id_module", db.Integer, db.ForeignKey("gn_commons.t_modules.id_module"), primary_key=True
),
db.Column(
"id_module_tag",
Expand Down
3 changes: 1 addition & 2 deletions backend/gn_modulator/module/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def registred_modules(cls):
"""
return list(
filter(
lambda module_code: cls.module_config(module_code)["registred"],
cls.module_codes(),
lambda module_code: cls.module_config(module_code)["registred"], cls.module_codes()
)
)

Expand Down
8 changes: 1 addition & 7 deletions backend/gn_modulator/module/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ def init_module_config(cls, module_code):
module_db = SchemaMethods("commons.module").get_row_as_dict(
module_code,
field_name="module_code",
fields=[
"module_code",
"module_picto",
"module_desc",
"module_label",
"module_path",
],
fields=["module_code", "module_picto", "module_desc", "module_label", "module_path"],
)

module_config = copy.deepcopy(module_definition)
Expand Down
57 changes: 6 additions & 51 deletions backend/gn_modulator/module/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,49 +300,15 @@ def add_basic_fields(cls, module_code, object_code):
sm = SchemaMethods(cls.schema_code(module_code, object_code))
if sm.definition is None:
return
authorized_read_fields = (
get_global_cache(
[
"keys",
module_code,
object_code,
"read",
]
)
or []
)
authorized_read_fields = get_global_cache(["keys", module_code, object_code, "read"]) or []

authorized_write_fields = (
get_global_cache(
[
"keys",
module_code,
object_code,
"read",
]
)
or []
get_global_cache(["keys", module_code, object_code, "read"]) or []
)

set_global_cache(
[
"keys",
module_code,
object_code,
"read",
],
authorized_read_fields,
)
set_global_cache(["keys", module_code, object_code, "read"], authorized_read_fields)

set_global_cache(
[
"keys",
module_code,
object_code,
"write",
],
authorized_write_fields,
)
set_global_cache(["keys", module_code, object_code, "write"], authorized_write_fields)

# pour la lecture, on ajoute par défaut les champs
# - pk_field_name
Expand Down Expand Up @@ -415,11 +381,7 @@ def get_layout_keys(cls, layout, params, context):
if layout.get("additional_fields"):
key_add += layout["additional_fields"]
if key_add:
cls.get_layout_keys(
key_add,
params,
{**context, "data_keys": []},
)
cls.get_layout_keys(key_add, params, {**context, "data_keys": []})
if (
layout.get("return_object")
and layout.get("additional_fields")
Expand Down Expand Up @@ -482,11 +444,4 @@ def add_key(cls, context, key):

@classmethod
def get_autorized_fields(cls, module_code, object_code, write=False):
return get_global_cache(
[
"keys",
module_code,
object_code,
"write" if write else "read",
]
)
return get_global_cache(["keys", module_code, object_code, "write" if write else "read"])
8 changes: 1 addition & 7 deletions backend/gn_modulator/query/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ class BaseSchemaQuery(BaseQuery):
def Model(self):
return self._primary_entity.mapper.entity

def getModelAttr(
self,
Model,
field_name,
only_fields="",
index=0,
):
def getModelAttr(self, Model, field_name, only_fields="", index=0):
return _getModelAttr(self, Model, field_name, only_fields=only_fields, index=index)

def clear_query_cache(self):
Expand Down
2 changes: 1 addition & 1 deletion backend/gn_modulator/query/existing_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def synthese_subquery_scope(cls, id_role):
pre_scope.c.id_organisme_af == pre_scope.c.id_organisme_cur,
),
)
),
)
),
2,
),
Expand Down
5 changes: 1 addition & 4 deletions backend/gn_modulator/query/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def process_fields(self, fields):
property_fields = list(
map(
lambda x: getattr(Model, x),
filter(
lambda x: "." not in x and not Model.is_relationship(x),
fields_to_process,
),
filter(lambda x: "." not in x and not Model.is_relationship(x), fields_to_process),
)
)

Expand Down
8 changes: 2 additions & 6 deletions backend/gn_modulator/query/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class unaccent(ReturnTypeFromArgs):
pass


class SchemaQueryFilters(
BaseSchemaQuery,
):
class SchemaQueryFilters(BaseSchemaQuery):
"""
repositories - filters
Expand Down Expand Up @@ -227,9 +225,7 @@ def get_filter(self, filter):
self = self.join(alias, getattr(alias, Model.pk_field_name()) == value)
geom = getattr(alias, geom_field)
geo_filter = func.ST_DWithin(
func.ST_GeogFromWKB(model_attribute),
func.ST_GeogFromWKB(geom),
radius,
func.ST_GeogFromWKB(model_attribute), func.ST_GeogFromWKB(geom), radius
)
filter_out = geo_filter

Expand Down
6 changes: 2 additions & 4 deletions backend/gn_modulator/query/getattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def _getModelAttr(query, BaseModel, field_name, only_fields="", index=0, conditi
else BaseModel
)

res = {
"val": getattr(current_Model, current_field),
}
res = {"val": getattr(current_Model, current_field)}

# si c'est une propriété
if is_relationship:
Expand Down Expand Up @@ -154,7 +152,7 @@ def _eager_load_only(query, field_name, only_fields, index):
),
only_fields,
),
),
)
)
if not only_columns_i:
relation_Model = query.Model().relation_Model(key_cache_eager)
Expand Down
Loading

0 comments on commit d349fcb

Please sign in to comment.