--- a/src/pyams_content/workflow/interfaces.py Mon Sep 11 14:42:46 2017 +0200
+++ b/src/pyams_content/workflow/interfaces.py Mon Sep 11 14:43:43 2017 +0200
@@ -16,10 +16,20 @@
# import standard library
# import interfaces
+from pyams_scheduler.interfaces import ITask
from pyams_workflow.interfaces import IWorkflow
# import packages
+from zope.interface import Interface
class IContentWorkflow(IWorkflow):
"""PyAMS default content workflow marker interface"""
+
+
+class IContentArchiverTaskInfo(Interface):
+ """Content archiver task info"""
+
+
+class IContentArchiverTask(ITask, IContentArchiverTaskInfo):
+ """Content archiver task interface"""
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/workflow/task.py Mon Sep 11 14:43:43 2017 +0200
@@ -0,0 +1,67 @@
+#
+# 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
+from datetime import datetime
+
+# import interfaces
+from hypatia.interfaces import ICatalog
+from pyams_content.shared.common.interfaces import ISharedTool
+from pyams_content.workflow.interfaces import IContentArchiverTask
+from pyams_i18n.interfaces import II18n
+from pyams_sequence.interfaces import ISequentialIdInfo
+from pyams_workflow.interfaces import IWorkflow, IWorkflowInfo
+
+# import packages
+from hypatia.catalog import CatalogQuery
+from hypatia.query import Eq, Lt, Any
+from pyams_catalog.query import CatalogResultSet
+from pyams_scheduler.task import Task
+from pyams_utils.registry import get_utility, get_all_utilities_registered_for
+from pyams_utils.request import check_request
+from pyams_utils.timezone import gmtime
+from zope.interface import implementer
+
+from pyams_content import _
+
+
+@implementer(IContentArchiverTask)
+class ContentArchiverTask(Task):
+ """"Content archiver task"""
+
+ settings_view_name = None
+
+ def run(self, report):
+ request = check_request()
+ translate = request.localizer.translate
+ catalog = get_utility(ICatalog)
+ now = gmtime(datetime.utcnow())
+ has_retired = False
+ for tool in get_all_utilities_registered_for(ISharedTool):
+ workflow = IWorkflow(tool)
+ params = Eq(catalog['content_type'], tool.shared_content_type) & \
+ Any(catalog['workflow_state'], workflow.published_states) & \
+ Lt(catalog['expiration_date'], now)
+ for content in CatalogResultSet(CatalogQuery(catalog).query(params)):
+ if not has_retired:
+ report.write(translate(_("Automatic contents withdrawal:\n")))
+ has_retired = True
+ info = IWorkflowInfo(content)
+ info.fire_transition_toward(workflow.auto_retired_state,
+ check_security=False,
+ principal='system:internal')
+ info.fire_automatic()
+ report.write("- {0} ({1})\n".format(II18n(content).query_attribute('title', request=request),
+ ISequentialIdInfo(content).hex_oid))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/workflow/zmi/task.py Mon Sep 11 14:43:43 2017 +0200
@@ -0,0 +1,64 @@
+#
+# 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 IToolbarAddingMenu
+from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.interfaces import MANAGE_SYSTEM_PERMISSION
+from zope.component.interfaces import ISite
+
+# import packages
+from pyams_content.workflow.task import ContentArchiverTask
+from pyams_form.form import AJAXAddForm
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_scheduler.zmi.scheduler import SchedulerTasksTable
+from pyams_scheduler.zmi.task import TaskBaseAddForm
+from pyams_skin.viewlet.toolbar import ToolbarMenuItem
+from pyams_viewlet.viewlet import viewlet_config
+from pyramid.view import view_config
+
+from pyams_content import _
+
+
+@viewlet_config(name='add-content-archiver-task.menu', context=ISite, layer=IPyAMSLayer,
+ view=SchedulerTasksTable, manager=IToolbarAddingMenu,
+ permission=MANAGE_SYSTEM_PERMISSION, weight=100)
+class ContentArchiverTaskAddMenu(ToolbarMenuItem):
+ """Content archiver task add menu"""
+
+ label = _("Add content archiver task...")
+ label_css_class = 'fa fa-fw fa-archive'
+ url = 'add-content-archiver-task.html'
+ modal_target = True
+
+
+@pagelet_config(name='add-content-archiver-task.html', context=ISite, layer=IPyAMSLayer,
+ permission=MANAGE_SYSTEM_PERMISSION)
+class ContentArchiverTaskAddForm(TaskBaseAddForm):
+ """Content archiver task add form"""
+
+ legend = _("Add automatic content archiver")
+ icon_css_class = 'fa fa-fw fa-archive'
+
+ ajax_handler = 'add-content-archiver-task.json'
+ task_factory = ContentArchiverTask
+
+
+@view_config(name='add-content-archiver-task.json', context=ISite, request_type=IPyAMSLayer,
+ permission=MANAGE_SYSTEM_PERMISSION, renderer='json', xhr=True)
+class ContentArchiverTaskAJAXAddForm(AJAXAddForm, ContentArchiverTaskAddForm):
+ """Content archiver task add form, JSON renderer"""