Skip to content

Commit 903af25

Browse files
committed
fix wizard according to req
1 parent 8cc8127 commit 903af25

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

por/dashboard/forms/wizard.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class CustomerRequest(colander.Schema):
242242
customer_request = CustomerRequest(title='')
243243

244244

245-
class Contracts(colander.SequenceSchema):
245+
class CRperContracts(colander.MappingSchema):
246246
class Contract(colander.Schema):
247247
name = SchemaNode(typ=colander.String(),
248248
widget=TextInputWidget(placeholder=u'Contract name'),
@@ -270,6 +270,7 @@ class Contract(colander.Schema):
270270
missing=None,
271271
title=u'End date')
272272

273+
customer_requests = CustomerRequests()
273274
contract = Contract(name='',)
274275

275276

@@ -279,8 +280,7 @@ class WizardSchema(colander.Schema):
279280
users = UsersSchema()
280281
new_users = NewUsersSchema()
281282
milestones = Milestones()
282-
customer_requests = CustomerRequests()
283-
contracts = Contracts()
283+
contracts = CRperContracts()
284284

285285

286286
class Wizard(object):
@@ -318,7 +318,8 @@ def render(self):
318318
[(str(role.id), role.name) for role in roles]
319319

320320
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)
322323

323324
controls = self.request.POST.items()
324325
if controls != []:
@@ -329,26 +330,19 @@ def render(self):
329330
result['form'] = e.render()
330331
return result
331332

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'})
338339
result['form'] = form.render(appstruct=appstruct)
339340
return result
340341

341342
def handle_save(self, form, appstruct):
342343
""" The main handle method for the wizard. """
343344
customer = self.context.get_instance()
344345

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-
352346
# create new users
353347
recipients = []
354348
groups = {}
@@ -397,14 +391,15 @@ def handle_save(self, form, appstruct):
397391
group = Group(roles=[role, ], users=users)
398392
project.add_group(group)
399393

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
404399

405400
#create CR
406401
tickets = []
407-
for cr in appstruct['customer_requests']:
402+
for cr in crs:
408403
customer_request = CustomerRequest(name=cr['title'])
409404
person_types = {
410405
'junior': 'Junior',
@@ -417,21 +412,23 @@ def handle_save(self, form, appstruct):
417412
for key, value in person_types.items():
418413
if cr[key]:
419414
Estimation(person_type=value,
420-
days=cr[key],
421-
customer_request=customer_request)
415+
days=cr[key],
416+
customer_request=customer_request)
422417
project.add_customer_request(customer_request)
418+
customer_request.contract = contract
423419
if not cr['ticket']:
424420
continue
425421
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}]
432428

433429
#create project management CR and tickets
434430
project_management_cr = CustomerRequest(name="Project management")
431+
project_management_cr.contract = contract
435432
project.add_customer_request(project_management_cr)
436433
project_management_tickets = PM_TICKETS
437434
for summary, description in project_management_tickets.items():

0 commit comments

Comments
 (0)