<s> """<STR_LIT>""" <EOL> import floppyforms . __future__ as forms <EOL> from django . core . exceptions import ValidationError <EOL> from moztrap import model <EOL> from moztrap . view . lists import filters <EOL> from moztrap . view . utils import mtforms <EOL> class RunForm ( mtforms . NonFieldErrorsClassFormMixin , mtforms . MTModelForm ) : <EOL> """<STR_LIT>""" <EOL> suites = mtforms . MTMultipleChoiceField ( <EOL> required = False , <EOL> widget = mtforms . FilteredSelectMultiple ( <EOL> choice_template = "<STR_LIT>" , <EOL> listordering_template = ( <EOL> "<STR_LIT>" ) , <EOL> filters = [ <EOL> filters . KeywordFilter ( "<STR_LIT:name>" ) , <EOL> filters . ModelFilter ( <EOL> "<STR_LIT>" , queryset = model . User . objects . all ( ) ) , <EOL> ] , <EOL> ) <EOL> ) <EOL> productversion = mtforms . MTModelChoiceField ( <EOL> queryset = model . ProductVersion . objects . all ( ) , <EOL> choice_attrs = mtforms . product_id_attrs , <EOL> ) <EOL> build = forms . CharField ( max_length = <NUM_LIT:200> , required = False ) <EOL> is_series = forms . BooleanField ( required = False ) <EOL> class Meta : <EOL> model = model . Run <EOL> fields = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:name>" , <EOL> "<STR_LIT:description>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:start>" , <EOL> "<STR_LIT:end>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> widgets = { <EOL> "<STR_LIT:name>" : forms . TextInput , <EOL> "<STR_LIT:description>" : mtforms . BareTextarea , <EOL> "<STR_LIT>" : forms . TextInput , <EOL> "<STR_LIT>" : forms . CheckboxInput , <EOL> "<STR_LIT:start>" : forms . DateInput , <EOL> "<STR_LIT:end>" : forms . DateInput , <EOL> } <EOL> def clean_suites ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> suites = dict ( ( unicode ( x . id ) , x ) for x in <EOL> model . Suite . objects . filter ( pk__in = self . cleaned_data [ "<STR_LIT>" ] ) ) <EOL> try : <EOL> return [ suites [ x ] for x in self . cleaned_data [ "<STR_LIT>" ] ] <EOL> except KeyError as e : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> if "<STR_LIT>" in self . changed_data : <EOL> self . changed_data . remove ( "<STR_LIT>" ) <EOL> return None <EOL> def clean_build ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cleaned_data [ "<STR_LIT>" ] : <EOL> return None <EOL> def save ( self , user = None ) : <EOL> """<STR_LIT>""" <EOL> user = user or self . user <EOL> run = super ( RunForm , self ) . save ( user = user ) <EOL> if "<STR_LIT>" in self . changed_data : <EOL> run . runsuites . all ( ) . delete ( permanent = True ) <EOL> for i , suite in enumerate ( self . cleaned_data [ "<STR_LIT>" ] ) : <EOL> model . RunSuite . objects . create ( <EOL> run = run , suite = suite , order = i , user = user ) <EOL> return run <EOL> class AddRunForm ( RunForm ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( AddRunForm , self ) . __init__ ( * args , ** kwargs ) <EOL> isf = self . fields [ "<STR_LIT>" ] <EOL> isf . initial = True <EOL> class EditRunForm ( RunForm ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( EditRunForm , self ) . __init__ ( * args , ** kwargs ) <EOL> pvf = self . fields [ "<STR_LIT>" ] <EOL> sf = self . fields [ "<STR_LIT>" ] <EOL> isf = self . fields [ "<STR_LIT>" ] <EOL> self . initial [ "<STR_LIT>" ] = list ( <EOL> self . instance . suites . values_list ( <EOL> "<STR_LIT:name>" , flat = True ) . order_by ( "<STR_LIT>" ) ) <EOL> if self . instance . status == model . Run . STATUS . active : <EOL> pvf . queryset = pvf . queryset . filter ( <EOL> pk = self . instance . productversion_id ) <EOL> pvf . readonly = True <EOL> isf . readonly = True <EOL> sf . readonly = True <EOL> else : <EOL> pvf . queryset = pvf . queryset . filter ( <EOL> product = self . instance . productversion . product_id ) </s>
