Commits

sislau  committed 8621c3e

fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.

  • Participants
  • Parent commits c2879c9

Comments (0)

Files changed (3)

File MoinMoin/apps/frontend/views.py

         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()),
         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
         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()),
         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()
         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()
         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()
         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()
     # 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:
                            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

File MoinMoin/items/__init__.py

                    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)
                                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]:

File MoinMoin/templates/404.html

+{% 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 %}
+
+
+
+
+