<s> from django import forms <EOL> from django . forms import fields <EOL> from django . core . validators import validate_email <EOL> from . widgets import AutocompleteTextarea <EOL> class CSVListField ( fields . CharField ) : <EOL> """<STR_LIT>""" <EOL> def to_python ( self , value ) : <EOL> if isinstance ( value , list ) : <EOL> return "<STR_LIT:U+002CU+0020>" . join ( value ) <EOL> return [ v . strip ( ) for v in value . split ( '<STR_LIT:U+002C>' ) ] <EOL> def prepare_value ( self , value ) : <EOL> if isinstance ( value , list ) : <EOL> return "<STR_LIT:U+002CU+0020>" . join ( value ) <EOL> return value <EOL> class MultiCharField ( forms . Field ) : <EOL> """<STR_LIT>""" <EOL> widget = AutocompleteTextarea <EOL> def __init__ ( self , initial = None , choices = ( ) , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if initial : <EOL> initial = '<STR_LIT:U+002CU+0020>' . join ( initial ) <EOL> super ( MultiCharField , self ) . __init__ ( initial = initial , * args , ** kwargs ) <EOL> self . choices = choices <EOL> def _get_choices ( self ) : <EOL> return self . _choices <EOL> def _set_choices ( self , value ) : <EOL> self . _choices = self . widget . choices = value <EOL> choices = property ( _get_choices , _set_choices ) <EOL> def to_python ( self , value ) : <EOL> if not value : <EOL> return [ ] <EOL> return [ val . strip ( ) for val in value . split ( '<STR_LIT:U+002C>' ) if val . strip ( ) ] <EOL> def run_validators ( self , value ) : <EOL> for val in value : <EOL> if val not in self . choices : <EOL> super ( MultiCharField , self ) . run_validators ( val ) <EOL> class MultiEmailField ( MultiCharField ) : <EOL> """<STR_LIT>""" <EOL> default_validators = [ validate_email ] <EOL> default_error_messages = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } </s>
