changeset 316:4ee796d759bf

use url_for_item where appropriate (in py code, no template changes yet) make url_for_item available for templates
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 05 Aug 2011 14:01:21 +0200
parents fed6024028b4
children c61d7e7c6c6b
files MoinMoin/apps/feed/views.py MoinMoin/apps/frontend/views.py MoinMoin/items/__init__.py MoinMoin/themes/__init__.py
diffstat 4 files changed, 25 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/feed/views.py	Fri Aug 05 13:25:12 2011 +0200
+++ b/MoinMoin/apps/feed/views.py	Fri Aug 05 14:01:21 2011 +0200
@@ -11,7 +11,7 @@
 
 from datetime import datetime
 
-from flask import request, url_for, Response
+from flask import request, Response
 from flask import current_app as app
 from flask import g as flaskg
 
@@ -27,6 +27,8 @@
 from MoinMoin.themes import get_editor_info
 from MoinMoin.items import Item
 from MoinMoin.util.crypto import cache_key
+from MoinMoin.util.interwiki import url_for_item
+
 
 @feed.route('/atom/<itemname:item_name>')
 @feed.route('/atom', defaults=dict(item_name=''))
@@ -66,7 +68,7 @@
                      summary=rev.get(COMMENT, ''), summary_type='text',
                      content=content, content_type=content_type,
                      author=get_editor_info(rev, external=True),
-                     url=url_for('frontend.show_item', item_name=name, rev=this_revno, _external=True),
+                     url=url_for_item(name, rev=this_revno, _external=True),
                      updated=datetime.utcfromtimestamp(rev.timestamp),
                     )
         content = feed.to_string()
--- a/MoinMoin/apps/frontend/views.py	Fri Aug 05 13:25:12 2011 +0200
+++ b/MoinMoin/apps/frontend/views.py	Fri Aug 05 14:01:21 2011 +0200
@@ -41,6 +41,7 @@
 from MoinMoin import config, user, wikiutil
 from MoinMoin.config import CONTENTTYPE, ITEMLINKS, ITEMTRANSCLUSIONS
 from MoinMoin.util import crypto
+from MoinMoin.util.interwiki import url_for_item
 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, AccessDeniedError
 from MoinMoin.signalling import item_displayed, item_modified
@@ -59,8 +60,7 @@
 @frontend.route('/')
 def show_root():
     item_name = app.cfg.item_root
-    location = url_for('.show_item', item_name=item_name)
-    return redirect(location)
+    return redirect(url_for_item(item_name))
 
 @frontend.route('/robots.txt')
 def robots():
@@ -178,7 +178,7 @@
 
 @frontend.route('/+show/<itemname:item_name>')
 def redirect_show_item(item_name):
-    return redirect(url_for('.show_item', item_name=item_name))
+    return redirect(url_for_item(item_name))
 
 
 @frontend.route('/+dom/<int:rev>/<itemname:item_name>')
@@ -352,7 +352,7 @@
         TextCha(form).amend_form()
         if form.validate():
             item.revert()
-            return redirect(url_for('.show_item', item_name=item_name))
+            return redirect(url_for_item(item_name))
     return render_template(item.revert_template,
                            item=item, item_name=item_name,
                            rev_no=rev,
@@ -377,7 +377,7 @@
             target = form['target'].value
             comment = form['comment'].value
             item.copy(target, comment)
-            return redirect(url_for('.show_item', item_name=target))
+            return redirect(url_for_item(target))
     return render_template(item.copy_template,
                            item=item, item_name=item_name,
                            form=form,
@@ -401,7 +401,7 @@
             target = form['target'].value
             comment = form['comment'].value
             item.rename(target, comment)
-            return redirect(url_for('.show_item', item_name=target))
+            return redirect(url_for_item(target))
     return render_template(item.rename_template,
                            item=item, item_name=item_name,
                            form=form,
@@ -423,7 +423,7 @@
         if form.validate():
             comment = form['comment'].value
             item.delete(comment)
-            return redirect(url_for('.show_item', item_name=item_name))
+            return redirect(url_for_item(item_name))
     return render_template(item.delete_template,
                            item=item, item_name=item_name,
                            form=form,
@@ -453,7 +453,7 @@
         if form.validate():
             comment = form['comment'].value
             item.destroy(comment=comment, destroy_item=destroy_item)
-            return redirect(url_for('.show_item', item_name=item_name))
+            return redirect(url_for_item(item_name))
     return render_template(item.destroy_template,
                            item=item, item_name=item_name,
                            rev_no=rev,
@@ -480,8 +480,8 @@
             abort(403)
         files = []
         for full_name, rel_name, mimetype in item.flat_index():
-            url = url_for('.show_item', item_name=full_name)
-            url_download = url_for('.download_item', item_name=full_name)
+            url = url_for_item(full_name)
+            url_download = url_for_item(full_name, endpoint='frontend.download_item')
             files.append(dict(name=rel_name, url=url, url_download=url_download, size=0))
         return jsonify(files=files)
     if request.method == 'POST':
@@ -495,8 +495,8 @@
                                item_name=item_name)
             return jsonify(name=subitem_name,
                            size=size,
-                           url=url_for('.show_item', item_name=item_name, rev=revno),
-                           url_download=url_for('.download_item', item_name=item_name, rev=revno),
+                           url=url_for_item(item_name, rev=revno),
+                           url_download=url_for_item(item_name, rev=revno, endpoint='frontend.download_item'),
                           )
         except AccessDeniedError:
             abort(403)
@@ -689,7 +689,7 @@
             msg = _('Your quicklink to this page could not be removed.'), "error"
     if msg:
         flash(*msg)
-    return redirect(url_for('.show_item', item_name=item_name))
+    return redirect(url_for_item(item_name))
 
 
 @frontend.route('/+subscribe/<itemname:item_name>')
@@ -713,7 +713,7 @@
             msg = _('You could not get subscribed to this item.'), "error"
     if msg:
         flash(*msg)
-    return redirect(url_for('.show_item', item_name=item_name))
+    return redirect(url_for_item(item_name))
 
 
 class ValidRegistration(Validator):
--- a/MoinMoin/items/__init__.py	Fri Aug 05 13:25:12 2011 +0200
+++ b/MoinMoin/items/__init__.py	Fri Aug 05 14:01:21 2011 +0200
@@ -61,6 +61,7 @@
 from MoinMoin.themes import render_template
 from MoinMoin import wikiutil, config, user
 from MoinMoin.util.send_file import send_file
+from MoinMoin.util.interwiki import url_for_item
 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, AccessDeniedError, \
                                    StorageError
 from MoinMoin.config import UUID, NAME, NAME_OLD, MTIME, REVERTED_TO, ACL, \
@@ -709,7 +710,7 @@
                 except AccessDeniedError:
                     abort(403)
                 else:
-                    return redirect(url_for('frontend.show_item', item_name=self.name))
+                    return redirect(url_for_item(self.name))
         return render_template(self.template,
                                item_name=self.name,
                                rows_meta=str(ROWS_META), cols=str(COLS),
@@ -1170,7 +1171,7 @@
                 except AccessDeniedError:
                     abort(403)
                 else:
-                    return redirect(url_for('frontend.show_item', item_name=self.name))
+                    return redirect(url_for_item(self.name))
         return render_template(self.template,
                                item_name=self.name,
                                rows_data=str(ROWS_DATA), rows_meta=str(ROWS_META), cols=str(COLS),
--- a/MoinMoin/themes/__init__.py	Fri Aug 05 13:25:12 2011 +0200
+++ b/MoinMoin/themes/__init__.py	Fri Aug 05 14:01:21 2011 +0200
@@ -180,21 +180,13 @@
         if target.startswith("wiki:"):
             target = target[5:]
 
-        # try handling interwiki links
         wiki_name, item_name = split_interwiki(target)
+        if wiki_name == 'Self':
+            wiki_name = ''
         href = url_for_item(item_name, wiki_name=wiki_name)
-        if not is_local_wiki(wiki_name):
-            if not title:
-                title = item_name
-            return href, title, wiki_name
-
-        # Handle regular pagename like "FrontPage"
-        item_name = wikiutil.normalize_pagename(item_name, self.cfg)
-
         if not title:
             title = item_name
-        href = url_for('frontend.show_item', item_name=item_name)
-        return href, title, wiki_local
+        return href, title, wiki_name
 
     def navibar(self, item_name):
         """
@@ -387,6 +379,7 @@
                             'clock': flaskg.clock,
                             'cfg': app.cfg,
                             'item_name': 'handlers need to give it',
+                            'url_for_item': url_for_item,
                             'get_editor_info': lambda rev: get_editor_info(rev),
                             'gen': make_generator(),
                             })