Added arguments to get versions in sorted order
authorThierry Florac <thierry.florac@onf.fr>
Tue, 19 Jan 2016 10:27:45 +0100
changeset 20 2539b0bc8304
parent 19 31bee5428853
child 21 dc24c94058da
Added arguments to get versions in sorted order
src/pyams_workflow/versions.py
--- a/src/pyams_workflow/versions.py	Tue Jan 19 10:27:09 2016 +0100
+++ b/src/pyams_workflow/versions.py	Tue Jan 19 10:27:45 2016 +0100
@@ -162,7 +162,7 @@
         except KeyError:
             raise VersionError("Missing given version ID {0}".format(version_id))
 
-    def get_versions(self, states=None):
+    def get_versions(self, states=None, sort=False, reverse=False):
         if states:
             if isinstance(states, str):
                 states = (states, )
@@ -171,6 +171,8 @@
                 if state is None:
                     state = '__none__'
                 [versions.add(self[str(version)]) for version in self.versions_by_state.get(state, ())]
+            if sort:
+                versions = sorted(versions, key=lambda x: int(x.__name__), reverse=reverse)
             return versions
         else:
             return (v for k, v in sorted(self.items(), key=lambda x: int(x[0])))