--- a/src/pyams_content/shared/news/__init__.py Mon Jan 18 17:43:34 2016 +0100
+++ b/src/pyams_content/shared/news/__init__.py Mon Jan 18 17:44:04 2016 +0100
@@ -21,12 +21,50 @@
from pyams_content.component.links.interfaces import ILinkContainerTarget
from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
from pyams_content.component.theme.interfaces import IThemesTarget
-from pyams_content.shared.news.interfaces import INewsEvent, IWfNewsEvent, NEWS_CONTENT_TYPE, NEWS_CONTENT_NAME
+from pyams_content.shared.news.interfaces import INewsEvent, IWfNewsEvent, NEWS_CONTENT_TYPE, NEWS_CONTENT_NAME, \
+ DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION, VERSION_DISPLAY
+from pyams_workflow.interfaces import IWorkflowVersions, VersionError, IWorkflowPublicationInfo
+from zope.schema.interfaces import IVocabularyFactory
# import packages
from pyams_content.shared.common import SharedContent, WfSharedContent, register_content_type
-from zope.interface import implementer
+from pyams_utils.date import format_date
+from pyams_utils.request import check_request
+from zope.interface import implementer, provider
from zope.schema.fieldproperty import FieldProperty
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm, getVocabularyRegistry
+
+
+@provider(IVocabularyFactory)
+class WfNewsDisplayedDateVocabulary(SimpleVocabulary):
+ """Base news event vocabulary"""
+
+ def __init__(self, context):
+ request = check_request()
+ terms = []
+ versions = IWorkflowVersions(context)
+ # check for current version
+ first_version_label = request.localizer.translate(VERSION_DISPLAY[DISPLAY_FIRST_VERSION])
+ try:
+ first_version = versions.get_version(1)
+ except VersionError:
+ pass
+ else:
+ info = IWorkflowPublicationInfo(first_version, None)
+ if info is not None and info.publication_effective_date:
+ first_version_label = '{0} ({1})'.format(first_version_label,
+ format_date(info.publication_effective_date))
+ terms.append(SimpleTerm(DISPLAY_FIRST_VERSION, title=first_version_label))
+ # check for current version
+ current_version_label = request.localizer.translate(VERSION_DISPLAY[DISPLAY_CURRENT_VERSION])
+ info = IWorkflowPublicationInfo(context, None)
+ if info is not None and info.publication_effective_date:
+ current_version_label = '{0} ({1})'.format(current_version_label,
+ format_date(info.publication_effective_date))
+ terms.append(SimpleTerm(DISPLAY_CURRENT_VERSION, title=current_version_label))
+ super(WfNewsDisplayedDateVocabulary, self).__init__(terms)
+
+getVocabularyRegistry().register('PyAMS news publication date', WfNewsDisplayedDateVocabulary)
@implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
--- a/src/pyams_content/shared/news/interfaces/__init__.py Mon Jan 18 17:43:34 2016 +0100
+++ b/src/pyams_content/shared/news/interfaces/__init__.py Mon Jan 18 17:44:04 2016 +0100
@@ -49,7 +49,7 @@
displayed_publication_date = Choice(title=_("Displayed publication date"),
description=_("The matching date will be displayed in front-office"),
- vocabulary=VERSION_DISPLAY_VOCABULARY,
+ vocabulary='PyAMS news publication date',
default=DISPLAY_FIRST_VERSION,
required=True)