Skip to content

Commit

Permalink
Modification structure, nom de champs
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Sep 3, 2020
1 parent b5f1738 commit 5037608
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 27 deletions.
4 changes: 2 additions & 2 deletions backend/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class ContactTaxon(DB.Model):
cd_nom = DB.Column(DB.Integer)
nom_complet = DB.Column(DB.Unicode(250))
espece_incertaine = DB.Column(DB.Boolean, default=False)
id_nomenclature_activite = DB.Column(DB.Integer)
id_nomenclature_preuve_repro = DB.Column(DB.Integer)
id_nomenclature_behaviour = DB.Column(DB.Integer)
id_nomenclature_preuve_repro = DB.Column(DB.Integer)
id_nomenclature_bio_condition = DB.Column(DB.Integer)
id_nomenclature_observation_status = DB.Column(DB.Integer)
indices_cmt = DB.Column(DB.Unicode(250))
commentaire = DB.Column(DB.Unicode(250))
Expand Down
7 changes: 7 additions & 0 deletions backend/utils/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
À déplacer à terme dans Geonature/backend/gn_monitoring
"""

import logging
from flask import current_app
from sqlalchemy import and_

Expand All @@ -29,6 +30,8 @@

from ..utils.relations import get_updated_relations

# get the root logger
log = logging.getLogger()

def process_synthese(schema_name, table_name, field_name, value):

Expand Down Expand Up @@ -331,6 +334,10 @@ def attach_uuid_to_medium(medium, uuid_attached_row):
Fonction permettant de ratacher à posteriori
une liste de media à une entité
'''
# Si liste vide aucun traitement
if not medium:
return

for m in medium:
m['uuid_attached_row'] = uuid_attached_row
mr = TMediaRepository(data=m, id_media=m['id_media'])
Expand Down
6 changes: 3 additions & 3 deletions configs.sample/obs_taxon/detail.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ subSchemaAdd = 3
label = "Description indices"

[[groups.fields]]
name = "id_nomenclature_activite"
name = "id_nomenclature_behaviour"
thesaurus_code_type = "CHI_ACTIVITE"
type = "select"
label = "Activité"

[[groups.fields]]
name = "id_nomenclature_eta_bio"
name = "id_nomenclature_bio_condition"
thesaurus_code_type = "ETA_BIO"
type = "select"
label = "Etat biologique"
Expand All @@ -63,7 +63,7 @@ subSchemaAdd = 3
label = "Preuves de reproduction"

[[groups.fields]]
name = "id_nomenclature_activite"
name = "id_nomenclature_behaviour"
thesaurus_code_type = "STATUT_OBS"
type = "select"
label = "Statut de l'observation"
Expand Down
4 changes: 2 additions & 2 deletions configs.sample/obs_taxon/form.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ name = "Informations"
[[groups.fields]]
thesaurus_code_type = "ETA_BIO"
label = "Etat bio"
name = "id_nomenclature_eta_bio"
name = "id_nomenclature_bio_condition"
type = "select"
regne = "Animalia"
group2_inpn = "Mammifères"
Expand All @@ -73,7 +73,7 @@ name = "Informations"
[[groups.fields]]
thesaurus_code_type = "CHI_ACTIVITE"
label = "Activité"
name = "id_nomenclature_activite"
name = "id_nomenclature_behaviour"
type = "select"
[groups.fields.options]
nullable = true
Expand Down
9 changes: 2 additions & 7 deletions configs.sample/obs_taxon/form_many.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@
type = "string"
label = "Taxon initial"

[[fields]]
name = "espece_incertaine"
type = "bool"
label = "Espece incertaine"

[[fields]]
thesaurus_code_type = "ETA_BIO"
label = "Etat bio"
name = "id_nomenclature_eta_bio"
name = "id_nomenclature_bio_condition"
type = "select"
regne = "Animalia"
group2_inpn = "Mammifères"
Expand All @@ -47,7 +42,7 @@
[[fields]]
thesaurus_code_type = "CHI_ACTIVITE"
label = "Activité"
name = "id_nomenclature_activite"
name = "id_nomenclature_behaviour"
type = "select"
[fields.options]
nullable = true
Expand Down
8 changes: 4 additions & 4 deletions data/data_chiro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ VALUES
(ref_nomenclatures.get_id_nomenclature_type('CHI_REPRO'),'RC','Reproduction certaine','Reproduction certaine','Reproduction certaine','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_REPRO'),'RP','Reproduction probable','Reproduction probable','Reproduction probable','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'T','Transit','Transit','Transit','monitoring_chiro','Validation en cours',0,'013.001.001',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'H','Hivernage','Hivernage','Hivernage','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'C','Chasse','Chasse','Chasse','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'D','Déplacement','Déplacement','Déplacement','monitoring_chiro','Validation en cours',0,'013.001.004',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'9','Hivernage','Hivernage','Hivernage','monitoring_chiro','Validation en cours',0,'013.001.002',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'8','ChassAlim','Chasse/alimentation','Chasse/alimentation','monitoring_chiro','Validation en cours',0,'013.001.003',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'16','Déplacement','Déplacement','Déplacement','monitoring_chiro','Validation en cours',0,'013.001.004',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'SG','Sortie de gîte','Sortie de gîte','Sortie de gîte','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE),
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'SW','Swarming','Swarming','Swarming','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE)
(ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE'),'7','Swarming','Swarming','Swarming','monitoring_chiro','Validation en cours',0,'013.001.005',TRUE)

ON CONFLICT ON CONSTRAINT unique_id_type_cd_nomenclature DO NOTHING;

Expand Down
10 changes: 5 additions & 5 deletions data/schema_chiro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ CREATE TABLE monitoring_chiro.t_visite_contact_taxons (
nom_complet character varying(255),
espece_incertaine boolean DEFAULT false NOT NULL,
id_nomenclature_preuve_repro integer,
id_nomenclature_activite integer,
id_nomenclature_etat_bio integer,
id_nomenclature_behaviour integer,
id_nomenclature_bio_condition integer,
id_nomenclature_observation_status integer,
indices_cmt character varying(1000),
commentaire character varying(1000),
Expand Down Expand Up @@ -165,13 +165,13 @@ ALTER TABLE monitoring_chiro.t_contact_taxon_biometries
ADD CONSTRAINT check_cor_counting_contact_life_stage CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_life_stage, 'STADE_VIE')) NOT VALID;

ALTER TABLE monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT check_t_visite_contact_taxons_etat_bio CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_etat_bio, 'ETA_BIO')) NOT VALID;
ADD CONSTRAINT check_t_visite_contact_taxons_bio_condition CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_condition, 'ETA_BIO')) NOT VALID;

ALTER TABLE monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT check_t_visite_contact_taxons_preuve_repro CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_preuve_repro, 'CHI_REPRO')) NOT VALID;

ALTER TABLE monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT check_t_visite_contact_taxons_activite CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_activite, 'CHI_ACTIVITE')) NOT VALID;
ADD CONSTRAINT check_t_visite_contact_taxons_behaviour CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_behaviour, 'CHI_ACTIVITE')) NOT VALID;

ALTER TABLE monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT check_t_visite_contact_taxons_obs_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_observation_status, 'STATUT_OBS')) NOT VALID;
Expand Down Expand Up @@ -310,7 +310,7 @@ ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT t_visite_contact_taxons_id_digitiser_fkey FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE;

ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_activite_fkey FOREIGN KEY (id_nomenclature_activite) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE;
ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_behaviour_fkey FOREIGN KEY (id_nomenclature_behaviour) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE;

ALTER TABLE ONLY monitoring_chiro.t_visite_contact_taxons
ADD CONSTRAINT t_visite_contact_taxons_id_nomenclature_preuve_repro_fkey FOREIGN KEY (id_nomenclature_preuve_repro) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE;
Expand Down
18 changes: 15 additions & 3 deletions data/view_synthese.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@

DROP VIEW monitoring_chiro.v_chiro_gn_synthese ;
DROP VIEW IF EXISTS monitoring_chiro.v_chiro_gn_synthese ;
CREATE OR REPLACE VIEW monitoring_chiro.v_chiro_gn_synthese AS
WITH source AS (
SELECT id_source FROM gn_synthese.t_sources WHERE name_source = 'SUIVI_CHIRO'
), cor_nom_act_comp AS (
SELECT ca.id_nomenclature as id_nomenclature_act, co.id_nomenclature as id_nomenclature_comp
FROM ref_nomenclatures.t_nomenclatures ca
JOIN ref_nomenclatures.t_nomenclatures co
ON ca.id_type = ref_nomenclatures.get_id_nomenclature_type('CHI_ACTIVITE')
AND
co.id_type = ref_nomenclatures.get_id_nomenclature_type('OCC_COMPORTEMENT')
AND ca.cd_nomenclature = co.cd_nomenclature
)
SELECT
ccc.unique_id_sinp as unique_id_sinp,
Expand All @@ -15,7 +23,7 @@ SELECT
v.id_nomenclature_grp_typ as id_nomenclature_grp_typ,
-- MISSING FIELD id_nomenclature_obs_meth,
-- NOT IN SYNTHESE v.id_nomenclature_tech_collect_campanule as id_nomenclature_tech_collect_campanule,
vct.id_nomenclature_etat_bio as id_nomenclature_bio_condition,
vct.id_nomenclature_bio_condition as id_nomenclature_bio_condition,
-- MISSING FIELD id_nomenclature_bio_status,
-- MISSING FIELD id_nomenclature_naturalness,
-- MISSING FIELD id_nomenclature_exist_proof,
Expand All @@ -24,10 +32,12 @@ ccc.id_nomenclature_life_stage,
ccc.id_nomenclature_sex,
ccc.id_nomenclature_obj_count,
ccc.id_nomenclature_type_count,
vct.id_nomenclature_observation_status,
-- MISSING FIELD id_nomenclature_observation_status,
-- MISSING FIELD id_nomenclature_blurring,
-- MISSING FIELD id_nomenclature_source_status,
-- MISSING FIELD id_nomenclature_info_geo_type,
cnac.id_nomenclature_comp as id_nomenclature_behaviour,
ccc.count_min,
ccc.count_max,
vct.cd_nom as cd_nom,
Expand Down Expand Up @@ -65,4 +75,6 @@ LEFT OUTER JOIN (
ON vr.id_role = r.id_role
GROUP BY id_base_visit
) obs
ON obs.id_base_visit = v.id_base_visit;
ON obs.id_base_visit = v.id_base_visit
LEFT OUTER JOIN cor_nom_act_comp cnac
ON cnac.id_nomenclature_act = vct.id_nomenclature_behaviour ;
2 changes: 1 addition & 1 deletion data/views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ct.cd_nom,
ct.nom_complet,
ccc.nb_total_min,
ccc.nb_total_max
/*espece_incertaine, id_nomenclature_preuve_repro, id_nomenclature_activite,
/*espece_incertaine, id_nomenclature_preuve_repro, id_nomenclature_behaviour,
indices_cmt, commentaire, meta_create_date, meta_update_date,
id_digitiser, db_suivi_id, app*/
FROM monitoring_chiro.t_visite_contact_taxons ct
Expand Down

1 comment on commit 5037608

@camillemonchicourt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joli, ça vaudrait le coup de faire une RELEASE quand y a une version du module compatible avec une version de GeoNature.

Please sign in to comment.