src/pyams_content/shared/news/__init__.py
changeset 114 7799437055f1
parent 60 da1454d7d358
child 139 99a481dc4c89
equal deleted inserted replaced
113:05caef75bac3 114:7799437055f1
    19 from pyams_content.component.gallery.interfaces import IGalleryContainerTarget
    19 from pyams_content.component.gallery.interfaces import IGalleryContainerTarget
    20 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
    20 from pyams_content.component.extfile.interfaces import IExtFileContainerTarget
    21 from pyams_content.component.links.interfaces import ILinkContainerTarget
    21 from pyams_content.component.links.interfaces import ILinkContainerTarget
    22 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
    22 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget
    23 from pyams_content.component.theme.interfaces import IThemesTarget
    23 from pyams_content.component.theme.interfaces import IThemesTarget
    24 from pyams_content.shared.news.interfaces import INewsEvent, IWfNewsEvent, NEWS_CONTENT_TYPE, NEWS_CONTENT_NAME, \
    24 from pyams_content.shared.news.interfaces import INewsEvent, IWfNewsEvent, NEWS_CONTENT_TYPE, NEWS_CONTENT_NAME
    25     DISPLAY_FIRST_VERSION, DISPLAY_CURRENT_VERSION, VERSION_DISPLAY
       
    26 from pyams_workflow.interfaces import IWorkflowVersions, VersionError, IWorkflowPublicationInfo
       
    27 
    25 
    28 # import packages
    26 # import packages
    29 from pyams_content.shared.common import SharedContent, WfSharedContent, register_content_type
    27 from pyams_content.shared.common import SharedContent, WfSharedContent, register_content_type
    30 from pyams_utils.date import format_date
       
    31 from pyams_utils.request import check_request
       
    32 from pyams_utils.vocabulary import vocabulary_config
       
    33 from zope.interface import implementer
    28 from zope.interface import implementer
    34 from zope.schema.fieldproperty import FieldProperty
       
    35 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
       
    36 
       
    37 
       
    38 @vocabulary_config(name='PyAMS news publication date')
       
    39 class WfNewsDisplayedDateVocabulary(SimpleVocabulary):
       
    40     """Base news event vocabulary"""
       
    41 
       
    42     def __init__(self, context):
       
    43         request = check_request()
       
    44         terms = []
       
    45         versions = IWorkflowVersions(context)
       
    46         # check for current version
       
    47         first_version_label = request.localizer.translate(VERSION_DISPLAY[DISPLAY_FIRST_VERSION])
       
    48         try:
       
    49             first_version = versions.get_version(1)
       
    50         except VersionError:
       
    51             pass
       
    52         else:
       
    53             info = IWorkflowPublicationInfo(first_version, None)
       
    54             if info is not None and info.publication_effective_date:
       
    55                 first_version_label = '{0} ({1})'.format(first_version_label,
       
    56                                                          format_date(info.publication_effective_date))
       
    57         terms.append(SimpleTerm(DISPLAY_FIRST_VERSION, title=first_version_label))
       
    58         # check for current version
       
    59         current_version_label = request.localizer.translate(VERSION_DISPLAY[DISPLAY_CURRENT_VERSION])
       
    60         info = IWorkflowPublicationInfo(context, None)
       
    61         if info is not None and info.publication_effective_date:
       
    62             current_version_label = '{0} ({1})'.format(current_version_label,
       
    63                                                        format_date(info.publication_effective_date))
       
    64         terms.append(SimpleTerm(DISPLAY_CURRENT_VERSION, title=current_version_label))
       
    65         super(WfNewsDisplayedDateVocabulary, self).__init__(terms)
       
    66 
    29 
    67 
    30 
    68 @implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
    31 @implementer(IWfNewsEvent, IParagraphContainerTarget, IThemesTarget, IExtFileContainerTarget, ILinkContainerTarget,
    69              IGalleryContainerTarget)
    32              IGalleryContainerTarget)
    70 class WfNewsEvent(WfSharedContent):
    33 class WfNewsEvent(WfSharedContent):
    71     """Base news event"""
    34     """Base news event"""
    72 
    35 
    73     content_type = NEWS_CONTENT_TYPE
    36     content_type = NEWS_CONTENT_TYPE
    74     content_name = NEWS_CONTENT_NAME
    37     content_name = NEWS_CONTENT_NAME
    75 
    38 
    76     displayed_publication_date = FieldProperty(IWfNewsEvent['displayed_publication_date'])
       
    77     push_end_date = FieldProperty(IWfNewsEvent['push_end_date'])
       
    78 
       
    79 register_content_type(WfNewsEvent)
    39 register_content_type(WfNewsEvent)
    80 
    40 
    81 
    41 
    82 @implementer(INewsEvent)
    42 @implementer(INewsEvent)
    83 class NewsEvent(SharedContent):
    43 class NewsEvent(SharedContent):