Thanks for the enlightenment - seems I had some misconceptions about
how validators work. Based on this misconceptions I designed some tests
which somehow worked but not as I liked - hence my posting. My crude
first cut was like this:

# ripped out of django/db/models/base.py
def validate(instance):
    error_dict = {}
    invalid_python = {}
    for f in instance._meta.fields:
        try:
            setattr(instance, f.attname, f.to_python(getattr(instance,
f.attname, f.get_default())))
        except ValidationError, e:
            error_dict[f.name] = e.messages
            invalid_python[f.name] = 1
    for f in instance._meta.fields:
        if f.name in invalid_python:
            continue
        errors = f.validate_full(getattr(instance, f.attname,
f.get_default()), instance.__dict__)
        for v in f.validator_list:
            try:
                v(getattr(instance, f.attname, f.get_default()),
instance.__dict__)
            except ValidationError, e:
                errors = e.messages
        if errors:
            error_dict[f.name] = errors
    return error_dict

class TestSanityChecks(unittest.TestCase):
    def test_saneweight(self):
        product = Product.objects.create(artnr='40003', name='Test',
package_weight='320', ve1_weight='232')
        errors = validate(product)
        self.assertEqual(errors['ve1_weight'], ['Das VE1 Gewicht darf
nicht kleiner als das Produktpaketgewicht sein.'])

This worked to a certain degree but resulted in all find of odd effects
because  the 'data string and all_data dictionary' the validators where
seeing different data when being called this way than when they would
be called by a form validator.

Now I'll try to rework this into something more realistic based on
Malcom's comments


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to