On 3/28/06, Neboj¹a Ðorðeviæ <[EMAIL PROTECTED]> wrote:
> Currently implemented validate() methods (in EmailField, IPAddressField and 
> PhoneNumberField) just call
> validators.isValidFOO(field_data, all_data) and, for example, validate method 
> for PositiveIntegerField will look
> something like this:
>
>     def validate(self, field_data, all_data):
>         if i < 0:
>                 raise ValidationError, gettext("Positive numbers only!")
>
> Fromdocstring in Field.validate() I can assume that field_data is already 
> converted to int and that validate() will not
> be called if field_data is invalid integer.

Each field type is responsible for two types of validation -- type
coercion (in the to_python() method) and actual validation (in the
validate() method) -- so the implementation depends on the field.

> I take a (very) fast look at the code and here is a list of the fields that 
> requires validate method (IMHO), for other
> fields to_python is already performed some type of validation (i.e. 
> IntegerField):
>
>  * CharField - check if maxlength is not exceeded
>  * CommaSeparatedIntegerField - check format (\d+,)+
>  * FloatField - check max_digits?
>  * ImageField - check image dimensions if given
>  * PositiveIntegerField/PositiveSmallIntegerField - assert that field_data >= > 0
>  * SlugField - check that field_data conforms to slug format ([a-z]_\-)+
>  * URLField - check that field_data points to a valid URL
>  * USStateField - ??
>  * XMLField - probably validate against Relax NG compact schema?
>  * ForeignKey - check if given id exist in related table (or to_python is 
> already checked that while converting?)
>  * OneToOneField - check that no other field has same id
>  * ManyToManyField - like ForeignKey, but for all records in related table
>
> This applies to all fields:
>  * validate_full will take care of blank fields, but how about NOT NULL 
> fields?
>  * check uniqueness for the fields with unique=True and also for the 
> unique_for_FOO?
>  * finally run through the validator_list to perform user requested 
> validation?
>
> Lot's of this functionality is already implemented with existing validators 
> so validate() method will first call
> appropriate function/class from validators.py and then perform any additional 
> validation.

That's pretty much it. Let me know if you decide to take this on...We
should coordinate which fields we're taking.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" 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/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to