changeset 1899:f38a893334b5

new ItemNameConverter that does not match trailing slashes we do not support trailing slashes in itemnames, but for user convenience, we redirect <root_url>/itemname/ to <root_url>/itemname. this partly fixes #46.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 24 Dec 2012 00:39:45 +0100
parents 2b4bcb80d644
children d4a382f781c9
files MoinMoin/app.py MoinMoin/apps/frontend/views.py
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/app.py	Mon Dec 24 00:10:20 2012 +0100
+++ b/MoinMoin/app.py	Mon Dec 24 00:39:45 2012 +0100
@@ -100,8 +100,22 @@
     clock.stop('create_app load config')
     clock.start('create_app register')
     # register converters
-    from werkzeug.routing import PathConverter
-    app.url_map.converters['itemname'] = PathConverter
+    from werkzeug.routing import BaseConverter
+
+    class ItemNameConverter(BaseConverter):
+        """Like the default :class:`UnicodeConverter`, but it also matches
+        slashes (except at the beginning AND end).
+        This is useful for wikis and similar applications::
+
+            Rule('/<itemname:wikipage>')
+            Rule('/<itemname:wikipage>/edit')
+
+        :param map: the :class:`Map`.
+        """
+        regex = '[^/].*?[^/]'
+        weight = 200
+
+    app.url_map.converters['itemname'] = ItemNameConverter
     # register modules, before/after request functions
     from MoinMoin.apps.frontend import frontend
     frontend.before_request(before_wiki)
--- a/MoinMoin/apps/frontend/views.py	Mon Dec 24 00:10:20 2012 +0100
+++ b/MoinMoin/apps/frontend/views.py	Mon Dec 24 00:39:45 2012 +0100
@@ -359,6 +359,7 @@
     return item.do_show(rev)
 
 
+@frontend.route('/<itemname:item_name>/')  # note: unwanted trailing slash
 @frontend.route('/+show/<itemname:item_name>')
 def redirect_show_item(item_name):
     return redirect(url_for_item(item_name))