--- a/src/pyams_content/shared/common/zmi/header.py Fri Oct 13 08:35:54 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/header.py Fri Oct 13 08:36:16 2017 +0200
@@ -114,30 +114,52 @@
self.state = state_format.format(state=state_label.get_label(context, request, format=False),
principal=security.get_principal(state.state_principal).title)
self.state_date = translate(_("since {date}")).format(date=format_datetime(state.state_date, request=request))
- has_update_state = versions.has_version(workflow.update_states)
- if (state.state not in workflow.update_states and has_update_state) or \
- (state.state in workflow.retired_states and has_update_state):
- target = sorted(versions.get_versions(workflow.update_states),
- key=lambda x: IWorkflowState(x).version_id)[-1]
- if target is not context:
- self.version_link = {
- 'css_class': 'text-danger',
- 'href': absolute_url(target, request, 'admin'),
- 'title': translate(_("access new version"))
- }
- else:
- self.version_link = None
- elif state.state not in workflow.published_states and versions.has_version(workflow.published_states):
- target = sorted(versions.get_versions(workflow.published_states),
- key=lambda x: IWorkflowState(x).version_id,
- reverse=True)[-1]
- self.version_link = {
- 'css_class': 'text-danger',
- 'href': absolute_url(target, request, 'admin'),
- 'title': translate(_("access published version"))
- }
- else:
- self.version_link = None
+ # check for links to other versions
+ links = []
+ draft_versions = sorted(versions.get_versions(workflow.update_states),
+ key=lambda x: IWorkflowState(x).version_id)
+ waiting_versions = sorted(versions.get_versions(workflow.waiting_states),
+ key=lambda x: IWorkflowState(x).version_id)
+ published_versions = sorted(versions.get_versions(workflow.published_states),
+ key=lambda x: IWorkflowState(x).version_id)
+ if (state.version_id > 1) or (state.state != workflow.initial_state):
+ if draft_versions:
+ target = draft_versions[0]
+ if target is not context:
+ links.append({'title': translate(_("access new version")),
+ 'href': absolute_url(target, request, 'admin'),
+ 'css_class': 'text-danger'})
+ elif waiting_versions:
+ target = waiting_versions[-1]
+ if target is not context:
+ links.append({'title': translate(_("access waiting version")),
+ 'href': absolute_url(target, request, 'admin'),
+ 'css_class': 'text-danger'})
+ if published_versions:
+ target = published_versions[0]
+ if target is not context:
+ links.append({'title': translate(_("access published version")),
+ 'href': absolute_url(target, request, 'admin'),
+ 'css_class': 'text-danger'})
+ if state.state not in (workflow.retired_states | workflow.archived_states):
+ retired_versions = sorted(versions.get_versions(workflow.retired_states),
+ key=lambda x: IWorkflowState(x).version_id)
+ if retired_versions:
+ target = retired_versions[-1]
+ if target is not context:
+ links.append({'title': translate(_("access retired version")),
+ 'href': absolute_url(target, request, 'admin'),
+ 'css_class': 'text-danger'})
+ else:
+ archived_versions = sorted(versions.get_versions(workflow.archived_states),
+ key=lambda x: IWorkflowState(x).version_id)
+ if archived_versions:
+ target = archived_versions[-1]
+ if target is not context:
+ links.append({'title': translate(_("access archived version")),
+ 'href': absolute_url(target, request, 'admin'),
+ 'css_class': 'text-danger'})
+ self.versions_links = links
@property
def title(self):
--- a/src/pyams_content/shared/common/zmi/templates/header.pt Fri Oct 13 08:35:54 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/templates/header.pt Fri Oct 13 08:36:16 2017 +0200
@@ -27,10 +27,10 @@
<span class="content-version" tal:content="string:V${view.version_id}">Version</span> =
<span class="content-state" tal:content="structure view.state">state</span> |
<span class="content-state-date" tal:content="view.state_date">state date</span>
- <tal:if define="state_link view.version_link" condition="state_link">|
- <a tal:attributes="class state_link['css_class'];
- href state_link['href'];"
- tal:content="state_link['title']">link</a>
- </tal:if>
+ <tal:loop repeat="link view.versions_links">|
+ <a tal:attributes="class link['css_class'];
+ href link['href'];"
+ tal:content="link['title']">link</a>
+ </tal:loop>
</div>
</tal:block>