Skip to content

Commit

Permalink
feat(import): add coresponding entity to import errors
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Feb 16, 2024
1 parent c2e427b commit 6c76bb8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/geonature/core/imports/checks/dataframe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def report_error(imprt, entity, df, error):
{
"id_import": imprt.id_import,
"id_error": error_type.pk,
"id_entity": entity.id_entity,
"column_error": column,
"id_rows": ordered_invalid_rows,
"comment": error.get("comment"),
Expand Down
2 changes: 2 additions & 0 deletions backend/geonature/core/imports/checks/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def report_erroneous_rows(imprt, entity, error_type, error_column, whereclause):
error = select(
literal(imprt.id_import).label("id_import"),
literal(error_type.pk).label("id_type"),
literal(entity.id_entity).label("id_entity"),
array_agg(
aggregate_order_by(cte.c.line_no, cte.c.line_no),
).label("rows"),
Expand All @@ -81,6 +82,7 @@ def report_erroneous_rows(imprt, entity, error_type, error_column, whereclause):
names=[
ImportUserError.id_import,
ImportUserError.id_type,
ImportUserError.id_entity,
ImportUserError.rows,
ImportUserError.column,
],
Expand Down
7 changes: 6 additions & 1 deletion backend/geonature/core/imports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ class ImportUserError(db.Model):
type = db.relationship("ImportUserErrorType")
column = db.Column("column_error", db.Unicode)
rows = db.Column("id_rows", db.ARRAY(db.Integer))
comment = db.Column(db.UnicodeText)
comment = db.Column(db.UnicodeText),
id_entity = db.Column(
db.Integer,
db.ForeignKey("gn_imports.bib_entities.id_entity", onupdate="CASCADE", ondelete="CASCADE"),
)
entity = db.relationship("Entity")

def __str__(self):
return f"<ImportError import={self.id_import},type={self.type.name},rows={self.rows}>"
Expand Down
4 changes: 2 additions & 2 deletions backend/geonature/core/imports/routes/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def get_import_errors(scope, imprt):
"""
if not imprt.has_instance_permission(scope):
raise Forbidden
return jsonify([error.as_dict(fields=["type"]) for error in imprt.errors])
return jsonify([error.as_dict(fields=["type", "entity"]) for error in imprt.errors])


@blueprint.route("/<destination>/imports/<int:import_id>/source_file", methods=["GET"])
Expand Down Expand Up @@ -644,7 +644,7 @@ def export_pdf(scope, imprt):
"""
if not imprt.has_instance_permission(scope):
raise Forbidden
ctx = imprt.as_dict(fields=["errors", "errors.type", "dataset.dataset_name"])
ctx = imprt.as_dict(fields=["errors", "errors.type", "errors.entity", "dataset.dataset_name"])

ctx["map"] = request.form.get("map")
ctx["chart"] = request.form.get("chart")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ <h5 class="zone-geographique">Zone géographique</h5>
<th class="main-color">Type d'erreur</th>
<th class="main-color">Champ</th>
<th class="main-color">Nombre d'erreur(s)</th>
<th class="main-color">Entité</th>
</tr>
</thead>
<tbody>
Expand All @@ -146,6 +147,7 @@ <h5 class="zone-geographique">Zone géographique</h5>
<td>{{ error.type.description }}</td>
<td>{{ error.column }}</td>
<td>{{ error.rows | length }}</td>
<td>{{ error.entity.label }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Add id_entity in users errors
Revision ID: bfc90691737d
Revises: 2b0b3bd0248c
Create Date: 2024-02-15 16:20:57.049889
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'bfc90691737d'
down_revision = '2b0b3bd0248c'
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
schema="gn_imports",
table_name="t_user_errors",
column=sa.Column(
"id_entity",
sa.Integer,
),
)
op.create_foreign_key(
constraint_name="t_user_errors_id_entity_fkey",
source_schema="gn_imports",
source_table="t_user_errors",
local_cols=["id_entity"],
referent_schema="gn_imports",
referent_table="bib_entities",
remote_cols=["id_entity"],
onupdate="CASCADE",
ondelete="CASCADE",
)
pass


def downgrade():
op.drop_constraint(
schema="gn_imports",
table_name="t_user_errors",
constraint_name="t_user_errors_id_entity_fkey",
)
op.drop_column(
schema="gn_imports",
table_name="t_user_errors",
column_name="id_entity"
)
pass
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3 class="underlined" *ngIf="importErrors"> Erreurs</h3>
<th>Champ </th>
<th>Description erreur</th>
<th>Nombre d'erreur(s)</th>
<th>Numéro des lignes en erreur </th>
<th>Entité</th>
</tr>
</thead>
<tbody>
Expand All @@ -44,6 +44,7 @@ <h3 class="underlined" *ngIf="importErrors"> Erreurs</h3>
<td> {{error.type.description}} <i *ngIf="error.comment"> <br> {{error.comment}} </i> </td>
<td> {{error.rows.length || ''}} </td>
<td> {{error.rows.join(', ')}} </td>
<td> {{error.entity.label}} </td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ <h6>{{ importErrors.length }} erreur(s)</h6>
<th>Description erreur</th>
<th>Nombre d'erreur(s)</th>
<th>Numéro des lignes en erreur</th>
<th>Entité</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -197,6 +198,9 @@ <h6>{{ importErrors.length }} erreur(s)</h6>
</button>
</span>
</td>
<td>
{{ error.entity.label }}
</td>
</tr>
</tbody>
</table>
Expand All @@ -215,6 +219,7 @@ <h6>{{ importWarnings.length }} alerte(s)</h6>
<th>Description erreur</th>
<th>Nombre d'erreur(s)</th>
<th>Numéro des lignes en erreur</th>
<th>Entité</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -245,6 +250,9 @@ <h6>{{ importWarnings.length }} alerte(s)</h6>
</button>
</span>
</td>
<td>
{{ error.entity.label }}
</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 6c76bb8

Please sign in to comment.