changeset 1861:d7812ed6da4c

fix revert action bug when called for current revision
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 09 Mar 2007 00:04:27 +0100
parents 327b23c27532
children f2706da26773
files MoinMoin/action/revert.py
diffstat 1 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/revert.py	Thu Mar 08 18:02:43 2007 +0100
+++ b/MoinMoin/action/revert.py	Fri Mar 09 00:04:27 2007 +0100
@@ -12,22 +12,24 @@
     """ restore another revision of a page as a new current revision """
     from MoinMoin.PageEditor import PageEditor
     _ = request.getText
+    msg = None
+    rev = request.rev
+    pg = Page(request, pagename, rev=rev)
 
     if not request.user.may.revert(pagename):
-        return Page(request, pagename).send_page(
-            msg=_('You are not allowed to revert this page!'))
-
-    rev = request.rev
-    revstr = '%08d' % rev
-    oldpg = Page(request, pagename, rev=rev)
-    pg = PageEditor(request, pagename)
-
-    try:
-        savemsg = pg.saveText(oldpg.get_raw_body(), 0, extra=revstr,
-                              action="SAVE/REVERT")
-    except pg.SaveError, msg:
-        # msg contain a unicode string
-        savemsg = unicode(msg)
-    request.reset()
-    pg.send_page(msg=savemsg)
-
+        msg = _('You are not allowed to revert this page!')
+    elif rev is None:
+        msg = _('You were viewing the current revision of this page when you called the revert action. '
+                'If you want to revert to an older revision, first view that older revision and '
+                'then call revert to this (older) revision again.')
+    else:
+        newpg = PageEditor(request, pagename)
+    
+        revstr = '%08d' % rev
+        try:
+            msg = newpg.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT")
+            pg = newpg
+        except newpg.SaveError, msg:
+            msg = unicode(msg)
+        request.reset()
+    pg.send_page(msg=msg)