<s> import os . path <EOL> import wtforms <EOL> from flask . ext import wtf <EOL> from kozmic . models import TrackedFile <EOL> required = wtforms . validators . Required ( ) <EOL> optional = wtforms . validators . Optional ( ) <EOL> class TrackedFilesField ( wtforms . TextAreaField ) : <EOL> def process_data ( self , value ) : <EOL> if value : <EOL> value = '<STR_LIT:\n>' . join ( tracked_file . path for tracked_file in value ) <EOL> return super ( TrackedFilesField , self ) . process_data ( value ) <EOL> def process_formdata ( self , valuelist ) : <EOL> assert len ( valuelist ) == <NUM_LIT:1> <EOL> value = valuelist . pop ( ) <EOL> if value : <EOL> paths = set ( os . path . relpath ( path , start = '<STR_LIT:.>' ) <EOL> for path in value . splitlines ( ) if path ) <EOL> value = [ TrackedFile ( path = path ) for path in paths ] <EOL> valuelist . append ( value ) <EOL> return super ( TrackedFilesField , self ) . process_formdata ( valuelist ) <EOL> def populate_obj ( self , obj , name ) : <EOL> getattr ( obj , name ) . delete ( ) <EOL> setattr ( obj , name , self . data ) <EOL> class UnixEndingsTextAreaField ( wtforms . TextAreaField ) : <EOL> def process_formdata ( self , valuelist ) : <EOL> valuelist = [ '<STR_LIT:\n>' . join ( value . splitlines ( ) ) for value in valuelist ] <EOL> return super ( UnixEndingsTextAreaField , self ) . process_formdata ( valuelist ) <EOL> class HookForm ( wtf . Form ) : <EOL> title = wtforms . TextField ( '<STR_LIT>' , [ required ] ) <EOL> install_script = UnixEndingsTextAreaField ( <EOL> '<STR_LIT>' , [ optional ] ) <EOL> tracked_files = TrackedFilesField ( <EOL> '<STR_LIT>' , [ optional ] ) <EOL> build_script = UnixEndingsTextAreaField ( <EOL> '<STR_LIT>' , [ required ] , <EOL> default = '<STR_LIT>' ) <EOL> docker_image = wtforms . TextField ( <EOL> '<STR_LIT>' , [ required ] , <EOL> default = '<STR_LIT>' ) <EOL> submit = wtforms . SubmitField ( '<STR_LIT>' ) <EOL> class MemberForm ( wtf . Form ) : <EOL> gh_login = wtforms . TextField ( '<STR_LIT>' , [ required ] ) <EOL> is_manager = wtforms . BooleanField ( <EOL> '<STR_LIT>' , [ wtforms . validators . NumberRange ( <NUM_LIT:0> , <NUM_LIT:1> ) ] ) <EOL> submit = wtforms . SubmitField ( '<STR_LIT>' ) </s>
