<s> from __future__ import unicode_literals <EOL> import warnings <EOL> from wtforms import ValidationError <EOL> from sqlalchemy . orm . exc import NoResultFound <EOL> class Unique ( object ) : <EOL> """<STR_LIT>""" <EOL> field_flags = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , get_session , model , column , message = None ) : <EOL> warnings . warn ( '<STR_LIT>' , DeprecationWarning ) <EOL> self . get_session = get_session <EOL> self . model = model <EOL> self . column = column <EOL> self . message = message <EOL> def __call__ ( self , form , field ) : <EOL> try : <EOL> obj = self . get_session ( ) . query ( self . model ) . filter ( self . column == field . data ) . one ( ) <EOL> if not hasattr ( form , '<STR_LIT>' ) or not form . _obj == obj : <EOL> if self . message is None : <EOL> self . message = field . gettext ( '<STR_LIT>' ) <EOL> raise ValidationError ( self . message ) <EOL> except NoResultFound : <EOL> pass </s>
