Updated multi-versions helpers functions
authorThierry Florac <tflorac@ulthar.net>
Sat, 21 Jul 2018 03:36:59 +0200
changeset 60 932b9f6fa4ac
parent 59 e39db7fc1d3c
child 61 e9f92321f04d
Updated multi-versions helpers functions
src/pyams_sequence/reference.py
--- a/src/pyams_sequence/reference.py	Sat Jul 21 03:36:17 2018 +0200
+++ b/src/pyams_sequence/reference.py	Sat Jul 21 03:36:59 2018 +0200
@@ -69,8 +69,10 @@
 
 def get_last_version(content):
     """Check for last available version"""
-    if handle_workflow and (IWorkflowVersion.providedBy(content) or IWorkflowManagedContent.providedBy(content)):
-        content = IWorkflowVersions(content).get_last_versions()[0]
+    if handle_workflow:
+        versions = IWorkflowVersions(content, None)
+        if versions is not None:
+            content = versions.get_last_versions()[0]
     if ISequentialIdInfo(content, None) is not None:
         return content
     else:
@@ -80,17 +82,15 @@
 def get_visible_version(content):
     """Check for visible version"""
     if handle_workflow:
-        if IWorkflowVersion.providedBy(content) or IWorkflowManagedContent.providedBy(content):
+        versions = IWorkflowVersions(content, None)
+        if versions is not None:
             workflow = IWorkflow(content)
-            versions = IWorkflowVersions(content).get_versions(workflow.published_states, sort=True)
-            if versions:
-                return versions[-1]
+            visible_versions = versions.get_versions(workflow.published_states, sort=True)
+            if visible_versions:
+                return visible_versions[-1]
         publication_info = IWorkflowPublicationInfo(content, None)
         if publication_info is not None:
-            if publication_info.is_visible():
-                return content
-            else:
-                return None
+            return content if publication_info.is_visible() else None
     return content