changeset 2698:0a6f74a01646

Fix revert action and xmlrpc call.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 19 Aug 2007 00:04:27 +0200
parents 80cf17344f98
children 98f7c5c64e91
files MoinMoin/PageEditor.py MoinMoin/action/revert.py MoinMoin/xmlrpc/__init__.py
diffstat 3 files changed, 54 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Sat Aug 18 03:58:59 2007 +0200
+++ b/MoinMoin/PageEditor.py	Sun Aug 19 00:04:27 2007 +0200
@@ -63,6 +63,8 @@
     # exceptions for .saveText()
     class SaveError(error.Error):
         pass
+    class RevertError(SaveError):
+        pass
     class AccessDenied(SaveError):
         pass
     class Immutable(AccessDenied):
@@ -627,6 +629,41 @@
             else:
                 return False, _('Could not rename page because of file system error: %s.') % unicode(err)
 
+
+    def revertPage(self, revision):
+        """ Reverts page to the given revision
+
+        @param revision: revision to revert to
+        @type revision: int
+
+        """
+        _ = self.request.getText
+
+        if not self.request.user.may.revert(self.page_name):
+            raise self.RevertError(_('You are not allowed to revert this page!'))
+        elif revision is None:
+            raise self.RevertError(_('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:
+            revstr = '%08d' % revision
+            pg = Page(self.request, self.page_name, rev=revision)
+            msg = self.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT", notify=False)
+
+            # Remove cache entry (if exists)
+            from MoinMoin import caching
+            pg = Page(self.request, self.page_name)
+            key = self.request.form.get('key', ['text_html'])[0]
+            caching.CacheEntry(self.request, pg, key, scope='item').remove()
+            caching.CacheEntry(self.request, pg, "pagelinks", scope='item').remove()
+
+            # Notify observers
+            from MoinMoin.events import PageRevertedEvent, send_event
+            e = PageRevertedEvent(self.request, self.page_name, revision, revstr)
+            send_event(e)
+
+            return msg
+
     def deletePage(self, comment=None):
         """ Delete the current version of the page (making a backup before deletion
             and keeping the backups, logs and attachments).
--- a/MoinMoin/action/revert.py	Sat Aug 18 03:58:59 2007 +0200
+++ b/MoinMoin/action/revert.py	Sun Aug 19 00:04:27 2007 +0200
@@ -11,41 +11,13 @@
 def execute(pagename, request):
     """ 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):
-        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)
+    pg = PageEditor(request, pagename)
 
-        revstr = '%08d' % rev
-        try:
-            msg = newpg.saveText(pg.get_raw_body(), 0, extra=revstr, action="SAVE/REVERT", notify=False)
-            pg = newpg
-        except newpg.SaveError, msg:
-            msg = unicode(msg)
-        request.reset()
-
-        key = request.form.get('key', ['text_html'])[0]
+    try:
+        msg = pg.revertPage(rev)
+    except PageEditor.RevertError, error:
+        msg = unicode(error)
 
-        # Remove cache entry (if exists)
-        pg = Page(request, pagename)
-        from MoinMoin import caching
-        caching.CacheEntry(request, pg, key, scope='item').remove()
-        caching.CacheEntry(request, pg, "pagelinks", scope='item').remove()
-
-        # Notify observers
-        from MoinMoin.events import PageRevertedEvent, send_event
-        e = PageRevertedEvent(request, pagename, request.rev, revstr)
-        send_event(e)
-
-    if request.action != "xmlrpc":
-        pg.send_page(msg=msg)
-
+    request.reset()
+    pg.send_page(msg=msg)
--- a/MoinMoin/xmlrpc/__init__.py	Sat Aug 18 03:58:59 2007 +0200
+++ b/MoinMoin/xmlrpc/__init__.py	Sun Aug 19 00:04:27 2007 +0200
@@ -570,13 +570,16 @@
         if not self.request.user.may.write(pagename):
             return xmlrpclib.Fault(1, "You are not allowed to edit this page")
 
-        from MoinMoin.action import revert
-        self.request.rev = int(self._instr(revision))
-        msg = revert.execute(pagename, self.request)
-        if msg:
-            return xmlrpclib.Fault(1, "Revert failed: %s" % (msg, ))
-        else:
-            return xmlrpclib.Boolean(1)
+        from MoinMoin.PageEditor import PageEditor
+        rev = int(self._instr(revision))
+        editor = PageEditor(self.request, pagename)
+
+        try:
+            editor.revertPage(rev)
+        except PageEditor.SaveError, error:
+            return xmlrpclib.Fault(1, "Revert failed: %s" % (str(error), ))
+
+        return xmlrpclib.Boolean(1)
 
     def xmlrpc_searchPages(self, query_string):
         """ Searches pages for query_string.