src/pyams_workflow/content.py
changeset 71 f782ba6a001b
parent 63 66d25a5fa1d3
child 77 91e0b2a7a544
equal deleted inserted replaced
70:09800bab28db 71:f782ba6a001b
    20 from pyams_security.interfaces import ISecurityManager
    20 from pyams_security.interfaces import ISecurityManager
    21 from pyams_utils.interfaces import VIEW_PERMISSION
    21 from pyams_utils.interfaces import VIEW_PERMISSION
    22 from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflowPublicationInfo, IWorkflow, IWorkflowVersions, \
    22 from pyams_workflow.interfaces import IWorkflowManagedContent, IWorkflowPublicationInfo, IWorkflow, IWorkflowVersions, \
    23     IWorkflowPublicationSupport, IObjectClonedEvent, IWorkflowState, VersionError, VERSION_DISPLAY, \
    23     IWorkflowPublicationSupport, IObjectClonedEvent, IWorkflowState, VersionError, VERSION_DISPLAY, \
    24     DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION
    24     DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION
    25 from zope.annotation.interfaces import IAnnotations
       
    26 from zope.dublincore.interfaces import IZopeDublinCore
    25 from zope.dublincore.interfaces import IZopeDublinCore
    27 
    26 
    28 # import packages
    27 # import packages
    29 from persistent import Persistent
    28 from persistent import Persistent
    30 from pyams_utils.adapter import adapter_config
    29 from pyams_utils.adapter import adapter_config, get_annotation_adapter
    31 from pyams_utils.date import format_datetime, format_date, SH_DATE_FORMAT
    30 from pyams_utils.date import format_datetime, format_date, SH_DATE_FORMAT
    32 from pyams_utils.registry import get_utility
    31 from pyams_utils.registry import get_utility
    33 from pyams_utils.request import check_request
    32 from pyams_utils.request import check_request
    34 from pyams_utils.timezone import gmtime, tztime, GMT
    33 from pyams_utils.timezone import gmtime, tztime, GMT
    35 from pyams_utils.traversing import get_parent
    34 from pyams_utils.traversing import get_parent
    36 from pyams_utils.vocabulary import vocabulary_config
    35 from pyams_utils.vocabulary import vocabulary_config
    37 from pyams_workflow.versions import WorkflowHistoryItem
    36 from pyams_workflow.versions import WorkflowHistoryItem
    38 from pyramid.events import subscriber
    37 from pyramid.events import subscriber
    39 from pyramid.threadlocal import get_current_registry
       
    40 from zope.container.contained import Contained
    38 from zope.container.contained import Contained
    41 from zope.interface import implementer
    39 from zope.interface import implementer
    42 from zope.lifecycleevent import ObjectCreatedEvent
       
    43 from zope.location import locate
       
    44 from zope.schema.fieldproperty import FieldProperty
    40 from zope.schema.fieldproperty import FieldProperty
    45 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    41 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    46 
    42 
    47 from pyams_workflow import _
    43 from pyams_workflow import _
    48 
    44 
   198 
   194 
   199 
   195 
   200 @adapter_config(context=IWorkflowPublicationSupport, provides=IWorkflowPublicationInfo)
   196 @adapter_config(context=IWorkflowPublicationSupport, provides=IWorkflowPublicationInfo)
   201 def workflow_content_publication_info_factory(context):
   197 def workflow_content_publication_info_factory(context):
   202     """Workflow content info factory"""
   198     """Workflow content info factory"""
   203     annotations = IAnnotations(context)
   199     return get_annotation_adapter(context, WORKFLOW_CONTENT_KEY, WorkflowContentPublicationInfo)
   204     info = annotations.get(WORKFLOW_CONTENT_KEY)
       
   205     if info is None:
       
   206         info = annotations[WORKFLOW_CONTENT_KEY] = WorkflowContentPublicationInfo()
       
   207         registry = get_current_registry()
       
   208         registry.notify(ObjectCreatedEvent(info))
       
   209         locate(info, context)
       
   210     return info
       
   211 
   200 
   212 
   201 
   213 @subscriber(IObjectClonedEvent)
   202 @subscriber(IObjectClonedEvent)
   214 def handle_cloned_object(event):
   203 def handle_cloned_object(event):
   215     """Add comment when an object is cloned"""
   204     """Add comment when an object is cloned"""