Werner schrieb:
> Question #1:

Does it work if you set the validator explicitely?

widgets.SingleSelectField(
     name='user', label='Users', options=mylist, default=0,
     validator=validators.Int)

> #Question #2

Use a chained validator:

class MySchema(validators.Schema):
     """Validator schema for offer search form."""
     ...
     start = validators.All(
         validators.DateValidator(today_or_after=True),
         validators.DateTimeConverter(format=my_date_format))
     end = validators.All(
         validators.DateValidator(today_or_after=True),
         validators.DateTimeConverter(format=my_date_format))
     ...
     chained_validators = [DatesOrdered('start', 'end')]

class DatesOrdered(validators.FieldsMatch):
     """Tests that the dates in the given fields are ordered.

     Useful for testing if start dates are not later than end dates.
     Pass the list of field names in as 'field_names'.

     """

     messages = {
         'invalidNotOrdered': _("Date should be later")
     }

     date_validator = validators.All(
         validators.DateValidator(today_or_after=True),
         validators.DateTimeConverter(format=date_format))

     def to_date(self, value):
         try:
             return (value
                 and self.date_validator.to_python(value) or None)
         except validators.Invalid:
             return None

     def validate_python(self, field_dict, state):
         last = self.to_date(field_dict[self.field_names[0]])
         errors = {}
         for name in self.field_names[1:]:
             current = self.to_date(field_dict.get(name))
             if current is None or last is None:
                 continue
             if current < last:
                 errors[name] = self.message('invalidNotOrdered', state)
         if errors:
             error_list = sorted(errors.iteritems())
             error_message = '<br>\n'.join(
                 ['%s: %s' % (name, value)
                     for name, value in error_list])
             raise validators.Invalid(error_message,
                 field_dict, state, error_dict=errors)

Hope this helps.

-- Christoph


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to