From 5bcf3b2a6309a24b6b1c9a79962ab37364f870eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 2 Aug 2023 19:05:16 +0200 Subject: [PATCH] fix reset_check_constraint_of_placeholders --- ereuse_devicehub/inventory/forms.py | 8 ++--- ..._reset_check_constraint_of_placeholders.py | 35 ++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 6b3a7546..e22e1872 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -521,22 +521,22 @@ class NewDeviceForm(FlaskForm): error = ["Not a correct value"] is_valid = super().validate(extra_validators) - if self.weight.data and not (0.1 <= self.weight.data): + if self.weight.data and not (0.1 <= self.weight.data) or self.weight.data == 0: txt = ["Supported values greater than 0.1"] self.weight.errors = txt is_valid = False - if self.height.data and not (0.1 <= self.height.data): + if self.height.data and not (0.1 <= self.height.data) or self.height.data == 0: txt = ["Supported values greater than 0.1"] self.height.errors = txt is_valid = False - if self.width.data and not (0.1 <= self.width.data): + if self.width.data and not (0.1 <= self.width.data) or self.width.data == 0: txt = ["Supported values greater than 0.1"] self.width.errors = txt is_valid = False - if self.depth.data and not (0.1 <= self.depth.data): + if self.depth.data and not (0.1 <= self.depth.data) or self.depth.data == 0: txt = ["Supported values greater than 0.1"] self.depth.errors = txt is_valid = False diff --git a/ereuse_devicehub/migrations/versions/57e6201f280c_reset_check_constraint_of_placeholders.py b/ereuse_devicehub/migrations/versions/57e6201f280c_reset_check_constraint_of_placeholders.py index ab55de57..d386fa1f 100644 --- a/ereuse_devicehub/migrations/versions/57e6201f280c_reset_check_constraint_of_placeholders.py +++ b/ereuse_devicehub/migrations/versions/57e6201f280c_reset_check_constraint_of_placeholders.py @@ -23,18 +23,29 @@ def get_inv(): def upgrade(): - op.drop_constraint( - 'device_depth_check', "device", type_="check", schema=f'{get_inv()}' - ) - op.drop_constraint( - 'device_height_check', "device", type_="check", schema=f'{get_inv()}' - ) - op.drop_constraint( - 'device_width_check', "device", type_="check", schema=f'{get_inv()}' - ) - op.drop_constraint( - 'device_weight_check', "device", type_="check", schema=f'{get_inv()}' - ) + sql = "select constraint_name from information_schema.table_constraints " + sql += "where table_name='device' and constraint_type='CHECK';" + con = op.get_bind() + constraints = [] + for c in con.execute(sql): + constraints.append(c.constraint_name) + if 'device_depth_check' in constraints: + op.drop_constraint( + 'device_depth_check', "device", type_="check", schema=f'{get_inv()}' + ) + if 'device_height_check' in constraints: + op.drop_constraint( + 'device_height_check', "device", type_="check", schema=f'{get_inv()}' + ) + if 'device_width_check' in constraints: + op.drop_constraint( + 'device_width_check', "device", type_="check", schema=f'{get_inv()}' + ) + if 'device_weight_check' in constraints: + op.drop_constraint( + 'device_weight_check', "device", type_="check", schema=f'{get_inv()}' + ) + op.create_check_constraint( "device_depth_check", "device",