src/pyams_content/shared/common/__init__.py
changeset 1028 3a608029647e
parent 951 9395a088cd46
child 1060 29b1aaf9e080
equal deleted inserted replaced
1027:f5244268e151 1028:3a608029647e
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    14 
    14 
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from hypatia.interfaces import ICatalog
    15 from hypatia.interfaces import ICatalog
    20 from persistent import Persistent
    16 from persistent import Persistent
    21 from pyramid.events import subscriber
    17 from pyramid.events import subscriber
    22 from pyramid.interfaces import IWSGIApplicationCreatedEvent
    18 from pyramid.interfaces import IWSGIApplicationCreatedEvent
    23 from pyramid.settings import asbool
    19 from pyramid.settings import asbool
    26 from zope.dublincore.interfaces import IZopeDublinCore
    22 from zope.dublincore.interfaces import IZopeDublinCore
    27 from zope.interface import implementer
    23 from zope.interface import implementer
    28 from zope.intid.interfaces import IIntIds
    24 from zope.intid.interfaces import IIntIds
    29 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    25 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    30 from zope.schema.fieldproperty import FieldProperty
    26 from zope.schema.fieldproperty import FieldProperty
    31 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
    27 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
    32 
    28 
    33 from pyams_content import _
       
    34 # import packages
       
    35 from pyams_content.features.checker import BaseContentChecker
    29 from pyams_content.features.checker import BaseContentChecker
    36 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE, ERROR_VALUE
    30 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
    37 from pyams_content.features.review.interfaces import IReviewComments
    31 from pyams_content.features.review.interfaces import IReviewComments
    38 from pyams_content.interfaces import IBaseContentInfo, OWNER_ROLE, MANAGER_ROLE, CONTRIBUTOR_ROLE, READER_ROLE, \
    32 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, MANAGER_ROLE, OWNER_ROLE, \
    39     GUEST_ROLE
    33     READER_ROLE
    40 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, \
    34 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, ISharedContent, \
    41     IBaseSharedTool, ISharedSite, IWfSharedContentFactory, CONTENT_TYPES_VOCABULARY
    35     ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles
    42 from pyams_i18n.content import I18nManagerMixin
    36 from pyams_i18n.content import I18nManagerMixin
    43 from pyams_i18n.interfaces import II18nManager, II18n
    37 from pyams_i18n.interfaces import II18n, II18nManager
    44 from pyams_portal.interfaces import DESIGNER_ROLE
    38 from pyams_portal.interfaces import DESIGNER_ROLE
    45 from pyams_security.interfaces import IDefaultProtectionPolicy
    39 from pyams_security.interfaces import IDefaultProtectionPolicy
    46 from pyams_security.property import RolePrincipalsFieldProperty
    40 from pyams_security.property import RolePrincipalsFieldProperty
    47 from pyams_security.security import ProtectedObject
    41 from pyams_security.security import ProtectedObject
    48 from pyams_security.utility import get_principal
    42 from pyams_security.utility import get_principal
    49 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo
    43 from pyams_sequence.interfaces import ISequentialIdInfo, ISequentialIdTarget
    50 from pyams_utils.adapter import adapter_config, ContextAdapter
    44 from pyams_utils.adapter import ContextAdapter, adapter_config
    51 from pyams_utils.date import format_datetime
    45 from pyams_utils.date import format_datetime
    52 from pyams_utils.interfaces import VIEW_PERMISSION
    46 from pyams_utils.interfaces import VIEW_PERMISSION
    53 from pyams_utils.property import classproperty, classproperty_support
    47 from pyams_utils.property import classproperty, classproperty_support
    54 from pyams_utils.registry import query_utility, get_utilities_for
    48 from pyams_utils.registry import get_utilities_for, query_utility
    55 from pyams_utils.request import query_request, check_request
    49 from pyams_utils.request import check_request, query_request
    56 from pyams_utils.timezone import tztime
    50 from pyams_utils.timezone import tztime
    57 from pyams_utils.traversing import get_parent
    51 from pyams_utils.traversing import get_parent
    58 from pyams_utils.vocabulary import vocabulary_config
    52 from pyams_utils.vocabulary import vocabulary_config
    59 from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions
    53 from pyams_utils.zodb import volatile_property
       
    54 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, IWorkflowPublicationSupport, \
       
    55     IWorkflowTransitionEvent, IWorkflowVersions
       
    56 
       
    57 from pyams_content import _
    60 
    58 
    61 
    59 
    62 @vocabulary_config(name='PyAMS shared sites')
    60 @vocabulary_config(name='PyAMS shared sites')
    63 class SharedSiteVocabulary(SimpleVocabulary):
    61 class SharedSiteVocabulary(SimpleVocabulary):
    64     """Shared sites vocabulary"""
    62     """Shared sites vocabulary"""
   292 
   290 
   293     @property
   291     @property
   294     def workflow_name(self):
   292     def workflow_name(self):
   295         return get_parent(self, IBaseSharedTool).shared_content_workflow
   293         return get_parent(self, IBaseSharedTool).shared_content_workflow
   296 
   294 
       
   295     @volatile_property
       
   296     def published_version(self):
       
   297         workflow = IWorkflow(self)
       
   298         versions = IWorkflowVersions(self).get_versions(workflow.published_states, sort=True)
       
   299         if versions:
       
   300             return versions[-1]
       
   301 
   297 
   302 
   298 @adapter_config(context=ISharedContent, provides=IBaseContentInfo)
   303 @adapter_config(context=ISharedContent, provides=IBaseContentInfo)
   299 class SharedContentInfoAdapter(ContextAdapter):
   304 class SharedContentInfoAdapter(ContextAdapter):
   300     """Shared content base info adapter"""
   305     """Shared content base info adapter"""
   301 
   306 
   311 @adapter_config(context=ISharedContent, provides=IWorkflow)
   316 @adapter_config(context=ISharedContent, provides=IWorkflow)
   312 def shared_content_workflow_adapter(context):
   317 def shared_content_workflow_adapter(context):
   313     """Shared content workflow adapter"""
   318     """Shared content workflow adapter"""
   314     parent = get_parent(context, IBaseSharedTool)
   319     parent = get_parent(context, IBaseSharedTool)
   315     return query_utility(IWorkflow, name=parent.shared_content_workflow)
   320     return query_utility(IWorkflow, name=parent.shared_content_workflow)
       
   321 
       
   322 
       
   323 @subscriber(IWorkflowTransitionEvent)
       
   324 def handle_workflow_event(event):
       
   325     """Reste target on workflow transition"""
       
   326     content = get_parent(event.object, ISharedContent)
       
   327     if content is not None:
       
   328         del content.published_version