<s> from djangae . forms . fields import TrueOrNullFormField <EOL> from djangae . core import validators <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from google . appengine . api . datastore_types import _MAX_STRING_LENGTH <EOL> from . iterable import * <EOL> from . related import * <EOL> from . computed import * <EOL> from . json import * <EOL> from . counting import * <EOL> class TrueOrNullField ( models . NullBooleanField ) : <EOL> """<STR_LIT>""" <EOL> default_error_messages = { <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> } <EOL> description = _ ( "<STR_LIT>" ) <EOL> def from_db_value ( self , value , expression , connection , context ) : <EOL> return self . to_python ( value ) <EOL> def to_python ( self , value ) : <EOL> if value in ( None , '<STR_LIT:None>' , False ) : <EOL> return None <EOL> if value in ( True , '<STR_LIT:t>' , '<STR_LIT:True>' , '<STR_LIT:1>' ) : <EOL> return True <EOL> msg = self . error_messages [ '<STR_LIT>' ] % str ( value ) <EOL> raise ValidationError ( msg ) <EOL> def get_prep_value ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value in ( None , False , '<STR_LIT>' , <NUM_LIT:0> ) : <EOL> return None <EOL> return True <EOL> def formfield ( self , ** kwargs ) : <EOL> defaults = { <EOL> '<STR_LIT>' : TrueOrNullFormField <EOL> } <EOL> defaults . update ( kwargs ) <EOL> return super ( TrueOrNullField , self ) . formfield ( ** defaults ) <EOL> class CharField ( models . CharField ) : <EOL> def __init__ ( self , max_length = _MAX_STRING_LENGTH , * args , ** kwargs ) : <EOL> assert max_length <= _MAX_STRING_LENGTH , "<STR_LIT>" % ( self . __class__ . __name__ , _MAX_STRING_LENGTH ) <EOL> super ( CharField , self ) . __init__ ( max_length = max_length , * args , ** kwargs ) <EOL> self . validators = [ validators . MaxBytesValidator ( limit_value = max_length ) ] </s>
