changeset 485:36c185629dd3

add download link to message about unknown mime type
author sheep@ghostwheel
date Tue, 07 Oct 2008 19:35:55 +0200
parents 38d18a21fea9
children b0396a89818f
files dandelion/diff.py dandelion/download.py dandelion/editor.py dandelion/history.py dandelion/request.py dandelion/spam.py dandelion/upload.py dandelion/viewer.py dandelion/wiki.py dandelion/word_search.py
diffstat 10 files changed, 49 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/dandelion/diff.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/diff.py	Tue Oct 07 19:35:55 2008 +0200
@@ -12,10 +12,11 @@
 
 mark_re = re.compile('\0[-+^]([^\1\0]*)\1|([^\0\1])')
 
-def diff_action(wiki, request, page):
+def diff_action(wiki, request):
+    page = request.page
     if page.current is None:
         raise NotFound()
-    stream = Stream(diff(wiki, request, page))
+    stream = Stream(diff(wiki, request))
     result = wiki.template("page.html", page, content=stream,
                            title=_(u'Changes of %s') % page.title)
     return Response(result, mimetype="text/html")
@@ -26,12 +27,21 @@
     while True:
         yield None
 
-def diff(wiki, request, page):
+def diff(wiki, request):
+    try:
+        rev = int(request.args["rev"])
+    except (ValueError, KeyError):
+        rev = request.page.current
+    page = request.page[rev]
     data = page.open().readlines()
-    if page.rev == 0:
+    try:
+        other_rev = int(request.args["other"])
+    except (ValueError, KeyError):
+        other_rev = rev-1 
+    if other_rev < 0:
         other_data = ""
     else:
-        other = page[max(page.rev-1, 0)]
+        other = page[other_rev]
         other_data = other.open().readlines()
     diff = difflib._mdiff(other_data, data)
     stack = []
--- a/dandelion/download.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/download.py	Tue Oct 07 19:35:55 2008 +0200
@@ -6,20 +6,22 @@
 from werkzeug import Response, redirect
 from werkzeug.exceptions import NotFound
 
-def robots_action(wiki, request, page):
+def robots_action(wiki, request):
     text = ["User-agent: *\r\n"]
     for action_name in wiki.actions:
         text.append("Disallow: /%s/\r\n" % action_name)
     return Response(text, mimetype="text/plain")
 
-def favicon_action(wiki, request, page):
-    return download_action(wiki, request, wiki["favicon.ico"])
+def favicon_action(wiki, request):
+    request.page = wiki["favicon.ico"]
+    return download_action(wiki, request)
 
-def download_action(wiki, request, page):
+def download_action(wiki, request):
     """ Display the raw content of the page, without any formatting
         or navigation, especially useful for things like images or css.
         If the page doesn't exist, only return error code.
     """
+    page = request.page
     if not page:
         raise NotFound()
     mime = page.get_mime()
@@ -29,7 +31,7 @@
             'Vary': 'Transfer-Encoding',
             'Allow': 'GET, HEAD',
         })
-#    response.add_etag(u"raw-%s-%d" % (page.title, page.rev))
-#    response.last_modified = page.date
+    response.add_etag(u"raw-%s" % (page.title)
+    response.last_modified = page.date
     response.make_conditional(request)
     return response
--- a/dandelion/editor.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/editor.py	Tue Oct 07 19:35:55 2008 +0200
@@ -8,7 +8,8 @@
 
 import wikiparser
 
-def edit_action(wiki, request, page):
+def edit_action(wiki, request):
+    page = request.page
     author = request.get_author()
     preview = u""
     if request.method == 'POST':
--- a/dandelion/history.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/history.py	Tue Oct 07 19:35:55 2008 +0200
@@ -8,11 +8,12 @@
 from werkzeug import Response, redirect
 from werkzeug.exceptions import NotFound
 
-def history_action(wiki, request, page):
+def history_action(wiki, request):
     """ Display the history of changes to a page, with links
         for viewing the revisions and optional diffs, if the
         diff action is available.
     """
+    page = request.page
     if page.current is None:
         raise NotFound()
     stream = wiki.template_stream("history.html", page, changes=list(page))
@@ -20,7 +21,7 @@
                          title="History of %s" % page.title)
     return Response(html, mimetype="text/html")
 
-def changes_action(wiki, request, page):
+def changes_action(wiki, request):
     """ Display list of recent changes in the wiki.
     """
     max_days = 7
@@ -60,11 +61,12 @@
         change['authors'] = authors
     if day['changes']:
         days.append(day)
-    stream = wiki.template_stream("changes.html", page, days=days)
-    html = wiki.template("page.html", page, content=stream, title=wiki.config["wiki", "changes_page"])
+    stream = wiki.template_stream("changes.html", request.page, days=days)
+    html = wiki.template("page.html", request.page, content=stream,
+                         title=wiki.config["wiki", "changes_page"])
     return Response(html, mimetype="text/html")
 
-def rss_action(wiki, request, page):
+def rss_action(wiki, request):
     changes = []
     for page in wiki.history():
         if page.date is not None:
--- a/dandelion/request.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/request.py	Tue Oct 07 19:35:55 2008 +0200
@@ -4,7 +4,7 @@
 import os
 import tempfile
 
-from werkzeug import BaseRequest, ETagRequestMixin
+from werkzeug import BaseRequest, ETagRequestMixin, url_quote, url_unquote
 
 class WikiRequest(BaseRequest, ETagRequestMixin):
     def __init__(self, wiki, environ, populate_request=True, shallow=False):
--- a/dandelion/spam.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/spam.py	Tue Oct 07 19:35:55 2008 +0200
@@ -4,9 +4,10 @@
 from werkzeug import Response, redirect, url_quote
 from werkzeug.exceptions import Forbidden, NotFound
 
-def spam_action(wiki, request, page):
+def spam_action(wiki, request):
     if request.method != 'POST':
         raise Forbidden()
+    page = request.page
     if not page:
         raise NotFound()
     author = request.get_author()
--- a/dandelion/upload.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/upload.py	Tue Oct 07 19:35:55 2008 +0200
@@ -4,7 +4,8 @@
 from werkzeug import Response, redirect, url_quote
 from werkzeug.exceptions import Forbidden
 
-def upload_action(wiki, request, page):
+def upload_action(wiki, request):
+    page = request.page
     author = request.get_author()
     if request.method == 'POST':
         save(wiki, request, page, author)
--- a/dandelion/viewer.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/viewer.py	Tue Oct 07 19:35:55 2008 +0200
@@ -12,7 +12,8 @@
 from template import html_start, html_text, html_end
 from genshi.core import Stream, Markup
 
-def view_action(wiki, request, page):
+def view_action(wiki, request):
+    page = request.page
     if not page:
         return redirect(page.get_url(action="edit"), code=303)
     mime = page.get_mime()
@@ -25,7 +26,8 @@
 
 def binary_viewer(wiki, page):
     return wiki.template("page.html", page,
-        content=u"Can't display page type <i>%s</i>" % escape(page.get_mime()))
+        content=Markup(u"""Can't display page type <i>%s</i>. You can however download it as file here: <a href="%s">%s</a>.""" % (
+    escape(page.get_mime()), page.get_url(action="download"), escape(page.title))))
 
 def text_viewer(wiki, page):
     """Display plain text without eny formatting, with monospaced font."""
--- a/dandelion/wiki.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/wiki.py	Tue Oct 07 19:35:55 2008 +0200
@@ -27,9 +27,10 @@
         
         Also contains some common utility functions.
 
-        >>> from werkzeug import Client, BaseResponse
-        >>> Client(Wiki(None).application, BaseResponse).get('/').status_code in (200, 404)
-        True
+        >>> from werkzeug import Client
+        >>> c = Client(Wiki().application)
+        >>> r = c.get('/')
+        >>> assert(r[1] in ('200 OK', '404 Not found'))
     """
     def __init__(self, cfg=None):
         if cfg is None:
@@ -158,21 +159,11 @@
         try:
             if not self.root_url:
                 self.root_url = req.url_root.strip('/')
-            try:
-                rev = int(req.args["rev"])
-            except (ValueError, KeyError):
-                rev = None
             action = self.actions.get(req.view, self.actions['view'])
             try:
-                response = action(self, req, req.page)
+                response = action(self, req)
             except HTTPException, e:
                 return e
-            if isinstance(response, Response) and req.page:
-                rev = req.page.rev
-                if req.page.rev is None:
-                    rev = req.page.current
-                response.add_etag(u"%s-%s-%d" % (req.view, req.page.title, rev))
-                response.make_conditional(req)
             return response
         finally:
             req.cleanup()
--- a/dandelion/word_search.py	Mon Oct 06 10:24:53 2008 +0200
+++ b/dandelion/word_search.py	Tue Oct 07 19:35:55 2008 +0200
@@ -169,7 +169,7 @@
                       % cgi.escape(m.group(0)), snippet)
     return html
 
-def search_action(wiki, request, page):
+def search_action(wiki, request):
     index = False
     if request.args.get("reindex") is not None:
         reindex(wiki)
@@ -187,9 +187,9 @@
         results = [p.title for p in wiki]
     else:
         results = [title for score, title in result]
-    content = wiki.template_stream("search.html", page,
+    content = wiki.template_stream("search.html", request.page,
                             query=query, results=results,
                             snippet=lambda title: snippet(wiki, title, words),
                             count=count)
-    html = wiki.template("page.html", page, title="Search", content=content)
+    html = wiki.template("page.html", request.page, title="Search", content=content)
     return BaseResponse(html, mimetype="text/html")