changeset 1003:8621c3e273a1

fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
author Bruno Martin <bruno@hacklab.com.br>
date Fri, 28 Oct 2011 19:32:53 -0200
parents c2879c9331f9
children 9fd0a6a988bb
files MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/templates/404.html
diffstat 3 files changed, 39 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Fri Oct 28 00:45:47 2011 -0200
+++ b/MoinMoin/apps/frontend/views.py	Fri Oct 28 19:32:53 2011 -0200
@@ -260,6 +260,8 @@
         item = Item.create(item_name, rev_id=rev)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     return render_template('highlight.html',
                            item=item, item_name=item.name,
                            data_text=Markup(item._render_data_highlight()),
@@ -274,6 +276,8 @@
         item = Item.create(item_name, rev_id=rev)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     show_revision = rev != CURRENT
     show_navigation = False # TODO
     first_rev = None
@@ -309,6 +313,8 @@
         item = Item.create(item_name, rev_id=rev)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     return render_template('content.html',
                            item_name=item.name,
                            data_rendered=Markup(item._render_data()),
@@ -416,6 +422,8 @@
         item = Item.create(item_name, rev_id=rev)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     if request.method == 'GET':
         form = RevertItemForm.from_defaults()
         TextCha(form).amend_form()
@@ -438,6 +446,8 @@
         item = Item.create(item_name)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     if request.method == 'GET':
         form = RenameItemForm.from_defaults()
         TextCha(form).amend_form()
@@ -462,6 +472,8 @@
         item = Item.create(item_name)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     if request.method == 'GET':
         form = DeleteItemForm.from_defaults()
         TextCha(form).amend_form()
@@ -554,6 +566,8 @@
         item = Item.create(item_name, rev_id=_rev)
     except AccessDeniedError:
         abort(403)
+    if isinstance(item, NonExistent):
+        abort(404, item_name)
     if request.method == 'GET':
         form = DestroyItemForm.from_defaults()
         TextCha(form).amend_form()
@@ -1370,6 +1384,7 @@
     # TODO get_item and get_revision calls may raise an AccessDeniedError.
     #      If this happens for get_item, don't show the diff at all
     #      If it happens for get_revision, we may just want to skip that rev in the list
+    # TODO verify if it does crash when the item does not exist
     try:
         item = flaskg.storage.get_item(item_name)
     except AccessDeniedError:
@@ -1693,3 +1708,7 @@
                            item_name=tag,
                            item_names=item_names)
 
+@frontend.errorhandler(404)
+def page_not_found(e):
+    return render_template('404.html',
+                           item_name=e.description), 404
--- a/MoinMoin/items/__init__.py	Fri Oct 28 00:45:47 2011 -0200
+++ b/MoinMoin/items/__init__.py	Fri Oct 28 19:32:53 2011 -0200
@@ -608,6 +608,12 @@
                    for name in names]
         return initials
 
+    delete_template = 'delete.html'
+    destroy_template = 'destroy.html'
+    diff_template = 'diff.html'
+    rename_template = 'rename.html'
+    revert_template = 'revert.html'
+
 class NonExistent(Item):
     def do_get(self, force_attachment=False, mimetype=None):
         abort(404)
@@ -695,12 +701,6 @@
                                form=form,
                               )
 
-    delete_template = 'delete.html'
-    destroy_template = 'destroy.html'
-    diff_template = 'diff.html'
-    rename_template = 'rename.html'
-    revert_template = 'revert.html'
-
     def _render_data_diff(self, oldrev, newrev):
         hash_name = HASH_ALGORITHM
         if oldrev.meta[hash_name] == newrev.meta[hash_name]:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/templates/404.html	Fri Oct 28 19:32:53 2011 -0200
@@ -0,0 +1,14 @@
+{% import "forms.html" as forms %}
+{% extends theme("layout.html") %}
+{% block content %}
+
+<p>
+{{ _("The item '%(item_name)s' does not exist.", item_name=item_name) }}
+</p>
+
+{% endblock %}
+
+
+
+
+