Added publication fields
authorThierry Florac <thierry.florac@onf.fr>
Mon, 18 Jan 2016 16:11:40 +0100
changeset 11 20bb3019612a
parent 10 cd69b40debd7
child 12 0cb4470d7eb6
Added publication fields
src/pyams_content/shared/common/__init__.py
src/pyams_content/shared/common/interfaces/__init__.py
--- a/src/pyams_content/shared/common/__init__.py	Mon Jan 18 16:10:52 2016 +0100
+++ b/src/pyams_content/shared/common/__init__.py	Mon Jan 18 16:11:40 2016 +0100
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_i18n.content import I18nManagerMixin
 
 __docformat__ = 'restructuredtext'
 
@@ -20,28 +19,33 @@
 from hypatia.interfaces import ICatalog
 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedContent, ISharedTool
 from pyams_content.interfaces import IBaseContentInfo
-from pyams_i18n.interfaces import II18nManager
-from pyams_security.interfaces import IDefaultProtectionPolicy
+from pyams_security.interfaces import IDefaultProtectionPolicy, ISecurityManager
 from pyams_sequence.interfaces import ISequentialIdTarget, ISequentialIdInfo
 from pyams_utils.interfaces import VIEW_PERMISSION
-from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions
+from pyams_workflow.interfaces import IWorkflowPublicationSupport, IWorkflow, IObjectClonedEvent, IWorkflowVersions, \
+    IWorkflowPublicationInfo
 from zope.dublincore.interfaces import IZopeDublinCore
 from zope.intid.interfaces import IIntIds
 from zope.lifecycleevent.interfaces import IObjectModifiedEvent
 
 # import packages
 from persistent import Persistent
+from pyams_i18n.content import I18nManagerMixin
 from pyams_security.property import RolePrincipalsFieldProperty
 from pyams_security.security import ProtectedObject
 from pyams_utils.adapter import adapter_config, ContextAdapter
-from pyams_utils.registry import query_utility
-from pyams_utils.request import query_request
+from pyams_utils.date import format_datetime
+from pyams_utils.registry import query_utility, get_utility
+from pyams_utils.request import query_request, check_request
+from pyams_utils.timezone import tztime
 from pyams_utils.traversing import get_parent
 from pyramid.events import subscriber
 from zope.container.contained import Contained
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
+from pyams_content import _
+
 
 #
 # Content types management
@@ -78,6 +82,8 @@
     short_name = FieldProperty(IWfSharedContent['short_name'])
     creator = FieldProperty(IWfSharedContent['creator'])
     modifiers = FieldProperty(IWfSharedContent['modifiers'])
+    last_modifier = FieldProperty(IWfSharedContent['last_modifier'])
+    publisher = FieldProperty(IWfSharedContent['publisher'])
     description = FieldProperty(IWfSharedContent['description'])
     keywords = FieldProperty(IWfSharedContent['keywords'])
     notepad = FieldProperty(IWfSharedContent['notepad'])
@@ -87,6 +93,14 @@
         versions = IWorkflowVersions(self)
         return versions.get_version(1).creator
 
+    @property
+    def publication(self):
+        request = check_request()
+        auth = get_utility(ISecurityManager)
+        return request.localizer.translate(_('{date} by {principal}')).format(
+            date=format_datetime(tztime(IWorkflowPublicationInfo(self).publication_date), request=request),
+            principal=auth.get_principal(self.publisher).title)
+
 
 @subscriber(IObjectModifiedEvent, context_selector=IWfSharedContent)
 def handle_modified_shared_content(event):
@@ -102,6 +116,7 @@
             catalog = query_utility(ICatalog)
             intids = query_utility(IIntIds)
             catalog['modifiers'].reindex_doc(intids.register(content), content)
+        content.last_modifier = principal_id
 
 
 @subscriber(IObjectClonedEvent, context_selector=IWfSharedContent)
--- a/src/pyams_content/shared/common/interfaces/__init__.py	Mon Jan 18 16:10:52 2016 +0100
+++ b/src/pyams_content/shared/common/interfaces/__init__.py	Mon Jan 18 16:11:40 2016 +0100
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_utils.schema import TextLineListField
 
 __docformat__ = 'restructuredtext'
 
@@ -25,9 +24,10 @@
 # import packages
 from pyams_i18n.schema import I18nTextField
 from pyams_security.schema import Principal, PrincipalsSet
+from pyams_utils.schema import TextLineListField
 from zope.container.constraints import containers, contains
 from zope.interface import Interface, Attribute
-from zope.schema import Choice, Bool, Text, Datetime
+from zope.schema import Choice, Bool, Text, TextLine
 
 from pyams_content import _
 
@@ -100,6 +100,19 @@
                               description=_("List of principals who modified this content"),
                               required=False)
 
+    last_modifier = Principal(title=_("Last modifier"),
+                              description=_("Last principal who modified this content"),
+                              required=False)
+
+    publisher = Principal(title=_("Publisher"),
+                          description=_("Name of the manager who published the document"),
+                          required=False)
+
+    publication = TextLine(title=_("Publication"),
+                           description=_("Last publication date and actor"),
+                           required=False,
+                           readonly=True)
+
     description = I18nTextField(title=_("Description"),
                                 description=_("The content's description is 'hidden' into HTML's page headers; but it "
                                               "can be seen, for example, in some search engines results as content's "