File: validators.py

package info (click to toggle)
sprox 0.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 508 kB
  • sloc: python: 3,235; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 686 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
validators Module

Copyright (c) 2008 Christopher Perkins
Original Version by Christopher Perkins 2008
Released under MIT license.
"""
from formencode import FancyValidator, Invalid

class UniqueValue(FancyValidator):
    def __init__(self, provider, entity, field_name, *args, **kw):
        self.provider = provider
        self.entity   = entity
        self.field_name    = field_name
        FancyValidator.__init__(self, *args, **kw)

    def _to_python(self, value, state):
        if not self.provider.is_unique(self.entity, self.field_name, value):
            raise Invalid(
                'That value already exists',
                value, state)
        return value