changeset 1874:c4eb073a9cca

refactor Save, merge save_raw into send_raw
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 11 Mar 2007 12:37:37 +0100
parents 9117dcbfd624
children 5afb427026ea
files MoinMoin/Page.py MoinMoin/action/Save.py
diffstat 2 files changed, 19 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Sun Mar 11 02:27:24 2007 +0100
+++ b/MoinMoin/Page.py	Sun Mar 11 12:37:37 2007 +0100
@@ -830,8 +830,12 @@
         return subscriber_list
 
 
-    def send_raw(self):
-        """ Output the raw page data (action=raw) """
+    def send_raw(self, content_disposition=None):
+        """ Output the raw page data (action=raw).
+            With no content_disposition, the browser usually just displays the
+            data on the screen, with content_disposition='attachment', it will
+            offer a dialogue to save it to disk (used by Save action).            
+        """
         request = self.request
         request.setHttpHeader("Content-type: text/plain; charset=%s" % config.charset)
         if self.exists():
@@ -842,6 +846,11 @@
             request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(os.path.getmtime(self._text_filename())))
             text = self.get_raw_body()
             text = self.encodeTextMimeType(text)
+            request.setHttpHeader("Content-Length: %d" % len(text))
+            if content_disposition:
+                file_name = "%s.txt" % self.page_name
+                request.setHttpHeader('Content-Disposition: %s; filename="%s"' % (
+                                      content_disposition, file_name))
         else:
             request.setHttpHeader('Status: 404 NOTFOUND')
             text = u"Page %s not found." % self.page_name
@@ -849,30 +858,6 @@
         request.emit_http_headers()
         request.write(text)
 
-
-    def save_raw(self):
-        """ Output the raw page data to a file  """
-        request = self.request
-        request.setHttpHeader("Content-type: text/plain; charset=%s" % config.charset)
-        if self.exists() and request.user.may.read(self.page_name):
-            # use the correct last-modified value from the on-disk file
-            # to ensure cacheability where supported. Because we are sending
-            # RAW (file) content, the file mtime is correct as Last-Modified header.
-            request.setHttpHeader("Status: 200 OK")
-            request.setHttpHeader("Last-Modified: %s" % util.timefuncs.formathttpdate(os.path.getmtime(self._text_filename())))
-            file_name = "%s.txt" % self.page_name
-            text = self.get_raw_body()
-            text = self.encodeTextMimeType(text)
-            request.setHttpHeader("Content-Length: %d" % len(text))
-            request.setHttpHeader('Content-Disposition: %s; filename="%s"' % ('attachment', file_name))
-        else:
-            request.setHttpHeader('Status: 404 NOTFOUND')
-            text = u"Page %s not found." % self.page_name
-
-        request.emit_http_headers()
-        request.write(text)
-
-
     def send_page(self, msg=None, **keywords):
         """ Output the formatted page.
 
--- a/MoinMoin/action/Save.py	Sun Mar 11 02:27:24 2007 +0100
+++ b/MoinMoin/action/Save.py	Sun Mar 11 12:37:37 2007 +0100
@@ -1,17 +1,16 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - Action macro for saving a page
+    MoinMoin - Action for saving a page
 
-    MODIFICATION HISTORY:
-        @copyright: 2007 by Reimar Bauer 
-        @license: GNU GPL, see COPYING for details.
+    @copyright: 2007 by Reimar Bauer 
+    @license: GNU GPL, see COPYING for details.
 """
 
 from MoinMoin.Page import Page
 
 def execute(pagename, request):
-    if request.user.may.read(pagename):
-        thispage = Page(request, pagename)
-        thispage.save_raw()
-
-
+    if not request.user.may.read(pagename):
+        Page(request, pagename).send_page()
+    else:
+        rev = request.rev or 0
+        Page(request, pagename, rev=rev).send_raw(content_disposition='attachment')