@@ -242,7 +242,7 @@ class CustomerRequest(colander.Schema):
242
242
customer_request = CustomerRequest (title = '' )
243
243
244
244
245
- class Contracts (colander .SequenceSchema ):
245
+ class CRperContracts (colander .MappingSchema ):
246
246
class Contract (colander .Schema ):
247
247
name = SchemaNode (typ = colander .String (),
248
248
widget = TextInputWidget (placeholder = u'Contract name' ),
@@ -270,6 +270,7 @@ class Contract(colander.Schema):
270
270
missing = None ,
271
271
title = u'End date' )
272
272
273
+ customer_requests = CustomerRequests ()
273
274
contract = Contract (name = '' ,)
274
275
275
276
@@ -279,8 +280,7 @@ class WizardSchema(colander.Schema):
279
280
users = UsersSchema ()
280
281
new_users = NewUsersSchema ()
281
282
milestones = Milestones ()
282
- customer_requests = CustomerRequests ()
283
- contracts = Contracts ()
283
+ contracts = CRperContracts ()
284
284
285
285
286
286
class Wizard (object ):
@@ -318,7 +318,8 @@ def render(self):
318
318
[(str (role .id ), role .name ) for role in roles ]
319
319
320
320
form ['milestones' ].widget = SequenceWidget (min_len = 1 )
321
- form ['customer_requests' ].widget = SequenceWidget (min_len = 2 )
321
+ form ['contracts' ].title = ''
322
+ form ['contracts' ]['customer_requests' ].widget = SequenceWidget (min_len = 2 )
322
323
323
324
controls = self .request .POST .items ()
324
325
if controls != []:
@@ -329,26 +330,19 @@ def render(self):
329
330
result ['form' ] = e .render ()
330
331
return result
331
332
332
- appstruct = {'customer_requests' : [{ 'ticket' : True ,
333
- 'title' : u'Analisi' },
334
- {'ticket' : True ,
335
- 'title' : u'Supporto' }]
336
- }
337
-
333
+ appstruct = {}
334
+ appstruct [ 'contracts' ] = { 'customer_requests' : []}
335
+ appstruct [ 'contracts' ][ 'customer_requests' ]. append ( {'ticket' : True ,
336
+ 'title' : u'Analisi' })
337
+ appstruct [ 'contracts' ][ 'customer_requests' ]. append ({ 'ticket' : True ,
338
+ 'title' : u'Supporto' })
338
339
result ['form' ] = form .render (appstruct = appstruct )
339
340
return result
340
341
341
342
def handle_save (self , form , appstruct ):
342
343
""" The main handle method for the wizard. """
343
344
customer = self .context .get_instance ()
344
345
345
- # check if the contracts are unique
346
- contract_names = [a ['name' ] for a in appstruct ['contracts' ]]
347
- if len (contract_names ) > len (set (contract_names )):
348
- self .request .add_message (_ (u'Contrct names are duplicated' ), type = 'danger' )
349
- raise ValidationFailure (form , appstruct ,
350
- colander .Invalid (None , None ))
351
-
352
346
# create new users
353
347
recipients = []
354
348
groups = {}
@@ -397,14 +391,15 @@ def handle_save(self, form, appstruct):
397
391
group = Group (roles = [role , ], users = users )
398
392
project .add_group (group )
399
393
400
- #create contract
401
- for co in appstruct ['contracts' ]:
402
- contract = Contract (** co )
403
- project .contracts .append (contract )
394
+ #create contract with cr
395
+ crs = appstruct ['contracts' ]['customer_requests' ]
396
+ co = appstruct ['contracts' ]['contract' ]
397
+ contract = Contract (** co )
398
+ contract .project_id = project .id
404
399
405
400
#create CR
406
401
tickets = []
407
- for cr in appstruct [ 'customer_requests' ] :
402
+ for cr in crs :
408
403
customer_request = CustomerRequest (name = cr ['title' ])
409
404
person_types = {
410
405
'junior' : 'Junior' ,
@@ -417,21 +412,23 @@ def handle_save(self, form, appstruct):
417
412
for key , value in person_types .items ():
418
413
if cr [key ]:
419
414
Estimation (person_type = value ,
420
- days = cr [key ],
421
- customer_request = customer_request )
415
+ days = cr [key ],
416
+ customer_request = customer_request )
422
417
project .add_customer_request (customer_request )
418
+ customer_request .contract = contract
423
419
if not cr ['ticket' ]:
424
420
continue
425
421
tickets += [{'summary' : cr ['title' ],
426
- 'customerrequest' : customer_request ,
427
- 'reporter' : manager .email ,
428
- 'type' : 'task' ,
429
- 'priority' : 'major' ,
430
- 'milestone' : 'Backlog' ,
431
- 'owner' : manager .email }]
422
+ 'customerrequest' : customer_request ,
423
+ 'reporter' : manager .email ,
424
+ 'type' : 'task' ,
425
+ 'priority' : 'major' ,
426
+ 'milestone' : 'Backlog' ,
427
+ 'owner' : manager .email }]
432
428
433
429
#create project management CR and tickets
434
430
project_management_cr = CustomerRequest (name = "Project management" )
431
+ project_management_cr .contract = contract
435
432
project .add_customer_request (project_management_cr )
436
433
project_management_tickets = PM_TICKETS
437
434
for summary , description in project_management_tickets .items ():
0 commit comments