[Zope3-checkins] CVS: Zope3/src/zope/app/browser - undo.py:1.7 undo_log.pt:1.6

Anthony Baxter anthony@interlink.com.au
Thu, 10 Jul 2003 08:42:47 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser
In directory cvs.zope.org:/tmp/cvs-serv9651

Modified Files:
	undo.py undo_log.pt 
Log Message:
Made the 'Undo' tab considerably more useful. You can choose to see just
your own transactions, or everyone's (default to just your own), you can
see more than the last 20 transactions. zodb's undoInfo supported 
passing through filter specifications, but this wasn't hooked up properly.

There's an outstanding issue with the username that's in the zodb
transaction 'user' field - it's being concatenated together with a 
'path' that's never set and defaults to '/ '. For now, all the 
unpleasantness is isolated in undo_log.pt, along with a comment 
with more details. Will try to fix this properly tomorrow.

A bunch of tests to check that the specification stuff is passed
through correctly. More tests to test_undo.py to provide better 
test coverage are needed.


=== Zope3/src/zope/app/browser/undo.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/browser/undo.py:1.6	Wed Jul  9 21:32:13 2003
+++ Zope3/src/zope/app/browser/undo.py	Thu Jul 10 08:42:12 2003
@@ -47,7 +47,7 @@
     # Implementation methods for interface
     # zope.app.interfaces.undo.IUndoManager.
 
-    def getUndoInfo(self):
+    def getUndoInfo(self, first=0, last=-20, user_name=None):
         '''See interface IUndoManager'''
 
         # Entries are a list of dictionaries, containing
@@ -56,19 +56,24 @@
         # time        -> unix timestamp of last access
         # description -> transaction description
 
-        entries = self.__db.undoInfo()
-
-        # We walk through the entries, (possibly removing some)
-        # and augmenting the dictionaries with some additional
-        # items (such as datetime, a useful form of the unix timestamp).
-        # If there is no description provided, we provide one.
+        if user_name is not None:
+            # !?&%!! The 'user' in the transactions is some combination
+            # of 'path' and 'user'. 'path' seems to only ever be '/' at
+            # the moment - I can't find anything that calls it :-(
+            # At the moment the path is hacked onto the user_name in the 
+            # PageTemplate 'undo_log.pt' (to minimise the nastiness).
+            specification = {'user_name':user_name}
+        else:
+            specification = None
+        entries = self.__db.undoInfo(first, last, specification)
+
+        # We walk through the entries, augmenting the dictionaries 
+        # with some additional items (at the moment, datetime, a useful 
+        # form of the unix timestamp).
 
         for e in entries:
             e['datetime'] = datetime.fromtimestamp(e['time'])
 
-        # Here we'd filter out ones we don't care about (for instance,
-        # to show only entries from the current user).
-
         return entries
 
 
@@ -98,6 +103,6 @@
         if REQUEST is not None:
             REQUEST.response.redirect('index.html')
 
-    def getUndoInfo(self):
+    def getUndoInfo(self, first=0, last=-20, user_name=None):
         utility = getUtility(self.context, IUndoManager)
-        return utility.getUndoInfo()
+        return utility.getUndoInfo(first, last, user_name)


=== Zope3/src/zope/app/browser/undo_log.pt 1.5 => 1.6 ===
--- Zope3/src/zope/app/browser/undo_log.pt:1.5	Wed Jul  9 21:32:13 2003
+++ Zope3/src/zope/app/browser/undo_log.pt	Thu Jul 10 08:42:12 2003
@@ -9,7 +9,7 @@
 <body>
 <div metal:fill-slot="body">
 
-<form action="@@undo.html" method="post">
+<form action="@@undo.html" method="post" tal:define="first python:int(request.get('first',0)); all python:request.get('all', None)">
 
 <p class="form-help">
 This application's transactional feature allows you to easily undo changes 
@@ -24,26 +24,40 @@
 modified objects that were modified by a selected transaction.
 </p>
 
+<span tal:condition="all">
+<p>You are <span tal:replace="request/user/getId">username</span>, looking at all transactions. <a href="?">View only your own transactions</a>.
+<span tal:omit-tag=""
+   tal:define="global undoInfo python:view.getUndoInfo(first=first)"/></p>
+</span>
+<span tal:condition="not:all">
+<p>You are <span tal:replace="request/user/getId">username</span>, looking at your own transactions.  <a href="?all=yes">View everyone's transactions</a>.
+<!-- This nasty piece of work is needed because user IDs are written to
+     the transaction log with a (bogus?) "path" prepended to the username.
+     see zodb.ztransaction.Transaction.setUser
+     I can't see a way to reconstruct this path right now. I also can't see 
+     anywhere that calls setUser() with a path specified. -->
+<span tal:omit-tag=""
+    tal:define="global undoInfo python:view.getUndoInfo(first=first, user_name='/ '+request.user.getId())"/></p>
+</span>
 
+<p><a tal:attributes="href python:'?first=%s'%(first+20)">View 20 earlier transactions</a></p>
 
 <a name="t_list" />
 
-<table width="100%" cellspacing="0" cellpadding="2" border="0">
+<table width="100%" cellspacing="0" cellpadding="2" border="0" >
 
-  <span tal:define="global undoInfo view/getUndoInfo" />
   <div tal:repeat="undoitem undoInfo">
-  <span tal:condition="repeat/undoitem/odd" ><span tal:define="global rowclass string:row-hilite"/> </span>
-  <span tal:condition="repeat/undoitem/even" ><span tal:define="global rowclass string:row-normal"/> </span>
+  <span tal:condition="repeat/undoitem/odd" ><span tal:define="global rowclass string:content odd"/> </span>
+  <span tal:condition="repeat/undoitem/even" ><span tal:define="global rowclass string:content even"/> </span>
 
   <tr tal:attributes="class rowclass">
     <td width="16" align="left" valign="top">
       <input type="checkbox" name="id_list:list" value="-1" tal:attributes="value undoitem/id"/>
     </td>
-    <td align="left" valign="top">
+    <td tal:attributes="class rowclass" align="left" valign="top">
     <div class="list-item">
      
-     <i tal:condition="not:undoitem/description">
-           no description available</i>
+     <i tal:condition="not:undoitem/description">no description available</i>
      <span tal:condition="undoitem/description" tal:omit-tag=""
            tal:content="undoitem/description">description goes here</span>
      <span tal:condition="undoitem/user_name" tal:omit-tag=""> by