src/pyams_workflow/zmi/workflow.py
changeset 52 76d0ac1526a0
parent 51 ea6028f6a177
child 53 cda141a3f551
--- a/src/pyams_workflow/zmi/workflow.py	Fri Dec 08 12:15:42 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,138 +0,0 @@
-#
-# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-
-__docformat__ = 'restructuredtext'
-
-
-# import standard library
-
-# import interfaces
-from pyams_skin.interfaces.viewlet import IToolbarViewletManager
-from pyams_i18n.interfaces import II18n
-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
-from pyams_zmi.layer import IAdminLayer
-from zope.container.interfaces import IContainer
-from zope.dublincore.interfaces import IZopeDublinCore
-
-# import packages
-from pyams_skin.table import NameColumn
-from pyams_skin.viewlet.toolbar import ToolbarMenu, ToolbarMenuItem
-from pyams_utils.registry import query_utility
-from pyams_utils.date import format_datetime
-from pyams_utils.timezone import tztime
-from pyams_utils.traversing import get_parent
-from pyams_utils.url import absolute_url
-from pyams_viewlet.manager import viewletmanager_config
-from pyams_viewlet.viewlet import viewlet_config
-from pyramid.response import Response
-from pyramid.view import view_config
-from zope.interface import implementer, Interface
-
-from pyams_workflow import _
-
-
-class WorkflowMenuItem(ToolbarMenuItem):
-    """Workflow menu item"""
-
-    def __init__(self, context, request, view, manager, transition):
-        super(WorkflowMenuItem, self).__init__(context, request, view, manager)
-        self.label = transition.title
-        self.label_css_class = transition.user_data.get('menu_css_class') or 'fa fa-fw'
-        self.url = '{url}?form.widgets.transition_id={transition}'.format(url=transition.user_data.get('view_name'),
-                                                                          transition=transition.transition_id)
-        self.weight = transition.order
-        self.modal_target = True
-
-
-@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):
-    """Workflow menu"""
-
-    label = _("Change status...")
-    label_css_class = ''
-    css_class = 'btn btn-xs btn-danger dropdown-toggle'
-
-    def _get_viewlets(self):
-        viewlets = []
-        parent = get_parent(self.context, IWorkflowManagedContent)
-        wf = query_utility(IWorkflow, name=parent.workflow_name)
-        if wf is None:
-            return viewlets
-        info = IWorkflowInfo(self.context)
-        for transition_id in info.get_manual_transition_ids():
-            transition = wf.get_transition_by_id(transition_id)
-            menu = WorkflowMenuItem(self.context, self.request, self.__parent__, self, transition)
-            viewlets.append((transition_id, menu))
-        viewlets.sort(key=lambda x: x[1].weight)
-        return viewlets
-
-
-class WorkflowContentNameColumn(NameColumn):
-    """Workflow content name column"""
-
-    name_field = 'title'
-
-    def getValue(self, obj):
-        result = ''
-        wf_versions = IWorkflowVersions(obj).get_last_versions(count=0)
-        if wf_versions:
-            content = get_parent(obj, IWorkflowManagedContent)
-            workflow = query_utility(IWorkflow, name=content.workflow_name)
-            result += '<i class="fa fa-fw fa-caret-right margin-top-2 pull-left" ' \
-                      'data-ams-url="PyAMS_workflow.versions_list.switchVersions"></i>'
-            result += '<span class="title">{0}</span>'.format(II18n(wf_versions[0]).query_attribute(self.name_field))
-            result += '<ul class="hidden versions">'
-            translate = self.request.localizer.translate
-            for version in wf_versions[:3]:
-                state = IWorkflowState(version)
-                result += '<li><a data-ams-url="{url}">{version}</a></li>'.format(
-                    url=absolute_url(version, self.request, 'admin'),
-                    version=translate(_("Version {version} ({state} - last update {date})")).format(
-                        version=state.version_id,
-                        state=translate(workflow.states.getTerm(state.state).title),
-                        date=format_datetime(tztime(IZopeDublinCore(version).modified))))
-            if len(wf_versions) > 3:
-                result += '<li class="nodot"><span data-ams-url="PyAMS_workflow.versions_list.switchAllVersions">' \
-                          '<i class="fa fa-fw fa-caret-right margin-top-2 pull-left"></i>' + \
-                          translate(_("Older versions")) + '</span>'
-                result += '<ul class="hidden old_versions"></ul></li>'
-            result += '</ul>'
-        return result
-
-
-@view_config(name='get-old-versions.html', context=IContainer, request_type=IPyAMSLayer,
-             permission=VIEW_SYSTEM_PERMISSION, xhr=True)
-def get_old_versions(request):
-    """Get old_versions of template"""
-    container = request.context
-    element = container.get(request.params.get('element_name'))
-    ignore = int(request.params.get('ignore', 3))
-    translate = request.localizer.translate
-    result = []
-    content = get_parent(element, IWorkflowManagedContent)
-    workflow = query_utility(IWorkflow, name=content.workflow_name)
-    for version in IWorkflowVersions(element).get_last_versions(count=0)[ignore:]:
-        state = IWorkflowState(version)
-        result += '<li><a data-ams-url="{url}">{version}</a></li>'.format(
-            url=absolute_url(version, request, 'admin'),
-            version=translate(_("Version {version} ({state} - last update {date})")).format(
-                version=state.version_id,
-                state=translate(workflow.states.getTerm(state.state).title),
-                date=format_datetime(tztime(IZopeDublinCore(version).modified))))
-    return Response(''.join(result))