Skip to content

Commit

Permalink
feat(back): add custom config when post site
Browse files Browse the repository at this point in the history
Change backend files in order to choose specific config when site is
created.

Reviewed-by: andriac
[Refs_ticket]: #5 , #6
  • Loading branch information
andriacap committed Apr 5, 2023
1 parent d282c78 commit a517e25
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion backend/gn_module_monitoring/config/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_config_objects(module_code, config, tree=None, parent_type=None, customS

# recursif
if tree[object_type]:
get_config_objects(module_code, config, tree[object_type], object_type)
get_config_objects(module_code, config, tree[object_type], object_type,customSpecConfig)


def config_object_from_files(module_code, object_type,custom=None):
Expand All @@ -87,6 +87,8 @@ def config_object_from_files(module_code, object_type,custom=None):
generic_config_object = json_config_from_file('generic', object_type)
specific_config_object = {} if module_code == 'generic' else json_config_from_file(module_code, object_type)

if module_code == 'generic' and object_type == 'site' and custom is not None:
specific_config_object = custom
config_object = generic_config_object
config_object.update(specific_config_object)

Expand Down
4 changes: 4 additions & 0 deletions backend/gn_module_monitoring/monitoring/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def preprocess_data(self, data):
for id_type_site in data['types_site']:
if int(id_type_site) not in type_site_ids:
type_site_ids.append(id_type_site)
#TODO: A enlever une fois qu'on aura enelever le champ "id_nomenclature_type_site" du model et de la bdd
data["id_nomenclature_type_site"]=data["types_site"][0]

data['types_site'] = type_site_ids


# module_ids = [module.id_module for module in self._model.modules]
# id_module = int(data['id_module'])
# if id_module not in module_ids:
Expand Down
3 changes: 3 additions & 0 deletions backend/gn_module_monitoring/monitoring/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def populate(self, post_data):

# ajout des données en base
if hasattr(self._model, 'from_geofeature'):
for key in list(post_data):
if key not in ("properties","geometry","type"):
post_data.pop(key)
self._model.from_geofeature(post_data, True)
else:
self._model.from_dict(properties, True)
6 changes: 5 additions & 1 deletion backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ def get_module_sites(module_code: str):
def post_sites():
module_code = "generic"
object_type = "site"
customConfig = dict()
post_data = dict(request.get_json())
get_config(module_code, force=True)
for keys in post_data['dataComplement'].keys():
if 'config' in post_data['dataComplement'][keys]:
customConfig.update( post_data['dataComplement'][keys]['config'])
get_config(module_code, force=True,customSpecConfig=customConfig)
return create_or_update_object_api(module_code, object_type), 201
4 changes: 4 additions & 0 deletions backend/gn_module_monitoring/routes/sites_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def create_or_update_object_api(module_code, object_type, id=None):
module = get_module("module_code", module_code)
else:
module = {"id_module": "generic"}
#TODO : A enlever une fois que le post_data contiendra geometry et type depuis le front
if object_type == "site":
post_data["geometry"]={'type':'Point', 'coordinates':[2.5,50]}
post_data["type"]='Feature'
# on rajoute id_module s'il n'est pas renseigné par défaut ??
if "id_module" not in post_data["properties"]:
module["id_module"] = "generic"
Expand Down

0 comments on commit a517e25

Please sign in to comment.