Added readonly attributes for creation and last modification labels
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 11:46:22 +0200
changeset 105 338c87104ede
parent 104 b5426d5f0990
child 106 b82200b101a9
Added readonly attributes for creation and last modification labels
src/pyams_content/shared/common/__init__.py
src/pyams_content/shared/common/interfaces/__init__.py
--- a/src/pyams_content/shared/common/__init__.py	Wed Jul 12 11:45:17 2017 +0200
+++ b/src/pyams_content/shared/common/__init__.py	Wed Jul 12 11:46:22 2017 +0200
@@ -34,9 +34,12 @@
 from pyams_i18n.content import I18nManagerMixin
 from pyams_security.property import RolePrincipalsFieldProperty
 from pyams_security.security import ProtectedObject
+from pyams_security.utility import get_principal
 from pyams_utils.adapter import adapter_config, ContextAdapter
+from pyams_utils.date import format_datetime
 from pyams_utils.registry import query_utility
 from pyams_utils.request import query_request, check_request
+from pyams_utils.timezone import tztime
 from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
 from pyramid.events import subscriber
@@ -47,6 +50,8 @@
 from zope.schema.fieldproperty import FieldProperty
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 
+from pyams_content import _
+
 
 #
 # Content types management
@@ -114,6 +119,22 @@
         versions = IWorkflowVersions(self)
         return versions.get_version(1).creator
 
+    @property
+    def creation_label(self):
+        request = check_request()
+        translate = request.localizer.translate
+        return translate(_('{date} by {principal}')).format(
+            date=format_datetime(tztime(IBaseContentInfo(self).created_date)),
+            principal=get_principal(request, self.creator).title)
+
+    @property
+    def last_update_label(self):
+        request = check_request()
+        translate = request.localizer.translate
+        return translate(_('{date} by {principal}')).format(
+            date=format_datetime(tztime(IBaseContentInfo(self).modified_date)),
+            principal=get_principal(request, self.last_modifier).title)
+
 
 @subscriber(IObjectModifiedEvent, context_selector=IWfSharedContent)
 def handle_modified_shared_content(event):
--- a/src/pyams_content/shared/common/interfaces/__init__.py	Wed Jul 12 11:45:17 2017 +0200
+++ b/src/pyams_content/shared/common/interfaces/__init__.py	Wed Jul 12 11:46:22 2017 +0200
@@ -27,7 +27,7 @@
 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
+from zope.schema import Choice, Bool, Text, TextLine
 
 from pyams_content import _
 
@@ -102,6 +102,9 @@
                             required=True,
                             readonly=True)
 
+    creation_label = TextLine(title=_("Version creation"),
+                              readonly=True)
+
     modifiers = PrincipalsSet(title=_("Version modifiers"),
                               description=_("List of principals who modified this content"),
                               required=False)
@@ -110,6 +113,9 @@
                               description=_("Last principal who modified this content"),
                               required=False)
 
+    last_update_label = TextLine(title=_("Last update"),
+                                 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 "