I created this validator and it works except when it raises the invalid
message, because message is displayed in the right side of all fields in
the form.
I would like to display the message only near the field which generates
the error.
How can I do it?
Thank you,
class DateInizioFine(validators.FancyValidator):
def _to_python(self, value, state):
inizio = value.get('data_inizio_attivita')
fine = value.get('data_fine_attivita')
if fine and inizio > fine:
raise validators.Invalid('la data fine non deve essere
maggiore della data inizio!', value, state)
return value
jo
This validator is validating a compound widget so it needs to build
an error dict and attach it to the exception. Gonna paste a validator
I have that does exactly the same thing, but in spanish ;)
class ValidadorFechas(FormValidator):
messages = {
'publica_menor' : 'La fecha de publicacion debe ser menor
que la de '
'despublicacion',
'despublica_mayor' : 'La fecha de despublicacion debe ser
mayor que '
'la de publicacion',
}
def validate_python(self, value, state=None):
pub = value.get('fecha_publica', None)
des = value.get('fecha_despublica', None)
if (pub and des) and pub > des:
message = self.message('publica_menor', state)
errors = dict(
fecha_publica = self.message('publica_menor', state),
fecha_despublica = self.message( 'despublica_mayor',
state),
)
raise Invalid(message, value, state, error_dict=errors)
Alberto
Thank you Alberto, it works fine!
jo