i592: Use full path in various places
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 3 Oct 2011 12:01:13 +0000 (14:01 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 3 Oct 2011 12:01:13 +0000 (14:01 +0200)
When running mediagoblin in a sub path on a web server,
most things inside mediagoblin need the "inside path", but
when generating URLs for the webbrowser, full paths are
needed.

urlgen and routes already do that.

Some (mostly pagination and login) need the URL of the
current page. They used request.path_info. But this is the
"inside" path, not the full.

So now there is request.full_path and its used in various
places.

mediagoblin/app.py
mediagoblin/decorators.py
mediagoblin/templates/mediagoblin/utils/pagination.html
mediagoblin/tools/pagination.py

index 0f25a4e517b67a8b3ef050bc71bea51614164b7e..f052d4a2e52d46d98b24d90bbf243826636e1425 100644 (file)
@@ -117,6 +117,17 @@ class MediaGoblinApp(object):
         path_info = request.path_info
         route_match = self.routing.match(path_info)
 
+        # By using fcgi, mediagoblin can run under a base path
+        # like /mediagoblin/. request.path_info contains the
+        # path inside mediagoblin. If the something needs the
+        # full path of the current page, that should include
+        # the basepath.
+        # Note: urlgen and routes are fine!
+        request.full_path = environ["SCRIPT_NAME"] + request.path_info
+        # python-routes uses SCRIPT_NAME. So let's use that too.
+        # The other option would be:
+        # request.full_path = environ["SCRIPT_URL"]
+
         ## Attach utilities to the request object
         request.matchdict = route_match
         request.urlgen = routes.URLGenerator(self.routing, environ)
index 19e22bcabe257125f97a5e4944faa2e71aa81e2e..6431d67e329ba4b98aa1ddad981dcd4deaa57732 100644 (file)
@@ -45,7 +45,7 @@ def require_active_login(controller):
             return exc.HTTPFound(
                 location="%s?next=%s" % (
                     request.urlgen("mediagoblin.auth.login"),
-                    request.path_info))
+                    request.full_path))
 
         return controller(request, *args, **kwargs)
 
index 0df3bfea616f58bd70cab025a2f82ce92a53ee56..843361030665c2c90a2467c8275b9973c206acd2 100644 (file)
@@ -21,7 +21,7 @@
   {# only display if {{pagination}} is defined #}
   {% if pagination and pagination.pages > 1 %}
     {% if not base_url %}
-      {% set base_url = request.path_info %}
+      {% set base_url = request.full_path %}
     {% endif %}
 
     {% if preserve_get_params %}
index 859b60fb7983cbcd9cf71ac1bc600edbad49f20b..3ea96e6d5a05c5da1dd318be812a0401750b73f8 100644 (file)
@@ -106,4 +106,4 @@ class Pagination(object):
         This is a nice wrapper around get_page_url_explicit()
         """ 
         return self.get_page_url_explicit(
-            request.path_info, request.GET, page_no)
+            request.full_path, request.GET, page_no)