changeset 4429:574644cfc6d2

add missing request.getQualifiedURL()
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 20 Nov 2008 21:59:43 +0100
parents ded09bdc3902
children 97ecf28b5969
files MoinMoin/web/contexts.py
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py	Tue Nov 18 22:03:57 2008 +0100
+++ b/MoinMoin/web/contexts.py	Thu Nov 20 21:59:43 2008 +0100
@@ -13,7 +13,7 @@
 from werkzeug.utils import Headers, http_date, create_environ, redirect
 from werkzeug.exceptions import Unauthorized, NotFound, abort
 
-from MoinMoin import i18n, error, user, config
+from MoinMoin import i18n, error, user, config, wikiutil
 from MoinMoin.config import multiconfig
 from MoinMoin.formatter import text_html
 from MoinMoin.theme import load_theme_fallback
@@ -316,6 +316,26 @@
             DeprecationWarning)
         return self.request.url_root
 
+    def getQualifiedURL(self, uri=''):
+        """ Return an absolute URL starting with schema and host.
+
+        Already qualified urls are returned unchanged.
+
+        @param uri: server rooted uri e.g /scriptname/pagename.
+                    It must start with a slash. Must be ascii and url encoded.
+        """
+        import urlparse
+        scheme = urlparse.urlparse(uri)[0]
+        if scheme:
+            return uri
+
+        result = "%s%s" % (self.request.host_url, uri)
+
+        # This might break qualified urls in redirects!
+        # e.g. mapping 'http://netloc' -> '/'
+        return wikiutil.mapURL(self, result)
+
+
 class AuxilaryMixin(object):
     """
     Mixin for diverse attributes and methods that aren't clearly assignable