src/pyams_content/shared/common/__init__.py
changeset 1393 9479901b53a5
parent 1333 e10cf8795ff2
child 1456 a07b27effd38
equal deleted inserted replaced
1392:1d8fd5a53ced 1393:9479901b53a5
    23 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    23 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
    24 from zope.schema.fieldproperty import FieldProperty
    24 from zope.schema.fieldproperty import FieldProperty
    25 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
    25 from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
    26 
    26 
    27 from pyams_content.features.checker import BaseContentChecker
    27 from pyams_content.features.checker import BaseContentChecker
    28 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, MISSING_LANG_VALUE, MISSING_VALUE
    28 from pyams_content.features.checker.interfaces import ERROR_VALUE, IContentChecker, \
       
    29     MISSING_LANG_VALUE, MISSING_VALUE
    29 from pyams_content.features.review.interfaces import IReviewComments
    30 from pyams_content.features.review.interfaces import IReviewComments
    30 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, MANAGER_ROLE, OWNER_ROLE, \
    31 from pyams_content.interfaces import CONTRIBUTOR_ROLE, GUEST_ROLE, IBaseContentInfo, \
    31     READER_ROLE
    32     MANAGER_ROLE, OWNER_ROLE, READER_ROLE
    32 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, ISharedContent, \
    33 from pyams_content.shared.common.interfaces import CONTENT_TYPES_VOCABULARY, IBaseSharedTool, \
    33     ISharedSite, IWfSharedContent, IWfSharedContentFactory, IWfSharedContentRoles, SHARED_CONTENT_TYPES_VOCABULARY
    34     ISharedContent, ISharedSite, IWfSharedContent, IWfSharedContentFactory, \
       
    35     IWfSharedContentRoles, SHARED_CONTENT_TYPES_VOCABULARY
       
    36 from pyams_content.shared.common.interfaces.zmi import IDashboardTypeColumnValue
    34 from pyams_i18n.content import I18nManagerMixin
    37 from pyams_i18n.content import I18nManagerMixin
    35 from pyams_i18n.interfaces import II18n, II18nManager
    38 from pyams_i18n.interfaces import II18n, II18nManager
    36 from pyams_portal.interfaces import DESIGNER_ROLE
    39 from pyams_portal.interfaces import DESIGNER_ROLE
    37 from pyams_security.interfaces import IDefaultProtectionPolicy
    40 from pyams_security.interfaces import IDefaultProtectionPolicy
    38 from pyams_security.property import RolePrincipalsFieldProperty
    41 from pyams_security.property import RolePrincipalsFieldProperty
    47 from pyams_utils.request import check_request, query_request
    50 from pyams_utils.request import check_request, query_request
    48 from pyams_utils.timezone import tztime
    51 from pyams_utils.timezone import tztime
    49 from pyams_utils.traversing import get_parent
    52 from pyams_utils.traversing import get_parent
    50 from pyams_utils.vocabulary import vocabulary_config
    53 from pyams_utils.vocabulary import vocabulary_config
    51 from pyams_utils.zodb import volatile_property
    54 from pyams_utils.zodb import volatile_property
    52 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, IWorkflowPublicationSupport, \
    55 from pyams_workflow.interfaces import IObjectClonedEvent, IWorkflow, \
    53     IWorkflowTransitionEvent, IWorkflowVersions
    56     IWorkflowPublicationSupport, IWorkflowTransitionEvent, IWorkflowVersions
    54 
    57 
    55 
    58 
    56 __docformat__ = 'restructuredtext'
    59 __docformat__ = 'restructuredtext'
    57 
    60 
    58 from pyams_content import _
    61 from pyams_content import _
    64 
    67 
    65     interface = ISharedSite
    68     interface = ISharedSite
    66 
    69 
    67     def __init__(self, context):
    70     def __init__(self, context):
    68         request = query_request()
    71         request = query_request()
    69         super(SharedSiteVocabulary, self).__init__([SimpleTerm(v, title=II18n(t).query_attribute('title',
    72         super(SharedSiteVocabulary, self).__init__(
    70                                                                                                  request=request))
    73             [SimpleTerm(v, title=II18n(t).query_attribute('title',
    71                                                     for v, t in get_utilities_for(self.interface)])
    74                                                           request=request))
       
    75              for v, t in get_utilities_for(self.interface)])
    72 
    76 
    73 
    77 
    74 #
    78 #
    75 # Content types management
    79 # Content types management
    76 #
    80 #
   131 
   135 
   132 #
   136 #
   133 # Workflow shared content class and adapters
   137 # Workflow shared content class and adapters
   134 #
   138 #
   135 
   139 
   136 @implementer(IDefaultProtectionPolicy, IWfSharedContent, IWfSharedContentRoles, IWorkflowPublicationSupport)
   140 @implementer(IDefaultProtectionPolicy, IWfSharedContent, IWfSharedContentRoles,
       
   141              IWorkflowPublicationSupport)
   137 class WfSharedContent(ProtectedObject, Persistent, Contained, I18nManagerMixin):
   142 class WfSharedContent(ProtectedObject, Persistent, Contained, I18nManagerMixin):
   138     """Shared data content class"""
   143     """Shared data content class"""
   139 
   144 
   140     __roles__ = (OWNER_ROLE, MANAGER_ROLE, CONTRIBUTOR_ROLE, DESIGNER_ROLE, READER_ROLE, GUEST_ROLE)
   145     __roles__ = (OWNER_ROLE, MANAGER_ROLE, CONTRIBUTOR_ROLE, DESIGNER_ROLE, READER_ROLE,
       
   146                  GUEST_ROLE)
   141     roles_interface = IWfSharedContentRoles
   147     roles_interface = IWfSharedContentRoles
   142 
   148 
   143     owner = RolePrincipalsFieldProperty(IWfSharedContentRoles['owner'])
   149     owner = RolePrincipalsFieldProperty(IWfSharedContentRoles['owner'])
   144     managers = RolePrincipalsFieldProperty(IWfSharedContentRoles['managers'])
   150     managers = RolePrincipalsFieldProperty(IWfSharedContentRoles['managers'])
   145     contributors = RolePrincipalsFieldProperty(IWfSharedContentRoles['contributors'])
   151     contributors = RolePrincipalsFieldProperty(IWfSharedContentRoles['contributors'])
   277         for attr in ('title', 'short_name', 'description'):
   283         for attr in ('title', 'short_name', 'description'):
   278             for lang in langs:
   284             for lang in langs:
   279                 value = i18n.get_attribute(attr, lang, request)
   285                 value = i18n.get_attribute(attr, lang, request)
   280                 if not value:
   286                 if not value:
   281                     if len(langs) == 1:
   287                     if len(langs) == 1:
   282                         output.append(missing_value.format(field=translate(IWfSharedContent[attr].title)))
   288                         output.append(
       
   289                             missing_value.format(field=translate(IWfSharedContent[attr].title)))
   283                     else:
   290                     else:
   284                         output.append(missing_lang_value.format(field=translate(IWfSharedContent[attr].title),
   291                         output.append(missing_lang_value.format(
   285                                                                 lang=lang))
   292                             field=translate(IWfSharedContent[attr].title),
       
   293                             lang=lang))
   286                 else:
   294                 else:
   287                     length = len(value)
   295                     length = len(value)
   288                     if (attr == 'title') and (length < 40 or length > 66):
   296                     if (attr == 'title') and (length < 40 or length > 66):
   289                         output.append(translate(ERROR_VALUE).format(
   297                         output.append(translate(ERROR_VALUE).format(
   290                             field=translate(IWfSharedContent[attr].title),
   298                             field=translate(IWfSharedContent[attr].title),
   291                             message=translate(_("title length should be between 40 and 66 characters ({length} "
   299                             message=translate(
   292                                                 "actually)")).format(length=length)
   300                                 _("title length should be between 40 and 66 characters ({length} "
       
   301                                   "actually)")).format(length=length)
   293                         ))
   302                         ))
   294         if not self.context.keywords:
   303         if not self.context.keywords:
   295             output.append(missing_value.format(field=translate(IWfSharedContent['keywords'].title)))
   304             output.append(
       
   305                 missing_value.format(field=translate(IWfSharedContent['keywords'].title)))
   296         return output
   306         return output
   297 
   307 
   298 
   308 
   299 #
   309 #
   300 # Main shared content class and adapters
   310 # Main shared content class and adapters