[Zope-CVS] CVS: Packages/VersionControl - VersionControl.py:1.2 VersionSupport.py:1.2

Brian Lloyd brian@digicool.com
Fri, 19 Oct 2001 14:21:44 -0400


Update of /cvs-repository/Packages/VersionControl
In directory cvs.zope.org:/tmp/cvs-serv31911

Modified Files:
	VersionControl.py VersionSupport.py 
Log Message:
Added getVersionOfObject for demo


=== Packages/VersionControl/VersionControl.py 1.1 => 1.2 ===
         return history.getAllMessageEntries()
 
+
+    def getVersionOfObject(self, object, version_id):
+        """Return the version of object indicated by version_id. If the
+           version_id is None, return the latest version of object. Note
+           that the object returned is totally unwrapped."""
+                # First, make sure object is not already under version control.
+        if not self.isUnderVersionControl(object):
+            raise ValueError(
+                'Object is not under version control.'
+                )
+
+        vinfo = self.getVersionInfo(object)
+        repository_id = vinfo.getRepositoryId()
+        repository = self.getRepository(repository_id)
+        history_id = vinfo.getVersionHistoryId()
+        history = repository.getVersionHistory(history_id)
+        if version_id is None:
+            version_id = history.lastVersionId()
+        version = history.getVersion(version_id)
+
+        # This is a hack and should be changed!
+        vobject = Acquisition.aq_base(version.data)
+        return vobject
+
+
     def replaceObject(self, object, new_object):
         # Note - this is probably not right, which is why I made it a
         # separate method.


=== Packages/VersionControl/VersionSupport.py 1.1 => 1.2 ===
         return VersionControl(self).getAllMessageEntries(self)
 
+    security.declareProtected('Use version control', 'getVersionOfObject')
+    def getVersionOfObject(self, version_id):
+        """Returns a (possibly different) version of the current object,
+           wrapped in the context of the object this is called through.
+           If version_id is None, get the latest revision."""
+        vc = VersionControl(self)
+        return vc.getVersionOfObject(self, version_id)
+
+
     unVC__roles__ = None
     def unVC(self, REQUEST):
         """ """