def __call__(self, form, field):
        # print('Form data, retornado dentro de NumericCheck en {}:\n{}\n'.format(field,form.data))
        data_required = DataRequired('Campo requerido')

        def numeric_check(field):
            if field.name == 'qty':
                # print('Cantidad: {}| isdecimal(): {}'.format(field.data, field.data.isdecimal()))
                if not field.data.isdecimal():
                    raise StopValidation("Ingrese un valor numérico entero")

            if field.name == 'price':
                try:
                    a = float(field.data)
                    if a <= 0:
                        raise StopValidation("Ingrese un precio válido")
                except Exception as e:
                    print(e)
                    raise StopValidation("Ingrese un precio válido")

        if form.data['create_button']:
            # print('Validando desde el botón CREAR')

            numeric_check(field)

            if field.name in ('product_name', 'price', 'qty'):
                return data_required.__call__(form, field)

        elif form.data['update_button']:
            # print('Validando desde el botón ACTUALIZAR')
            if field.name == 'ref_number':
                return data_required.__call__(form, field)

            if (field.name in ('qty', 'price')) and (field.data != ""):
                # print('Validando el campo {}\n'.format(field.name))
                numeric_check(field)
Exemple #2
0
 def __call__(self, form, field):
     for name, data in self.conditions.items():
         other_field = form[name]
         if other_field is None:
             raise Exception('no field named "%s" in form' % name)
         if other_field.data == data and not field.data:
             DataRequired.__call__(self, form, field)
         Optional()(form, field)
Exemple #3
0
 def __call__(self, form, field):
     for name, data in self.conditions.items():
         other_field = form[name]
         if other_field is None:
             raise ValidationError("Preencha o campo.")
         if other_field.data == data and not field.data:
             DataRequired.__call__(self, form, field)
         Optional()(form, field)
 def __call__(self, form, test_field):
     for name, data in self.conditions.items():
         iter_field = form[name]
         if iter_field is None:
             raise Exception('no field named "{}"'.format(name))
         if iter_field.data == data and not test_field.data:
             DataRequired.__call__(self, form, test_field)
         Optional()(form, test_field)