allow to inspect/duplicate default workflow

This commit is contained in:
Frédéric Péters 2012-08-13 10:02:22 +02:00
parent c36e3b45f2
commit 507ca3da60
3 changed files with 155 additions and 113 deletions

View File

@ -159,21 +159,28 @@ class WorkflowStatusPage(Directory):
if not self.status.items:
'<p>%s</p>' % _('There are not yet any items in this status.')
else:
'<p>'
_('Use drag and drop to reorder items.')
'</p>'
'<ul id="items-list" class="biglist sortable">'
if str(self.workflow.id).startswith(str('_')):
'<ul id="items-list" class="biglist">'
else:
'<p>'
_('Use drag and drop to reorder items.')
'</p>'
'<ul id="items-list" class="biglist sortable">'
for i, item in enumerate(self.status.items):
'<li class="biglistitem" id="itemId_%s">' % item.id
if hasattr(item, str('fill_admin_form')):
'<a href="items/%s/">%s</a>' % (item.id, item.render_as_line())
else:
if str(self.workflow.id).startswith(str('_')):
item.render_as_line()
'<p class="commands">'
if hasattr(item, str('fill_admin_form')):
command_icon('items/%s/' % item.id, 'edit')
command_icon('items/%s/delete' % item.id, 'remove', popup = True)
'</p></li>'
else:
if hasattr(item, str('fill_admin_form')):
'<a href="items/%s/">%s</a>' % (item.id, item.render_as_line())
else:
item.render_as_line()
'<p class="commands">'
if hasattr(item, str('fill_admin_form')):
command_icon('items/%s/' % item.id, 'edit')
command_icon('items/%s/delete' % item.id, 'remove', popup = True)
'</p>'
'</li>'
'</ul>'
'<p><a href="../../">%s</a></p>' % _('Back to workflow main page')
@ -182,14 +189,20 @@ class WorkflowStatusPage(Directory):
def get_sidebar [html] (self):
'<ul>'
'<li><a href="edit">%s</a></li>' % _('Change Status Name')
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
'</ul>'
'<div id="new-field">'
'<h3>%s</h3>' % _('New Item')
self.get_new_item_form().render()
'</div>'
if str(self.workflow.id).startswith(str('_')):
'<p>'
_('''This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.''')
'</p>'
else:
'<ul>'
'<li><a href="edit">%s</a></li>' % _('Change Status Name')
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
'</ul>'
'<div id="new-field">'
'<h3>%s</h3>' % _('New Item')
self.get_new_item_form().render()
'</div>'
def get_new_item_form [html] (self):
form = Form(enctype='multipart/form-data', action = 'newitem')
@ -304,18 +317,21 @@ class WorkflowPage(Directory):
if not self.workflow.possible_status:
'<p>%s</p>' % _('There are not yet any status defined in this workflow.')
else:
'<p>'
_('Use drag and drop to reorder status.')
'</p>'
'<ul id="status-list" class="biglist sortable">'
if not str(self.workflow.id).startswith(str('_')):
'<p>'
_('Use drag and drop to reorder status.')
'</p>'
'<ul id="status-list" class="biglist sortable">'
else:
'<ul id="status-list" class="biglist">'
for status in self.workflow.possible_status:
'<li class="biglistitem" id="itemId_%s">' % status.id
'<a href="status/%s/">%s</a>' % (status.id, status.name)
'<p class="commands">'
command_icon('status/%s/' % status.id, 'edit')
command_icon('status/%s/delete' % status.id, 'remove', popup = True)
if not str(self.workflow.id).startswith(str('_')):
command_icon('status/%s/' % status.id, 'edit')
command_icon('status/%s/delete' % status.id, 'remove', popup = True)
'</p>'
'</li>'
'</ul>'
@ -323,14 +339,22 @@ class WorkflowPage(Directory):
get_response().filter['sidebar'] = self.get_sidebar()
def get_sidebar [html] (self):
if str(self.workflow.id).startswith(str('_')):
'<p>'
_('''This is the default workflow, you cannot edit it but you can
duplicate it to base your own workflow on it.''')
'</p>'
'<ul>'
'<li><a href="edit">%s</a></li>' % _('Change Title')
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
'<li><a href="duplicate">%s</a></li>' % _('Duplicate')
if not str(self.workflow.id).startswith(str('_')):
'<li><a href="edit">%s</a></li>' % _('Change Title')
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
if ET:
'<li><a href="duplicate">%s</a></li>' % _('Duplicate')
'<li><a href="export">%s</a></li>' % _('Export')
'</ul>'
self.get_new_status_form()
if not str(self.workflow.id).startswith(str('_')):
self.get_new_status_form()
def export(self):
x = self.workflow.export_to_xml()
@ -441,14 +465,15 @@ class WorkflowsDirectory(Directory):
'</ul>'
'<ul class="biglist">'
for workflow in Workflow.select(order_by = 'name'):
for workflow in [Workflow.get_default_workflow()] + Workflow.select(order_by = 'name'):
'<li>'
'<strong class="label"><a href="%s/">%s</a></strong>' % (workflow.id, workflow.name)
'<p class="details">'
'</p>'
'<p class="commands">'
command_icon('%s/' % workflow.id, 'edit')
command_icon('%s/delete' % workflow.id, 'remove', popup = True)
if not str(workflow.id).startswith(str('_')):
command_icon('%s/' % workflow.id, 'edit')
command_icon('%s/delete' % workflow.id, 'remove', popup = True)
command_icon('%s/duplicate' % workflow.id, 'duplicate')
'</p></li>'
'</ul>'

View File

@ -205,87 +205,10 @@ class FormDef(StorableObject):
try:
workflow = Workflow.get(self.workflow_id)
except KeyError:
return None
return Workflow.get_unknown_workflow()
return self.get_workflow_with_options(workflow)
else:
return self.get_default_workflow()
def get_default_workflow(self):
workflow = Workflow(name=_('Default'))
workflow.id = '_default'
new_status = workflow.add_status(_('New'), 'new')
rejected_status = workflow.add_status(_('Rejected'), 'rejected')
accepted_status = workflow.add_status(_('Accepted'), 'accepted')
finished_status = workflow.add_status(_('Finished'), 'finished')
commentable = CommentableWorkflowStatusItem()
commentable.id = '_commentable'
commentable.by = ('_submitted', '_receiver')
notify_new_receiver_email = SendmailWorkflowStatusItem()
notify_new_receiver_email.id = '_notify_new_receiver_email'
notify_new_receiver_email.to = ('_receiver',)
notify_new_receiver_email.subject = EmailsDirectory.get_subject('new_receiver')
notify_new_receiver_email.body = EmailsDirectory.get_body('new_receiver')
notify_new_user_email = SendmailWorkflowStatusItem()
notify_new_user_email.id = '_notify_new_user_email'
notify_new_user_email.to = ('_submitter',)
notify_new_user_email.subject = EmailsDirectory.get_subject('new_user')
notify_new_user_email.body = EmailsDirectory.get_body('new_user')
notify_change_receiver_email = SendmailWorkflowStatusItem()
notify_change_receiver_email.id = '_notify_change_receiver_email'
notify_change_receiver_email.to = ('_receiver',)
notify_change_receiver_email.subject = EmailsDirectory.get_subject('change_receiver')
notify_change_receiver_email.body = EmailsDirectory.get_body('change_receiver')
notify_change_user_email = SendmailWorkflowStatusItem()
notify_change_user_email.id = '_notify_change_user_email'
notify_change_user_email.to = ('_submitter',)
notify_change_user_email.subject = EmailsDirectory.get_subject('change_user')
notify_change_user_email.body = EmailsDirectory.get_body('change_user')
new_status.items.append(notify_new_receiver_email)
new_status.items.append(notify_new_user_email)
accepted_status.items.append(notify_change_receiver_email)
accepted_status.items.append(notify_change_user_email)
rejected_status.items.append(notify_change_receiver_email)
rejected_status.items.append(notify_change_user_email)
finished_status.items.append(notify_change_receiver_email)
finished_status.items.append(notify_change_user_email)
accept = ChoiceWorkflowStatusItem()
accept.id = '_accept'
accept.label = _('Accept')
accept.by = ('_receiver',)
accept.status = accepted_status.id
accept.parent = new_status
new_status.items.append(accept)
new_status.items.append(commentable)
accepted_status.items.append(commentable)
reject = ChoiceWorkflowStatusItem()
reject.id = '_reject'
reject.label = _('Reject')
reject.by = ('_receiver',)
reject.status = rejected_status.id
reject.parent = new_status
new_status.items.append(reject)
finish = ChoiceWorkflowStatusItem()
finish.id = '_finish'
finish.label = _('Finish')
finish.by = ('_receiver',)
finish.status = finished_status.id
finish.parent = accepted_status
accepted_status.items.append(finish)
return workflow
return Workflow.get_default_workflow()
def get_workflow_with_options(self, workflow):
# this needs to be kept in sync with admin/forms.ptl,

View File

@ -87,6 +87,13 @@ class Workflow(StorableObject):
self.name = name
self.possible_status = []
def get(cls, id, ignore_errors=False, ignore_migration=False):
if id == '_default':
return cls.get_default_workflow()
return super(Workflow, cls).get (id, ignore_errors=ignore_errors,
ignore_migration=ignore_migration)
get = classmethod(get)
def add_status(self, name, id=None):
if [x for x in self.possible_status if x.name == name]:
raise DuplicateStatusNameError()
@ -181,6 +188,93 @@ class Workflow(StorableObject):
return workflow
import_from_xml_tree = classmethod(import_from_xml_tree)
def get_unknown_workflow(cls):
workflow = Workflow(name=_('Unknown'))
workflow.id = '_unknown'
return workflow
get_unknown_workflow = classmethod(get_unknown_workflow)
def get_default_workflow(cls):
from qommon.admin.emails import EmailsDirectory
workflow = Workflow(name=_('Default'))
workflow.id = '_default'
new_status = workflow.add_status(_('New'), 'new')
rejected_status = workflow.add_status(_('Rejected'), 'rejected')
accepted_status = workflow.add_status(_('Accepted'), 'accepted')
finished_status = workflow.add_status(_('Finished'), 'finished')
commentable = CommentableWorkflowStatusItem()
commentable.id = '_commentable'
commentable.by = ['_submitted', '_receiver']
notify_new_receiver_email = SendmailWorkflowStatusItem()
notify_new_receiver_email.id = '_notify_new_receiver_email'
notify_new_receiver_email.to = ['_receiver']
notify_new_receiver_email.subject = EmailsDirectory.get_subject('new_receiver')
notify_new_receiver_email.body = EmailsDirectory.get_body('new_receiver')
notify_new_user_email = SendmailWorkflowStatusItem()
notify_new_user_email.id = '_notify_new_user_email'
notify_new_user_email.to = ['_submitter']
notify_new_user_email.subject = EmailsDirectory.get_subject('new_user')
notify_new_user_email.body = EmailsDirectory.get_body('new_user')
notify_change_receiver_email = SendmailWorkflowStatusItem()
notify_change_receiver_email.id = '_notify_change_receiver_email'
notify_change_receiver_email.to = ['_receiver']
notify_change_receiver_email.subject = EmailsDirectory.get_subject('change_receiver')
notify_change_receiver_email.body = EmailsDirectory.get_body('change_receiver')
notify_change_user_email = SendmailWorkflowStatusItem()
notify_change_user_email.id = '_notify_change_user_email'
notify_change_user_email.to = ['_submitter']
notify_change_user_email.subject = EmailsDirectory.get_subject('change_user')
notify_change_user_email.body = EmailsDirectory.get_body('change_user')
new_status.items.append(notify_new_receiver_email)
new_status.items.append(notify_new_user_email)
accepted_status.items.append(notify_change_receiver_email)
accepted_status.items.append(notify_change_user_email)
rejected_status.items.append(notify_change_receiver_email)
rejected_status.items.append(notify_change_user_email)
finished_status.items.append(notify_change_receiver_email)
finished_status.items.append(notify_change_user_email)
accept = ChoiceWorkflowStatusItem()
accept.id = '_accept'
accept.label = _('Accept')
accept.by = ['_receiver']
accept.status = accepted_status.id
accept.parent = new_status
new_status.items.append(accept)
new_status.items.append(commentable)
accepted_status.items.append(commentable)
reject = ChoiceWorkflowStatusItem()
reject.id = '_reject'
reject.label = _('Reject')
reject.by = ['_receiver']
reject.status = rejected_status.id
reject.parent = new_status
new_status.items.append(reject)
finish = ChoiceWorkflowStatusItem()
finish.id = '_finish'
finish.label = _('Finish')
finish.by = ['_receiver']
finish.status = finished_status.id
finish.parent = accepted_status
accepted_status.items.append(finish)
return workflow
get_default_workflow = classmethod(get_default_workflow)
class WorkflowStatus:
id = None