admin: better handling of workflow modifications (#1241)

This commit is contained in:
Thomas NOËL 2012-09-03 15:47:32 +02:00
parent 35426af9af
commit 31cbfce2fe
2 changed files with 33 additions and 17 deletions

View File

@ -38,6 +38,7 @@ from qommon import misc
from qommon.errors import *
from qommon.form import *
from qommon.admin.menu import html_top, command_icon, error_page
from qommon import get_logger
from qommon import tokens
from qommon.afterjobs import AfterJob
@ -574,6 +575,8 @@ class FormDefPage(Directory):
'</p>'
form.render()
else:
get_logger().info('admin - form "%s", workflow is now "%s" (was "%s")' % (
self.formdef.name, new_workflow.name, self.formdef.workflow.name))
self.workflow_status_remapping_submit(form)
if new_workflow.id == '_default':
self.formdef.workflow_id = None
@ -589,16 +592,9 @@ class FormDefPage(Directory):
form.get_widget('mapping-%s' % status.id).parse()
for item in self.formdef.data_class().select():
item.status = status_mapping.get(item.status)
if not item.evolution:
item.evolution = []
else:
if item.evolution:
for evo in item.evolution:
evo.status = status_mapping.get(evo.status)
evo = Evolution()
evo.time = time.localtime()
evo.status = item.status
evo.comment = _('Administrator changed workflow, reassigned status')
item.evolution.append(evo)
item.store()
def get_preview [html] (self):

View File

@ -28,6 +28,7 @@ from qommon import errors
from qommon import misc
from qommon.form import *
from qommon.admin.menu import html_top, command_icon, error_page
from qommon import get_logger
from wcs.workflows import *
from wcs.formdef import FormDef
@ -426,11 +427,13 @@ class WorkflowStatusPage(Directory):
form.render()
def reassign [html] (self):
options = [(None, 'Do nothing'), ('remove', _('Remove'))]
options = [(None, 'Do nothing'),
('remove', _('Remove these forms'))]
for status in self.workflow.get_waitpoint_status():
if status.id == self.status.id:
continue
options.append(('reassign-%s' % status.id, _('Change to "%s"') % status.name))
options.append(('reassign-%s' % status.id,
_('Change these forms status to "%s"') % status.name))
form = Form(enctype='multipart/form-data')
form.add(SingleSelectWidget, 'action', title=_('Pick an Action'),
@ -445,9 +448,10 @@ class WorkflowStatusPage(Directory):
return redirect('.')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('reassign', _('Reassign')))
html_top('workflows', title = _('Reassign'))
'<h2>%s</h2>' % _('Reassigning ')
get_response().breadcrumb.append(('reassign', _('Delete / Reassign')))
html_top('workflows', title = _('Delete Status'))
html_top('workflows', title = _('Delete Status / Reassign'))
'<h2>%s %s</h2>' % (_('Deleting Status:'), self.status.name)
'<p>'
_('''There are forms set to this status, they need to be changed before
this status can be deleted.''')
@ -465,18 +469,21 @@ class WorkflowStatusPage(Directory):
form.render()
else:
self.submit_reassign(form)
return redirect('.')
del self.workflow.possible_status[ self.workflow.possible_status.index(self.status) ]
self.workflow.store()
return redirect('../..')
def submit_reassign(self, form):
nb_forms = 0
action = form.get_widget('action').parse()
if action.startswith(str('reassign-')):
new_status = 'wf-%s' % str(action)[9:]
for formdef in FormDef.select():
if formdef.workflow_id != self.workflow.id:
continue
items = formdef.data_class().get_with_indexed_value(
str('status'), 'wf-%s' % self.status.id)
for item in items:
for item in formdef.data_class().get_with_indexed_value(
str('status'), 'wf-%s' % self.status.id):
nb_forms += 1
if action == 'remove':
item.remove_self()
else:
@ -489,6 +496,19 @@ class WorkflowStatusPage(Directory):
item.evolution = []
item.evolution.append(evo)
item.store()
# delete all (old) status references in evolutions
for item in formdef.data_class().select():
if item.evolution:
modified = False
for evo in item.evolution:
if evo.status == self.status:
evo.status = None
modified = True
if modified:
item.store()
if action == 'remove':
get_logger().info('admin - delete status "%s" in workflow "%s": %d forms deleted' % (
self.status.name, self.workflow.name, nb_forms))
class WorkflowStatusDirectory(Directory):