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/group3 inpn taxonomie #53

Merged
merged 10 commits into from
Jan 26, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "postgis_raster";'
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "uuid-ossp";'
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "pg_trgm";'
psql -h localhost -U postgres -d postgres -tc 'CREATE EXTENSION "unaccent";'
env:
PGPASSWORD: postgres
- uses: actions/checkout@v2
Expand All @@ -73,6 +74,7 @@ jobs:
-e file:dependencies/UsersHub-authentification-module#egg=pypnusershub
- name: Install database
run: |
flask db upgrade taxonomie@head -x local-srid=2154
flask db upgrade ref_geo@head -x local-srid=2154
flask db upgrade nomenclatures_taxonomie@head
flask db autoupgrade
Expand Down
2 changes: 1 addition & 1 deletion dependencies/TaxHub
Submodule TaxHub updated 54 files
+7 −1 .github/workflows/pytest.yml
+1 −1 Dockerfile
+1 −1 VERSION
+14 −6 apptax/app.py
+3 −2 apptax/log/logmanager.py
+65 −0 apptax/migrations/versions/23c25552d707_create_bdc_status_table_if_not_exists.py
+54 −0 apptax/migrations/versions/32c5ed42bdbd_add_table_t_meta_taxref.py
+49 −0 apptax/migrations/versions/33e20a7682b4_check_group3_inpn_vm_function.py
+113 −0 apptax/migrations/versions/3bd542b72955_optimize_vm_taxref_for_autocomplete.py
+70 −0 apptax/migrations/versions/6607b25b2d66_taxref_set_null_to_empty_string.py
+111 −0 apptax/migrations/versions/8f3256f60915_group3_inpn_autocomplete.py
+10 −1 apptax/taxonomie/commands/migrate_taxref/commands_v15.py
+11 −4 apptax/taxonomie/commands/migrate_taxref/commands_v16.py
+22 −0 apptax/taxonomie/commands/migrate_taxref/data/5_clean_db.sql
+2 −2 apptax/taxonomie/commands/migrate_taxref/data/specific_taxref_v15_v16/3.2_alter_taxref_data.sql
+7 −1 apptax/taxonomie/commands/taxref.py
+4 −1 apptax/taxonomie/commands/taxref_v15_v16.py
+88 −47 apptax/taxonomie/commands/utils.py
+16 −2 apptax/taxonomie/models.py
+9 −14 apptax/taxonomie/routesbiblistes.py
+12 −8 apptax/taxonomie/routesbibnoms.py
+114 −64 apptax/taxonomie/routestaxref.py
+4 −6 apptax/taxonomie/routestmedias.py
+39 −32 apptax/tests/fixtures.py
+25 −0 apptax/tests/test_bib_noms.py
+1 −1 apptax/tests/test_media.py
+2 −2 apptax/tests/test_taxhub.py
+155 −2 apptax/tests/test_taxref.py
+4 −6 apptax/tests/test_taxref_last_version.py
+6 −2 apptax/utils/utilssqlalchemy.py
+1 −1 data/scripts/update_taxref/README.rst
+1 −1 data/scripts/update_taxref/apply_changes.sh
+1 −1 data/scripts/update_taxref/clean_db.sh
+2 −2 data/scripts/update_taxref/import_taxref_v11_data.sh
+2 −2 data/scripts/update_taxref/import_taxref_v13_data.sh
+1 −1 data/scripts/update_taxref/import_taxref_v14.sh
+1 −1 dependencies/UsersHub-authentification-module
+1 −1 dependencies/Utils-Flask-SQLAlchemy
+1 −1 dependencies/Utils-Flask-SQLAlchemy-Geo
+15 −5 docs/auteurs.rst
+1,252 −0 docs/changelog.md
+0 −862 docs/changelog.rst
+1 −1 install_app.sh
+1 −1 install_db.sh
+2 −1 requirements-common.in
+1 −1 requirements-dependencies.in
+76 −65 requirements-dev.txt
+71 −59 requirements.txt
+4 −2 setup.py
+1 −1 static/app/app.js
+1 −1 static/app/bib_liste/edit/bibliste-edit-controler.js
+1 −1 static/app/bib_liste/populate/bibliste-populate-controler.js
+1 −1 static/app/bib_nom/edit/bibNom-form-controler.js
+21 −18 static/app/login/loginControler.js
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ sqlalchemy

utils-flask-sqlalchemy>=0.3.0
taxhub>=1.10.0
pypnusershub>=1.6.0
pypnusershub>=2.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-10-04 17:51:48.491261

"""

from alembic import op
import sqlalchemy as sa

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-09-16 14:15:57.784074

"""

import importlib.resources

from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-07-28 14:43:31.883082

"""

from alembic import op
import sqlalchemy as sa

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""add group3_inpn cor_taxref_nomenclature

Revision ID: 803524258bd3
Revises: f5436084bf17
Create Date: 2023-09-04 07:57:35.371378

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "803524258bd3"
down_revision = "f5436084bf17"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
table_name="cor_taxref_nomenclature",
column=sa.Column("group3_inpn", sa.VARCHAR(255), server_default="all"),
schema="ref_nomenclatures",
)
op.execute(
"""ALTER TABLE ref_nomenclatures.cor_taxref_nomenclature
ADD CONSTRAINT check_cor_taxref_nomenclature_isgroup3inpn
CHECK ((taxonomie.check_is_group3inpn((group3_inpn)::text) OR ((group3_inpn)::text = 'all'::text))) NOT VALID
"""
)
with op.batch_alter_table(
table_name="cor_taxref_nomenclature", schema="ref_nomenclatures"
) as batch:
batch.drop_constraint("pk_cor_taxref_nomenclature")
batch.create_primary_key(
constraint_name="pk_cor_taxref_nomenclature",
columns=["id_nomenclature", "regne", "group2_inpn", "group3_inpn"],
)
op.execute("DROP VIEW ref_nomenclatures.v_nomenclature_taxonomie")
op.execute(
"""
CREATE OR REPLACE VIEW ref_nomenclatures.v_nomenclature_taxonomie
AS SELECT tn.id_type,
tn.label_default AS type_label,
tn.definition_default AS type_definition,
tn.label_fr AS type_label_fr,
tn.definition_fr AS type_definition_fr,
tn.label_en AS type_label_en,
tn.definition_en AS type_definition_en,
tn.label_es AS type_label_es,
tn.definition_es AS type_definition_es,
tn.label_de AS type_label_de,
tn.definition_de AS type_definition_de,
tn.label_it AS type_label_it,
tn.definition_it AS type_definition_it,
ctn.regne,
ctn.group2_inpn,
ctn.group3_inpn,
n.id_nomenclature,
n.mnemonique,
n.label_default AS nomenclature_label,
n.definition_default AS nomenclature_definition,
n.label_fr AS nomenclature_label_fr,
n.definition_fr AS nomenclature_definition_fr,
n.label_en AS nomenclature_label_en,
n.definition_en AS nomenclature_definition_en,
n.label_es AS nomenclature_label_es,
n.definition_es AS nomenclature_definition_es,
n.label_de AS nomenclature_label_de,
n.definition_de AS nomenclature_definition_de,
n.label_it AS nomenclature_label_it,
n.definition_it AS nomenclature_definition_it,
n.id_broader,
n.hierarchy
FROM ref_nomenclatures.t_nomenclatures n
JOIN ref_nomenclatures.bib_nomenclatures_types tn ON tn.id_type = n.id_type
JOIN ref_nomenclatures.cor_taxref_nomenclature ctn ON ctn.id_nomenclature = n.id_nomenclature
WHERE n.active = true
ORDER BY tn.id_type, ctn.regne, ctn.group2_inpn, n.id_nomenclature;
"""
)


def downgrade():
with op.batch_alter_table(
table_name="cor_taxref_nomenclature", schema="ref_nomenclatures"
) as batch:
batch.drop_constraint("check_cor_taxref_nomenclature_isgroup3inpn")
batch.drop_constraint("pk_cor_taxref_nomenclature")
batch.create_primary_key(
constraint_name="pk_cor_taxref_nomenclature",
columns=["id_nomenclature", "regne", "group2_inpn"],
)
op.execute("DROP VIEW ref_nomenclatures.v_nomenclature_taxonomie")
op.drop_column("cor_taxref_nomenclature", "group3_inpn", schema="ref_nomenclatures")
op.execute(
"""
CREATE VIEW ref_nomenclatures.v_nomenclature_taxonomie
AS SELECT tn.id_type,
tn.label_default AS type_label,
tn.definition_default AS type_definition,
tn.label_fr AS type_label_fr,
tn.definition_fr AS type_definition_fr,
tn.label_en AS type_label_en,
tn.definition_en AS type_definition_en,
tn.label_es AS type_label_es,
tn.definition_es AS type_definition_es,
tn.label_de AS type_label_de,
tn.definition_de AS type_definition_de,
tn.label_it AS type_label_it,
tn.definition_it AS type_definition_it,
ctn.regne,
ctn.group2_inpn,
n.id_nomenclature,
n.mnemonique,
n.label_default AS nomenclature_label,
n.definition_default AS nomenclature_definition,
n.label_fr AS nomenclature_label_fr,
n.definition_fr AS nomenclature_definition_fr,
n.label_en AS nomenclature_label_en,
n.definition_en AS nomenclature_definition_en,
n.label_es AS nomenclature_label_es,
n.definition_es AS nomenclature_definition_es,
n.label_de AS nomenclature_label_de,
n.definition_de AS nomenclature_definition_de,
n.label_it AS nomenclature_label_it,
n.definition_it AS nomenclature_definition_it,
n.id_broader,
n.hierarchy
FROM ref_nomenclatures.t_nomenclatures n
JOIN ref_nomenclatures.bib_nomenclatures_types tn ON tn.id_type = n.id_type
JOIN ref_nomenclatures.cor_taxref_nomenclature ctn ON ctn.id_nomenclature = n.id_nomenclature
WHERE n.active = true
ORDER BY tn.id_type, ctn.regne, ctn.group2_inpn, n.id_nomenclature;"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Revises:
Create Date: 2021-09-16 15:36:57.784074
"""

import importlib.resources

from alembic import op, context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Revises:
Create Date: 2021-09-16 15:36:57.784074
"""

import importlib.resources

from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-12-10 10:07:09.478526

"""

from alembic import op
import sqlalchemy as sa

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-07-28 15:01:47.927979

"""

from alembic import op
import sqlalchemy as sa

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Create Date: 2021-09-16 15:08:57.784074

"""

import importlib.resources

from alembic import op
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2021-10-06 10:45:42.264034

"""

from alembic import op
import sqlalchemy as sa

Expand Down
2 changes: 2 additions & 0 deletions src/pypnnomenclature/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CorTaxrefNomenclature(db.Model):
)
regne = db.Column(db.Unicode, primary_key=True)
group2_inpn = db.Column(db.Unicode, primary_key=True)
group3_inpn = db.Column(db.Unicode, primary_key=True)


@serializable(
Expand Down Expand Up @@ -166,6 +167,7 @@ class VNomenclatureTaxonomie(db.Model):
type_definition_it = db.Column(db.Unicode)
regne = db.Column(db.Unicode, primary_key=True)
group2_inpn = db.Column(db.Unicode, primary_key=True)
group3_inpn = db.Column(db.Unicode, primary_key=True)
id_nomenclature = db.Column(db.Integer, primary_key=True)
mnemonique = db.Column(db.Unicode)
nomenclature_label = db.Column(db.Unicode)
Expand Down
9 changes: 7 additions & 2 deletions src/pypnnomenclature/repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Méthode permettant de manipuler les objets de la nomenclature
"""

from importlib import import_module
from flask import current_app

Expand All @@ -21,6 +22,7 @@
code_type=None,
regne=None,
group2_inpn=None,
group3_inpn=None,
hierarchy=None,
filter_params=None,
):
Expand Down Expand Up @@ -56,7 +58,10 @@
VNomenclatureTaxonomie.id_nomenclature == TNomenclatures.id_nomenclature,
).where(VNomenclatureTaxonomie.regne.in_(("all", regne)))
if group2_inpn:
q = q.where(VNomenclatureTaxonomie.group2_inpn.in_(("all", group2_inpn)))
q = q.filter(VNomenclatureTaxonomie.group2_inpn.in_(("all", group2_inpn)))
if group3_inpn:
q = q.where(VNomenclatureTaxonomie.group3_inpn.in_(("all", group3_inpn)))

Check warning on line 63 in src/pypnnomenclature/repository.py

View check run for this annotation

Codecov / codecov/patch

src/pypnnomenclature/repository.py#L61-L63

Added lines #L61 - L63 were not covered by tests

if "cd_nomenclature" in filter_params:
q = q.where(TNomenclatures.cd_nomenclature.in_(filter_params.getlist("cd_nomenclature")))
# Ordonnancement
Expand Down Expand Up @@ -146,7 +151,7 @@
]
)
nomenclature_dict["taxref"] = [
tr.as_dict(fields=["regne", "group2_inpn"]) for tr in n.taxref
tr.as_dict(fields=["regne", "group2_inpn", "group3_inpn"]) for tr in n.taxref
]

nomenclatures.append(nomenclature_dict)
Expand Down
6 changes: 6 additions & 0 deletions src/pypnnomenclature/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
"""
regne = request.args.get("regne")
group2inpn = request.args.get("group2_inpn")
group3inpn = request.args.get("group3_inpn")

Check warning on line 27 in src/pypnnomenclature/routes.py

View check run for this annotation

Codecov / codecov/patch

src/pypnnomenclature/routes.py#L27

Added line #L27 was not covered by tests

response = repository.get_nomenclature_list(
**{
"id_type": id_type,
"regne": regne,
"group2_inpn": group2inpn,
"group3_inpn": group3inpn,
"filter_params": request.args,
}
)
Expand All @@ -50,12 +52,14 @@
"""
regne = request.args.get("regne")
group2inpn = request.args.get("group2_inpn")
group3inpn = request.args.get("group3_inpn")

response = repository.get_nomenclature_list(
**{
"code_type": code_type,
"regne": regne,
"group2_inpn": group2inpn,
"group3_inpn": group3inpn,
"filter_params": request.args,
}
)
Expand All @@ -75,6 +79,7 @@
"""
regne = request.args.get("regne")
group2inpn = request.args.get("group2_inpn")
group3inpn = request.args.get("group3_inpn")
types = []
if "id_type" in request.args:
types = request.args.getlist("id_type")
Expand All @@ -90,6 +95,7 @@
param: id_type,
"regne": regne,
"group2_inpn": group2inpn,
"group3_inpn": group3inpn,
"filter_params": request.args,
}
)
Expand Down
Loading