﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
268	Patch: new validator that validates one of many validators	hugo <gb@…>	Adrian Holovaty	"Sometimes one needs to support different formats in a field and for each format there is already a validator. This validator would allow to just say that one of many validators is sufficient for correct data:

{{{
class ANY:
    """"""
    This validator tries all validators. If any one of them succeeds,
    the validator returns. If none of them succeeds, the given message
    is thrown as a validation error. The message is rather unspecific,
    so it's best to give a specific one on instantiation. always_test
    is propagated from the enclosed validators by setting it if any one
    of them contains a always_test attribute.
    """"""
    def __init__(self, validator_list=[], error_message=""This field should conform to one of several formats""):
        self.validator_list = validator_list
        self.error_message = error_message
        for v in validator_list:
            if hasattr(v, 'always_test'):
                self.always_test = True

    def __call__(self, field_data, all_data):
        for v in self.validator_list:
            try:
                v(field_data, all_data)
                return
            except validators.ValidationError, e:
                pass
        raise validators.ValidationError(self.error_message)
}}}
"	enhancement	closed	contrib.admin		normal	fixed			Unreviewed	0	0	0	0	0	0
