Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Helper for making form validators skippable

Project description

Motivation

While working on the EuroPython 2014 website we ran into a situation where we had a field validator that was rather expensive to evaluate.

Sadly, the validators-attribute on a model/form field is always evaluated as a whole (meaning each validator in that list is executed no matter if a previous one errored out already). So, we wanted to have a way to mark certain validators as not to be executed in case the field was being marked as invalid anyway.

We still wanted to use the field validator API simply because it keeps everything easily testible, though.

How to use

from django.db import models

from validatorchain import ValidatorChain

from .validators import a_cheap_validator
from .validators import another_cheap_validator
from .validators import an_expensive_validator


class SomeModel(models.Model):
    field = models.CharField(
        max_length=100,
        validators=ValidatorChain()
            .add(a_cheap_validator)
            .add(an_expensive_validator, skip_on_error=True)
            .add(another_cheap_validator)
        )

This way an_expensive_validator will not be executed if a_cheap_validator already raised an exception, while another_cheap_validator will be executed again.

Project details


Release history Release notifications

This version
History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-validatorchain-0.1.tar.gz (2.0 kB) Copy SHA256 hash SHA256 Source None Feb 9, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page