src/pyams_content/shared/common/zmi/summary.py
changeset 137 d17090a555a5
parent 110 991135437798
child 226 51a05a1f4212
equal deleted inserted replaced
136:5d1a29312100 137:d17090a555a5
    12 
    12 
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
       
    17 from datetime import datetime
    17 
    18 
    18 # import interfaces
    19 # import interfaces
    19 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedTool
    20 from pyams_content.shared.common.interfaces import IWfSharedContent, IWfSharedContentRoles, ISharedTool
    20 from pyams_form.interfaces.form import IWidgetForm, IInnerTabForm, IInnerSubForm
    21 from pyams_form.interfaces.form import IWidgetForm, IInnerTabForm, IInnerSubForm
    21 from pyams_skin.interfaces import IInnerPage
    22 from pyams_skin.interfaces import IInnerPage
   167 class SharedContentWorkflowHistorySummary(InnerAdminDisplayForm):
   168 class SharedContentWorkflowHistorySummary(InnerAdminDisplayForm):
   168     """Shared content workflow history summary"""
   169     """Shared content workflow history summary"""
   169 
   170 
   170     legend = _("Content history")
   171     legend = _("Content history")
   171 
   172 
   172     fields = field.Fields(IWfSharedContent).select('first_owner') + \
   173     fields = field.Fields(IWorkflowPublicationInfo).select('first_publication_date') + \
   173              field.Fields(IWorkflowPublicationInfo).select('first_publication_date')
   174              field.Fields(IWfSharedContent).select('first_owner')
   174 
   175 
   175     weight = 40
   176     weight = 40
   176 
   177 
   177     def updateWidgets(self, prefix=None):
   178     def updateWidgets(self, prefix=None):
   178         super(SharedContentWorkflowHistorySummary, self).updateWidgets(prefix)
   179         super(SharedContentWorkflowHistorySummary, self).updateWidgets(prefix)
   179         info = IWorkflowPublicationInfo(self.context)
   180         workflow = IWorkflow(self.context)
   180         self.widgets['first_publication_date'].value = format_datetime(tztime(info.first_publication_date))
   181         state = IWorkflowState(self.context)
       
   182         pub_date = tztime(state.get_first_state_date(workflow.published_states))
       
   183         if pub_date is None:
       
   184             value = '--'
       
   185         else:
       
   186             now = tztime(datetime.utcnow())
       
   187             pub_info = IWorkflowPublicationInfo(self.context)
       
   188             if (pub_info.publication_effective_date is None) or (pub_date >= pub_info.publication_effective_date):
       
   189                 value = format_datetime(tztime(pub_date))
       
   190             else:
       
   191                 if pub_info.publication_effective_date < now:
       
   192                     value = '--'
       
   193                 else:
       
   194                     value = format_datetime(tztime(pub_info.publication_effective_date))
       
   195         self.widgets['first_publication_date'].value = value