Project

General

Profile

delete-reassign-workflows.ptl.diff

Thomas Noël, 31 August 2012 04:41 PM

Download (3.33 KB)

View differences:


  

wcs/admin/workflows.ptl
426 426
        form.render()
427 427

  
428 428
    def reassign [html] (self):
429
        options = [(None, 'Do nothing'), ('remove', _('Remove'))]
429
        options = [(None, 'Do nothing'),
430
                    ('remove', _('Remove these forms'))]
430 431
        for status in self.workflow.get_waitpoint_status():
431 432
            if status.id == self.status.id:
432 433
                continue
433
            options.append(('reassign-%s' % status.id, _('Change to "%s"') % status.name))
434
            options.append(('reassign-%s' % status.id,
435
                _('Change these forms status to "%s"') % status.name))
434 436

  
435 437
        form = Form(enctype='multipart/form-data')
436 438
        form.add(SingleSelectWidget, 'action', title=_('Pick an Action'),
......
445 447
            return redirect('.')
446 448

  
447 449
        if not form.is_submitted() or form.has_errors():
448
            get_response().breadcrumb.append(('reassign', _('Reassign')))
449
            html_top('workflows', title = _('Reassign'))
450
            '<h2>%s</h2>' % _('Reassigning ')
450
            get_response().breadcrumb.append(('reassign', _('Delete / Reassign')))
451
            html_top('workflows', title = _('Delete Status'))
452
            html_top('workflows', title = _('Delete Status / Reassign'))
453
            '<h2>%s %s</h2>' % (_('Deleting Status:'), self.status.name)
451 454
            '<p>'
452 455
            _('''There are forms set to this status, they need to be changed before
453 456
                 this status can be deleted.''')
......
465 468
            form.render()
466 469
        else:
467 470
            self.submit_reassign(form)
468
            return redirect('.')
471
            del self.workflow.possible_status[ self.workflow.possible_status.index(self.status) ]
472
            self.workflow.store()
473
            return redirect('../..')
469 474

  
470 475
    def submit_reassign(self, form):
471 476
        action = form.get_widget('action').parse()
......
474 479
        for formdef in FormDef.select():
475 480
            if formdef.workflow_id != self.workflow.id:
476 481
                continue
477
            items = formdef.data_class().get_with_indexed_value(
478
                            str('status'), 'wf-%s' % self.status.id)
479
            for item in items:
482
            for item in formdef.data_class().get_with_indexed_value(
483
                    str('status'), 'wf-%s' % self.status.id):
480 484
                if action == 'remove':
481 485
                    item.remove_self()
482 486
                else:
......
489 493
                        item.evolution = []
490 494
                    item.evolution.append(evo)
491 495
                    item.store()
496
            # delete all (old) status references in evolutions
497
            for item in formdef.data_class().select():
498
                if item.evolution:
499
                    modified = False
500
                    for evo in item.evolution:
501
                        if evo.status == self.status:
502
                            evo.status = None
503
                            modified = True
504
                    if modified:
505
                        item.store()
492 506

  
493 507

  
494 508
class WorkflowStatusDirectory(Directory):