#NEWLINE# def save( self ) : #NEWLINE# #INDENT# 'Create and return the new case(s) and version(s).' #NEWLINE# assert self . is_valid ( ) #NEWLINE# product = self . cleaned_data [ 'product' ] #NEWLINE# idprefix = self . cleaned_data [ 'idprefix' ] #NEWLINE# priority = self . cleaned_data [ 'priority' ] #NEWLINE# try : #NEWLINE# #INDENT# int ( priority ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# priority = None #NEWLINE# #UNINDENT# self . save_new_tags ( product ) #NEWLINE# productversions = [ self . cleaned_data [ 'productversion' ] ] #NEWLINE# if self . cleaned_data . get ( 'and_later_versions' ) : #NEWLINE# #INDENT# productversions . extend ( product . versions . filter ( order__gt = productversions [ 0 ] . order ) ) #NEWLINE# #UNINDENT# suite = self . cleaned_data . get ( 'suite' ) #NEWLINE# cases = [ ] #NEWLINE# order = 0 #NEWLINE# if suite : #NEWLINE# #INDENT# order = ( model . SuiteCase . objects . filter ( suite = suite ) . aggregate ( Max ( 'order' ) ) [ 'order__max' ] or 0 ) #NEWLINE# #UNINDENT# for case_data in self . cleaned_data [ 'cases' ] : #NEWLINE# #INDENT# case = model . Case . objects . create ( product = product , user = self . user , idprefix = self , priority = priority ) #NEWLINE# version_kwargs = case_data . copy ( ) #NEWLINE# steps_data = version_kwargs . pop ( 'steps' ) #NEWLINE# version_kwargs [ 'case' ] = case #NEWLINE# version_kwargs [ 'status' ] = self . cleaned_data [ 'status' ] #NEWLINE# version_kwargs [ 'user' ] = self . user #NEWLINE# if suite : #NEWLINE# #INDENT# order += 1 #NEWLINE# model . SuiteCase . objects . create ( case = case , suite = suite , user = self . user , order = order ) #NEWLINE# #UNINDENT# for productversion in productversions : #NEWLINE# #INDENT# this_version_kwargs = version_kwargs . copy ( ) #NEWLINE# this_version_kwargs [ 'productversion' ] = productversion #NEWLINE# caseversion = model . CaseVersion . objects . create ( ** this_version_kwargs ) #NEWLINE# for ( i , step_kwargs ) in enumerate ( steps_data , 1 ) : #NEWLINE# #INDENT# model . CaseStep . objects . create ( user = self . user , caseversion = caseversion , number = i , ** step_kwargs ) #NEWLINE# #UNINDENT# self . save_tags ( caseversion ) #NEWLINE# #UNINDENT# cases . append ( case ) #NEWLINE# #UNINDENT# return cases