src/pyams_content/workflow/task.py
changeset 277 9649f8ce3b1c
parent 128 6cdea4a15bfd
child 400 d319362746d1
equal deleted inserted replaced
276:78422a1c4228 277:9649f8ce3b1c
    16 # import standard library
    16 # import standard library
    17 from datetime import datetime
    17 from datetime import datetime
    18 
    18 
    19 # import interfaces
    19 # import interfaces
    20 from hypatia.interfaces import ICatalog
    20 from hypatia.interfaces import ICatalog
    21 from pyams_content.shared.common.interfaces import ISharedTool
    21 from pyams_content.shared.common.interfaces import IBaseSharedTool
    22 from pyams_content.workflow.interfaces import IContentArchiverTask
    22 from pyams_content.workflow.interfaces import IContentArchiverTask
    23 from pyams_i18n.interfaces import II18n
    23 from pyams_i18n.interfaces import II18n
    24 from pyams_sequence.interfaces import ISequentialIdInfo
    24 from pyams_sequence.interfaces import ISequentialIdInfo
    25 from pyams_workflow.interfaces import IWorkflow, IWorkflowInfo
    25 from pyams_workflow.interfaces import IWorkflow, IWorkflowInfo
       
    26 from zope.intid.interfaces import IIntIds
    26 
    27 
    27 # import packages
    28 # import packages
    28 from hypatia.catalog import CatalogQuery
    29 from hypatia.catalog import CatalogQuery
    29 from hypatia.query import Eq, Lt, Any
    30 from hypatia.query import Eq, Lt, Any
    30 from pyams_catalog.query import CatalogResultSet
    31 from pyams_catalog.query import CatalogResultSet
    44     settings_view_name = None
    45     settings_view_name = None
    45 
    46 
    46     def run(self, report):
    47     def run(self, report):
    47         request = check_request()
    48         request = check_request()
    48         translate = request.localizer.translate
    49         translate = request.localizer.translate
       
    50         intids = get_utility(IIntIds)
    49         catalog = get_utility(ICatalog)
    51         catalog = get_utility(ICatalog)
    50         now = gmtime(datetime.utcnow())
    52         now = gmtime(datetime.utcnow())
    51         has_retired = False
    53         has_retired = False
    52         for tool in get_all_utilities_registered_for(ISharedTool):
    54         for tool in get_all_utilities_registered_for(IBaseSharedTool):
    53             workflow = IWorkflow(tool)
    55             workflow = IWorkflow(tool)
    54             params = Eq(catalog['content_type'], tool.shared_content_type) & \
    56             params = Eq(catalog['parents'], intids.register(tool)) & \
    55                      Any(catalog['workflow_state'], workflow.published_states) & \
    57                      Any(catalog['workflow_state'], workflow.published_states) & \
    56                      Lt(catalog['expiration_date'], now)
    58                      Lt(catalog['expiration_date'], now)
    57             for content in CatalogResultSet(CatalogQuery(catalog).query(params)):
    59             for content in CatalogResultSet(CatalogQuery(catalog).query(params)):
    58                 if not has_retired:
    60                 if not has_retired:
    59                     report.write(translate(_("Automatic contents withdrawal:\n")))
    61                     report.write(translate(_("Automatic contents withdrawal:\n")))