Adrian Holovaty wrote:
> Yeah, it doesn't get called on save() yet. It's not really intended
> for general use, because only a few of the Field classes have the
> validation method implemented. Help coding this up would be *much*
> appreciated!
I'll will try to help if I can.
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.
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.
Anything else?
> That should indeed work.
Great!!! This type of validation is just what I expect in the best Python ORM
;).
--
Nebojša Đorđević - nesh
Studio Quattro - Niš - SCG
http://studioquattro.biz/
http://djnesh.blogspot.com/ | http://djnesh-django.blogspot.com/ |
http://djangoutils.python-hosting.com/
Registered Linux User 282159 [http://counter.li.org]
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---