[Zope-Checkins] CVS: Zope2 - Undo.py:1.25
Jim Fulton
jim@digicool.com
Thu, 12 Apr 2001 14:49:03 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/App
In directory korak:/tmp/cvs-serv20047
Modified Files:
Undo.py
Log Message:
Carry descriptive info in the input form so that, when a transaction
is undone, the application can note the fact in the undoing
transaction. This is extremely desireable when doing transactional
undo, so that you can keep track of what the undoing transactions
actually (un)did.
--- Updated File Undo.py in package Zope2 --
--- Undo.py 2001/01/11 22:42:42 1.24
+++ Undo.py 2001/04/12 18:49:02 1.25
@@ -91,6 +91,7 @@
from DateTime import DateTime
from string import atof, find, atoi, split, rfind, join
from AccessControl import getSecurityManager
+import base64
class UndoSupport(ExtensionClass.Base):
@@ -164,16 +165,34 @@
r=Globals.UndoManager.undoInfo(
first_transaction, last_transaction, spec)
- for d in r: d['time']=DateTime(d['time'])
+ encode = base64.encodestring
+ for d in r:
+ d['time']=t=DateTime(d['time'])
+ desc = d['description']
+ tid=d['id']
+ if desc:
+ desc = split(desc)
+ d1=desc[0]
+ desc = join(desc[1:])
+ if len(desc) > 60: desc = desc[:56]+' ...'
+ tid = "%s %s %s %s" % (encode64(tid), t, d1, desc)
+ else:
+ tid = "%s %s" % (encode64(tid), t)
+ d['id']=tid
+
return r
def manage_undo_transactions(self, transaction_info, REQUEST=None):
"""
"""
undo=Globals.UndoManager.undo
- for i in transaction_info: undo(i)
-
+ for tid in transaction_info:
+ tid=split(tid)
+ if tid:
+ get_transaction().note("Undo %s" % join(tid[1:]))
+ tid=decode64(tid[0])
+ undo(tid)
if REQUEST is None: return
REQUEST['RESPONSE'].redirect("%s/manage_UndoForm" % REQUEST['URL1'])
@@ -195,3 +214,21 @@
return rval
+
+########################################################################
+# Blech, need this cause binascii.b2a_base64 is too pickly
+
+import binascii
+
+def encode64(s, b2a=binascii.b2a_base64):
+ if len(s) < 58: return b2a(s)
+ r=[]; a=r.append
+ for i in range(0, len(s), 57):
+ a(b2a(s[i:i+57])[:-1])
+ return join(r,'')
+
+def decode64(s, a2b=binascii.a2b_base64):
+ __traceback_info__=len(s), `s`
+ return a2b(s+'\n')
+
+del binascii