# HG changeset patch # User Thierry Florac # Date 1444297050 -7200 # Node ID 182f33bba91d99d83df4f52c59944acc3f0df1c9 # Parent 84c77a22656054fd4718a40d12225afb828817f3 Updated management interface diff -r 84c77a226560 -r 182f33bba91d src/pyams_workflow/zmi/transition.py --- a/src/pyams_workflow/zmi/transition.py Thu Oct 08 11:36:22 2015 +0200 +++ b/src/pyams_workflow/zmi/transition.py Thu Oct 08 11:37:30 2015 +0200 @@ -9,6 +9,7 @@ # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # +from pyams_form.form import AJAXAddForm __docformat__ = 'restructuredtext' @@ -17,7 +18,7 @@ # import interfaces from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflow, IWorkflowTransitionInfo, IWorkflowCommentInfo, \ - IWorkflowInfo + IWorkflowInfo, IWorkflowState from z3c.form.interfaces import HIDDEN_MODE # import packages @@ -71,8 +72,16 @@ info = IWorkflowInfo(self.context) info.fire_transition(self.transition.transition_id, comment=data.get('comment')) info.fire_automatic() + IWorkflowState(self.context).state_urgency = data.get('urgent_request') or False self.request.registry.notify(ObjectModifiedEvent(self.context)) return info def nextURL(self): return absolute_url(self.context, self.request, 'summary.html') + + +class WorkflowContentTransitionAJAXForm(AJAXAddForm): + """Workflow content transition AJAX form""" + + def get_ajax_output(self, changes): + return {'status': 'reload'} diff -r 84c77a226560 -r 182f33bba91d src/pyams_workflow/zmi/versions.py --- a/src/pyams_workflow/zmi/versions.py Thu Oct 08 11:36:22 2015 +0200 +++ b/src/pyams_workflow/zmi/versions.py Thu Oct 08 11:37:30 2015 +0200 @@ -16,49 +16,40 @@ # import standard library # import interfaces -from pyams_form.interfaces.form import IWidgetsSuffixViewletsManager from pyams_security.interfaces import ISecurityManager +from pyams_skin.interfaces import IInnerPage from pyams_skin.layer import IPyAMSLayer -from pyams_workflow.interfaces import IWorkflowVersion, IWorkflowState -from pyams_zmi.interfaces.menu import IPropertiesMenu +from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION +from pyams_workflow.interfaces import IWorkflowVersion, IWorkflowState, IWorkflow +from pyams_zmi.interfaces import IAdminView +from pyams_zmi.interfaces.menu import IContentManagementMenu from z3c.table.interfaces import IValues, IColumn # import packages from pyams_pagelet.pagelet import pagelet_config +from pyams_skin.container import ContainerView from pyams_skin.table import BaseTable, I18nColumn -from pyams_skin.viewlet.menu import MenuItem, MenuDivider +from pyams_skin.viewlet.menu import MenuItem from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter -from pyams_utils.date import format_datetime +from pyams_utils.date import format_datetime, SH_DATETIME_FORMAT from pyams_utils.registry import query_utility from pyams_utils.text import text_to_html -from pyams_viewlet.viewlet import viewlet_config, Viewlet -from pyams_zmi.form import AdminDialogDisplayForm +from pyams_viewlet.viewlet import viewlet_config from pyams_zmi.layer import IAdminLayer -from z3c.form import field from z3c.table.column import GetAttrColumn -from zope.interface import Interface +from zope.interface import implementer, Interface from pyams_workflow import _ @viewlet_config(name='workflow-history.menu', context=IWorkflowVersion, layer=IAdminLayer, - manager=IPropertiesMenu, permission='manage', weight=999) + manager=IContentManagementMenu, permission=VIEW_SYSTEM_PERMISSION, weight=999) class WorkflowVersionHistoryMenuItem(MenuItem): """Workflow history menu item""" - label = _("Version history...") + label = _("Version history") icon_class = 'fa fa-fw fa-history' - url = 'version-history.html' - modal_target = True - - -@pagelet_config(name='version-history.html', context=IWorkflowVersion, layer=IPyAMSLayer, - permission='manage') -class WorkflowVersionHistoryDisplayForm(AdminDialogDisplayForm): - """Workflow version history view""" - - dialog_class = 'modal-large' - fields = field.Fields(Interface) + url = '#version-history.html' class WorkflowVersionHistoryTable(BaseTable): @@ -71,7 +62,7 @@ cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight datatable'} sortOn = None - hide_toolbar = True + hide_body_toolbar = True @property def data_attributes(self): @@ -83,34 +74,44 @@ 'data-ams-datatable-pagination-type': 'bootstrap_prevnext'}} -@adapter_config(context=(IWorkflowVersion, IAdminLayer, WorkflowVersionHistoryTable), provides=IValues) +@adapter_config(context=(IWorkflowVersion, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IValues) class WorkflowVersionHistoryValuesAdapter(ContextRequestViewAdapter): """Workflow version history values adapter""" @property def values(self): - return IWorkflowState(self.context).history + return reversed(IWorkflowState(self.context).history) -@adapter_config(name='date', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) +@adapter_config(name='date', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) class WorkflowVersionHistoryDateColumn(I18nColumn, GetAttrColumn): """Workflow version history date column""" _header = _("Date") attrName = 'date' + cssClasses = {'td': 'nowrap'} weight = 1 def renderCell(self, item): - return format_datetime(item.date, request=self.request) + return format_datetime(item.date, SH_DATETIME_FORMAT, request=self.request) -@adapter_config(name='name', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) +@adapter_config(name='target', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) +class WorkflowVersionHistoryTargetColumn(I18nColumn, GetAttrColumn): + """Workflow version history source column""" + + _header = _("New state") + attrName = 'target_state' + weight = 5 + + +@adapter_config(name='name', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) class WorkflowVersionHistoryPrincipalColumn(I18nColumn, GetAttrColumn): """Workflow version history principal column""" - _header = _("Principal") + _header = _("Modifier") attrName = 'principal' - weight = 4 + weight = 10 def renderCell(self, item): manager = query_utility(ISecurityManager) @@ -120,66 +121,56 @@ return item.principal -@adapter_config(name='source', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) -class WorkflowVersionHistorySourceColumn(I18nColumn, GetAttrColumn): - """Workflow version history source column""" +@adapter_config(name='comment', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) +class WorkflowVersionHistoryCommentColumn(I18nColumn, GetAttrColumn): + """Workflow version history comment column""" - _header = _("Source") - weight = 10 + _header = _("Comment") + weight = 15 def renderCell(self, item): - translate = self.request.localizer.translate - if item.source_version: - return translate(_("Version {version} ({status})")).format( - version=item.source_version, - status=item.source_state) - else: - return translate(_("Version {version} ({status})")).format( - version=IWorkflowState(self.context).version_id, - status=item.source_state if item.source_state else '--') + return text_to_html(item.comment or '--') -@adapter_config(name='transition', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) +@adapter_config(name='transition', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) class WorkflowVersionHistoryTransitionColumn(I18nColumn, GetAttrColumn): """Workflow version history source column""" _header = _("Transition") attrName = 'transition' - weight = 11 - - -@adapter_config(name='target', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) -class WorkflowVersionHistoryTargetColumn(I18nColumn, GetAttrColumn): - """Workflow version history source column""" - - _header = _("Target state") - attrName = 'target_state' - weight = 12 - - -@adapter_config(name='comment', context=(Interface, IAdminLayer, WorkflowVersionHistoryTable), provides=IColumn) -class WorkflowVersionHistoryCommentColumn(I18nColumn, GetAttrColumn): - """Workflow version history comment column""" - - _header = _("Comment") weight = 20 def renderCell(self, item): - return text_to_html(item.comment or '--') + workflow = IWorkflow(self.context) + if item.transition_id: + transition = workflow.get_transition_by_id(item.transition_id) + label = self.request.localizer.translate(transition.user_data.get('history_label', item.transition)) + else: + label = item.transition + return label -@viewlet_config(name='version-history', view=WorkflowVersionHistoryDisplayForm, layer=IAdminLayer, - manager=IWidgetsSuffixViewletsManager) -class WorkflowVersionHistoryViewlet(Viewlet): - """Workflow version history viewlet""" +@adapter_config(name='source', context=(Interface, IPyAMSLayer, WorkflowVersionHistoryTable), provides=IColumn) +class WorkflowVersionHistorySourceColumn(I18nColumn, GetAttrColumn): + """Workflow version history source column""" + + _header = _("Previous state") + weight = 25 - def __init__(self, context, request, view, manager): - super(WorkflowVersionHistoryViewlet, self).__init__(context, request, view, manager) - self.table = WorkflowVersionHistoryTable(context, request) + def renderCell(self, item): + translate = self.request.localizer.translate + if item.source_version: + return translate(_("{status} (version {version})")).format( + version=item.source_version, + status=item.source_state) + else: + return item.source_state or '--' - def update(self): - super(WorkflowVersionHistoryViewlet, self).update() - self.table.update() - def render(self): - return '
{0}
'.format(self.table.render()) +@pagelet_config(name='version-history.html', context=IWorkflowVersion, layer=IPyAMSLayer, + permission=VIEW_SYSTEM_PERMISSION) +@implementer(IInnerPage, IAdminView) +class WorkflowVersionHistoryView(ContainerView): + """Workflow version history view""" + + table_class = WorkflowVersionHistoryTable diff -r 84c77a226560 -r 182f33bba91d src/pyams_workflow/zmi/viewlet/versions.py --- a/src/pyams_workflow/zmi/viewlet/versions.py Thu Oct 08 11:36:22 2015 +0200 +++ b/src/pyams_workflow/zmi/viewlet/versions.py Thu Oct 08 11:37:30 2015 +0200 @@ -27,10 +27,11 @@ from pyams_utils.traversing import get_parent from pyams_viewlet.viewlet import viewlet_config, Viewlet from pyramid.decorator import reify +from zope.interface import Interface @viewlet_config(name='pyams_workflow.versions', context=IWorkflowVersion, layer=IPyAMSLayer, - manager=IToolbarViewletManager, weight=1) + view=Interface, manager=IToolbarViewletManager, weight=1) @template_config(template='templates/versions.pt', layer=IPyAMSLayer) class WorkflowVersionMenuProvider(Viewlet): """Workflow versions menu content provider""" diff -r 84c77a226560 -r 182f33bba91d src/pyams_workflow/zmi/workflow.py --- a/src/pyams_workflow/zmi/workflow.py Thu Oct 08 11:36:22 2015 +0200 +++ b/src/pyams_workflow/zmi/workflow.py Thu Oct 08 11:37:30 2015 +0200 @@ -16,9 +16,10 @@ # import standard library # import interfaces +from pyams_skin.interfaces.viewlet import IToolbarViewletManager from pyams_i18n.interfaces import II18n -from pyams_skin.interfaces.viewlet import IToolbarViewletManager from pyams_skin.layer import IPyAMSLayer +from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION from pyams_workflow.interfaces import IWorkflow, IWorkflowInfo, IWorkflowVersion, IWorkflowManagedContent, \ IWorkflowVersions, IWorkflowState from pyams_workflow.zmi.interfaces import IWorkflowMenu @@ -56,8 +57,8 @@ self.modal_target = True -@viewlet_config(name='workflow.menu', view=Interface, layer=IAdminLayer, context=IWorkflowVersion, - manager=IToolbarViewletManager, weight=800) +@viewlet_config(name='workflow.menu', context=IWorkflowVersion, layer=IAdminLayer, + view=Interface, manager=IToolbarViewletManager, weight=800) @viewletmanager_config(name='workflow.menu', layer=IAdminLayer, provides=IWorkflowMenu) @implementer(IWorkflowMenu) class WorkflowMenu(ToolbarMenu): @@ -115,7 +116,7 @@ @view_config(name='get-old-versions.html', context=IContainer, request_type=IPyAMSLayer, - permission='system.view', xhr=True) + permission=VIEW_SYSTEM_PERMISSION, xhr=True) def get_old_versions(request): """Get old_versions of template""" container = request.context