[Zope-CMF] Historical revisions in CMF (was Re: CMF newbiequestions)
Dieter Maurer
dieter@handshake.de
Sun, 30 Mar 2003 09:22:32 +0200
--5WQbovnOO0
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit
Ausum Studio wrote at 2003-3-29 07:58 -0500:
> ....
> ----- Original Message -----
> From: "Dieter Maurer" <dieter@handshake.de>
> > ....
> > I also have a "historical connection" that automatically
> > loads subobjects as of a given historical time.
> > This makes the history mechanism available for structured
> > object, such as folders.
> >
> >
> > If someone it interested, I can make code available.
> >
>
> I am interested. :)
I attach the module.
Use its "Historical" the same way you would use "OFS.History.Historical".
It behaves like the original with the exception that access to
a persistent subobject does not return the current version
of the subobject but that which was current at the historical time.
The same holds true for indirect access to persistent descendants:
you see the subhierarchy as it was at the historical time.
The "_hasSmartHistory" function is part of my "ReadCommited" ZODB patch.
If applied (there is one known problem with respect to transaction
abortion; thus, you may want to wait until this has been sorted out),
you will get more efficient history operations (by a factor of 2)
for "FileStorage".
Dieter
--5WQbovnOO0
Content-Type: application/x-python
Content-Description: "History" module -- an extension to "OFS.History" to provide historical access to persistent subobjects
Content-Disposition: attachment;
filename="History.py"
Content-Transfer-Encoding: base64
IyAgICAgICAkSWQ6IEhpc3RvcnkucHksdiAxLjUgMjAwMy8wMy8yMCAxNDoyNzozNyBkaWV0
ZXIgRXhwICQKJycnSGlzdG9yeSBleHRlbnNpb25zLicnJwoKZnJvbSBPRlMuSGlzdG9yeSBp
bXBvcnQgSHlzdG9yeUphciwgSGlzdG9yaWFuLCBIaXN0b3JpY2FsCmZyb20gc3RydWN0IGlt
cG9ydCBwYWNrLCB1bnBhY2sKZnJvbSBjU3RyaW5nSU8gaW1wb3J0IFN0cmluZ0lPCmZyb20g
Y1BpY2tsZSBpbXBvcnQgVW5waWNrbGVyCmZyb20gWk9EQi5Db25uZWN0aW9uIGltcG9ydCBD
b25uZWN0aW9uCmZyb20gWk9EQi5QT1NFeGNlcHRpb24gaW1wb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