Skip to content

Commit

Permalink
fix medias for individuals & marking events + TIndividuals.nb_sites
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanMaillard authored and andriacap committed Aug 12, 2024
1 parent 5b0de36 commit 4091e60
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ tmp/
npm-debug.log*
yarn-error.log*
.ng_pkg_build/

*.DS_Store
7 changes: 6 additions & 1 deletion backend/gn_module_monitoring/config/generic/individual.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@
"required": true,
"hidden": true,
"type_util": "user"
}
},
"medias": {
"type_widget": "medias",
"attribut_label": "Médias",
"schema_dot_table": "gn_monitoring.t_individuals"
}
},
"change": [
"({objForm, meta}) => {",
Expand Down
5 changes: 5 additions & 0 deletions backend/gn_module_monitoring/config/generic/marking.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"required": true,
"hidden": true,
"type_util": "user"
},
"medias": {
"type_widget": "medias",
"attribut_label": "Médias",
"schema_dot_table": "gn_monitoring.t_marking_events"
}
}
}
38 changes: 9 additions & 29 deletions backend/gn_module_monitoring/monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,18 @@ class TMonitoringModules(TModules):

TIndividuals.nb_sites = column_property(
select([func.count(func.distinct(TMonitoringSites.id_base_site))])
.where(
and_(
TObservations.id_individual == TIndividuals.id_individual,
TObservations.id_base_visit == TMonitoringVisits.id_base_visit,
TBaseVisits.id_base_site == TMonitoringSites.id_base_site,
)
.join_from(
TObservations, TBaseVisits, TBaseVisits.id_base_visit == TObservations.id_base_visit
).join_from(
TBaseVisits, TMonitoringSites, TMonitoringSites.id_base_site == TBaseVisits.id_base_site
)
.correlate_except(TMonitoringSites)
.where(TObservations.id_individual == TIndividuals.id_individual)
.correlate_except(
TBaseVisits
) # Correlate permet d'éviter une répétition de la condition WHERE dans la sous requête
.scalar_subquery()
)
# NOTES: [SUIVI_INDIVIDU] pourquoi c'est nécessaire de le garder ici ?

TMonitoringSites.nb_individuals = column_property(
select([func.count(func.distinct(TIndividuals.id_individual))])
.join_from(
Expand All @@ -412,27 +413,6 @@ class TMonitoringModules(TModules):
) # Correlate permet d'éviter une répétition de la condition WHERE dans la sous requête
.scalar_subquery()
)
# NOTES: [SUIVI_INDIVIDU] ici le id_base_marking_site peut être null si on renseigne un marquage en entrant directement par les inidividus
# TIndividuals.nb_sites = column_property(
# select([func.count(func.distinct(TMonitoringSites.id_base_site))]).where(
# and_(
# TMarkingEvent.id_individual == TIndividuals.id_individual,
# TMarkingEvent.id_base_marking_site == TMonitoringSites.id_base_site,
# )
# )
# .scalar_subquery()
# )
# NOTES: [SUIVI_INDIVIDU] ici pareil le id_base_marking_site peut être null si on renseigne un marquage en entrant directement par les inidividus
# TMonitoringSites.nb_individuals = column_property(
# select([func.count(func.distinct(TIndividuals.id_individual))]).where(
# and_(
# TMarkingEvent.id_base_marking_site == TMonitoringSites.id_base_site,
# TMarkingEvent.id_individual == TIndividuals.id_individual,
# )
# )
# .scalar_subquery()
# )


# note the alias is mandotory otherwise the where is done on the subquery table
# and not the global TMonitoring table
Expand Down

0 comments on commit 4091e60

Please sign in to comment.