--- a/src/pyams_workflow/interfaces/__init__.py Wed May 20 12:43:47 2015 +0200
+++ b/src/pyams_workflow/interfaces/__init__.py Wed May 20 12:44:10 2015 +0200
@@ -9,8 +9,6 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.lifecycleevent.interfaces import IObjectCreatedEvent
__docformat__ = 'restructuredtext'
@@ -20,10 +18,12 @@
# import interfaces
from zope.annotation.interfaces import IAttributeAnnotatable
from zope.interface.interfaces import IObjectEvent, ObjectEvent
+from zope.lifecycleevent.interfaces import IObjectCreatedEvent
# import packages
from pyams_security.schema import Principal
from zope.interface import implementer, invariant, Interface, Attribute, Invalid
+from zope.lifecycleevent import ObjectCreatedEvent
from zope.schema import Choice, Datetime, Set, TextLine, Text, List, Object, Int
from pyams_workflow import _
@@ -284,6 +284,9 @@
def get_versions(self, state=None):
"""Get all versions of object known for this (optional) state"""
+ def get_last_versions(self, count=1):
+ """Get last versions of this object. Set count=0 to get all versions."""
+
def add_version(self, content, state):
"""Return new unique version id"""
--- a/src/pyams_workflow/versions.py Wed May 20 12:43:47 2015 +0200
+++ b/src/pyams_workflow/versions.py Wed May 20 12:44:10 2015 +0200
@@ -140,7 +140,13 @@
[versions.add(self[str(version)]) for version in self.versions_by_state.get(state, ())]
return versions
else:
- return self.values()
+ return (v for k, v in sorted(self.items(), key=lambda x: int(x[0])))
+
+ def get_last_versions(self, count=1):
+ result = list((v for k, v in sorted(self.items(), key=lambda x: -int(x[0]))))
+ if count:
+ result = result[:count]
+ return result
def add_version(self, content, state):
self.last_version_id += 1