Ticket #2535: manipulator_validators.diff

File manipulator_validators.diff, 1.5 KB (added by Tom Tobin <korpios@…>, 18 years ago)

Implements manipulator-aware validators in post-MR.

  • Users/korpios/checkouts/django/trunk/django/db/models/fields/__init__.py

     
    77from django.utils.functional import curry
    88from django.utils.text import capfirst
    99from django.utils.translation import gettext, gettext_lazy
    10 import datetime, os, time
     10import datetime, os, time, inspect
    1111
    1212class NOT_PROVIDED:
    1313    pass
     
    225225        """
    226226        field_objs, params = self.prepare_field_objs_and_params(manipulator, name_prefix)
    227227
     228        # Curry validators that require the manipulator passed in.
     229        for i, validator in enumerate(params['validator_list']):
     230            assert callable(validator), "Validator not callable: %r" % validator
     231            if inspect.isfunction(validator):
     232                wrap = len(inspect.getargspec(validator)[0]) == 3
     233            elif inspect.ismethod(validator):
     234                wrap = len(inspect.getargspec(validator)[0]) == 4
     235            else:
     236                wrap = len(inspect.getargspec(validator.__call__)[0]) == 4
     237            if wrap:               
     238                params['validator_list'][i] = curry(validator, manipulator)
     239
    228240        # Add the "unique" validator(s).
    229241        for field_name_list in opts.unique_together:
    230242            if field_name_list[0] == self.name:
Back to Top