Skip to content

Commit

Permalink
Improve check_depths, when only depth_min or depth_max in fields
Browse files Browse the repository at this point in the history
Signed-off-by: VincentCauchois <vincent.cauchois@mnhn.fr>
  • Loading branch information
VincentCauchois committed May 4, 2023
1 parent 65d88ec commit de8cdf5
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions backend/gn_module_import/checks/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,31 +485,35 @@ def check_altitudes(imprt, fields):


def check_depths(imprt, fields):
if "depth_min" not in fields or "depth_max" not in fields:
return
depth_min_field = fields["depth_min"]
depth_max_field = fields["depth_max"]
depth_min_synthese_field = getattr(ImportSyntheseData, depth_min_field.synthese_field)
depth_max_synthese_field = getattr(ImportSyntheseData, depth_max_field.synthese_field)
if "depth_min" in fields:
depth_min_field = fields["depth_min"]
depth_min_name_field = depth_min_field.name_field
depth_min_synthese_field = getattr(ImportSyntheseData, depth_min_field.synthese_field)
report_erroneous_rows(
imprt,
error_type="INVALID_INTEGER",
error_column=depth_min_name_field,
whereclause=(depth_min_synthese_field < 0),
)

report_erroneous_rows(
imprt,
error_type="DEPTH_MIN_SUP_ALTI_MAX", # Yes, there is a typo in db...
error_column=depth_min_field.name_field,
whereclause=(depth_min_synthese_field > depth_max_synthese_field),
)
report_erroneous_rows(
imprt,
error_type="INVALID_INTEGER",
error_column=depth_min_field.name_field,
whereclause=(depth_min_synthese_field < 0),
)
report_erroneous_rows(
imprt,
error_type="INVALID_INTEGER",
error_column=depth_max_field.name_field,
whereclause=(depth_max_synthese_field < 0),
)
if "depth_max" in fields:
depth_max_field = fields["depth_max"]
depth_max_name_field = depth_max_field.name_field
depth_max_synthese_field = getattr(ImportSyntheseData, depth_max_field.synthese_field)
report_erroneous_rows(
imprt,
error_type="INVALID_INTEGER",
error_column=depth_max_name_field,
whereclause=(depth_max_synthese_field < 0),
)

if "depth_min" in fields and "depth_max" in fields:
report_erroneous_rows(
imprt,
error_type="DEPTH_MIN_SUP_ALTI_MAX", # Yes, there is a typo in db... Should be "DEPTH_MIN_SUP_DEPTH_MAX"
error_column=depth_min_name_field,
whereclause=(depth_min_synthese_field > depth_max_synthese_field),
)


def check_digital_proof_urls(imprt, fields):
Expand Down

0 comments on commit de8cdf5

Please # to comment.