[Zope-Coders] Re: [CMF-checkins] CVS: CMF/CMFStaging CMF/CMFStaging - Imported sources

Brian Lloyd brian@zope.com
Wed, 15 May 2002 16:39:40 -0400


> Yum yum, I've had a look at that and ZopeVersionControl, looks quite
> interesting. And does in a much cleaner way what we do by hand for a
> project here...
>
> <snip>
>
> I have a question about ZopeVersionControl too: how would one go within
> this framework to implement traversal to a given revision ? What I mean
> by that is, that using a syntax like http://foo.com/bar;version=2.3 or a
> cookie or an URL parameter one would get to that object's version. Is it
> at all possible ?

Hi Florent -

If you look at the version control interface:

http://cvs.zope.org/Products/ZopeVersionControl/IVersionControl.py?rev=1.2&c
ontent-type=text/vnd.viewcvs-markup


...you'll see a getVersionOfResource call (that is implemented by
the Repository). You could pretty easily implement a traversal
hook to get directly addressable versions. A quick, untested
example:


class FolderThatSupportsVersionURLs(Folder):

  def __bobo_traverse__(self, REQUEST, name=None):
      # Split the object name and version info, and get
      # the named object.
      version_id = None
      parts = name.split(';')
      if len(parts) > 1:
          name = parts[0]
          version_id = parts[1]

      # Note I'm omitting some error checking :)
      theObject = getattr(self, name)

      # Get the ref to the repository somehow, and get the
      # version info (bookkeeping) for the object we need a
      # version of. We'll need the history_id (identity within
      # the repository) to get an arbitrary version using the
      # getVersionOfResource api.
      repository = self.getRepository()
      info = repository.getVersionInfo(theObject)
      history_id = info.history_id

      # Get the requested object version from the repository
      theVersion = repository.getVersionOfResource(
                     history_id,
                     version_id
                   )

      # Do acquisition wrapping of the version of the object.
      return theVersion.__of__(self)



Brian Lloyd        brian@zope.com
V.P. Engineering   540.361.1716
Zope Corporation   http://www.zope.com