Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/medias tmarkings events and little fixes #3303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,7 @@ install_all/install_all.log

/docs/CHANGELOG.html


/contrib/*/frontend/node_modules

*.DS_Store
9 changes: 9 additions & 0 deletions backend/geonature/core/gn_monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class TMarkingEvent(DB.Model):
__table_args__ = {"schema": "gn_monitoring"}

id_marking = DB.Column(DB.Integer, primary_key=True, autoincrement=True)
uuid_marking = DB.Column(UUID(as_uuid=True), default=select(func.uuid_generate_v4()))
id_individual = DB.Column(
DB.ForeignKey(f"gn_monitoring.t_individuals.id_individual", ondelete="CASCADE"),
nullable=False,
Expand Down Expand Up @@ -288,6 +289,14 @@ class TMarkingEvent(DB.Model):

digitiser = DB.relationship(User, lazy="joined", foreign_keys=[id_digitiser])

medias = DB.relationship(
TMedias,
lazy="joined",
primaryjoin=(TMedias.uuid_attached_row == uuid_marking),
foreign_keys=[TMedias.uuid_attached_row],
overlaps="medias,medias",
)

@hybrid_property
def organism_actors(self):
# return self.digitiser.id_organisme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def upgrade():
op.create_table(
"t_marking_events",
sa.Column("id_marking", sa.Integer, primary_key=True),
sa.Column(
"uuid_marking", UUID, nullable=False, server_default=sa.text("uuid_generate_v4()")
),
sa.Column(
"id_module",
sa.Integer,
Expand All @@ -80,7 +83,7 @@ def upgrade():
sa.ForeignKey(f"{SCHEMA}.t_individuals.id_individual", ondelete="CASCADE"),
nullable=False,
),
sa.Column("marking_date", sa.DateTime(timezone=False), nullable=False),
sa.Column("marking_date", sa.Date, nullable=False),
sa.Column(
"id_operator",
sa.Integer,
Expand Down Expand Up @@ -129,11 +132,51 @@ def upgrade():
),
schema=SCHEMA,
)
# TODO: add constraint to id_nomenclature_marking_type to check

op.execute(
"""
ALTER TABLE gn_monitoring.t_marking_events
ADD CONSTRAINT check_marking_type
CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(
id_nomenclature_marking_type, 'TYP_MARQUAGE'::character varying)
) NOT VALID;
"""
)

op.execute(
"""
INSERT INTO gn_commons.bib_tables_location (
table_desc, schema_name, table_name,
pk_field, uuid_field_name
)
VALUES
('Table centralisant les individus faisant l''objet de protocole de suivis',
'gn_monitoring','t_individuals','id_individual','uuid_individual'),
('Table centralisant les marquages réalisés sur les individus dans le cadre
de protocoles de suivis',
'gn_monitoring','t_marking_events','id_marking_event','uuid_marking');
"""
)


def downgrade():
op.drop_table("cor_individual_module", schema=SCHEMA)
op.execute(
"""
DELETE FROM gn_commons.t_medias m
WHERE id_table_location IN (
SELECT id_table_location FROM gn_commons.bib_tables_location
WHERE table_name IN ('t_individuals', 't_marking_events')
);
"""
)
op.execute(
"""
DELETE FROM gn_commons.bib_tables_location
WHERE table_name IN ('t_individuals', 't_marking_events')
AND schema_name='gn_monitoring';
"""
)
op.drop_table("t_marking_events", schema=SCHEMA)
op.execute(
"""
Expand Down
1 change: 1 addition & 0 deletions contrib/occtax/backend/occtax/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class CorCountingOccurrence(DB.Model):
foreign_keys=[TMedias.uuid_attached_row],
cascade="all",
lazy="select",
overlaps="medias",
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class IndividualsComponent implements OnInit {
) {}
ngOnInit(): void {
this.getIndividuals().subscribe((data) => {
this.values = data;
this.values = data.filter(item => item.active);
});
}

Expand Down
Loading