[Zope-Coders] Re: [CMF-checkins] CVS: CMF/CMFStaging CMF/CMFStaging - Imported sources
Florent Guillaume
fg@nuxeo.com
Thu, 16 May 2002 14:47:18 +0000 (UTC)
Brian Lloyd <brian@zope.com> wrote:
> ...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:
Ok thanks a lot. I hadn't looked deep enough at that part.
Thanks for the sample code too.
Very interesting indeed ;-)
Florent
> 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)
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com