Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18862 -- Honored script prefix in FlatPage.get_absolute_url.

  • Loading branch information...
commit a44531ae1592cf266e6c24387f49d665c639b480 1 parent 4b01ee7
Aymeric Augustin authored February 24, 2013
4  django/contrib/flatpages/models.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 from django.db import models
4 4
 from django.contrib.sites.models import Site
  5
+from django.core.urlresolvers import get_script_prefix
5 6
 from django.utils.translation import ugettext_lazy as _
6 7
 from django.utils.encoding import iri_to_uri, python_2_unicode_compatible
7 8
 
@@ -26,4 +27,5 @@ def __str__(self):
26 27
         return "%s -- %s" % (self.url, self.title)
27 28
 
28 29
     def get_absolute_url(self):
29  
-        return iri_to_uri(self.url)
  30
+        # Handle script prefix manually because we bypass reverse()
  31
+        return iri_to_uri(get_script_prefix().rstrip('/') + self.url)
9  django/contrib/flatpages/tests/models.py
@@ -2,6 +2,7 @@
2 2
 
3 3
 from __future__ import unicode_literals
4 4
 
  5
+from django.core.urlresolvers import set_script_prefix, clear_script_prefix
5 6
 from django.contrib.flatpages.models import FlatPage
6 7
 from django.test import TestCase
7 8
 
@@ -12,4 +13,10 @@ def test_get_absolute_url_urlencodes(self):
12 13
         pf = FlatPage(title="Café!", url='/café/')
13 14
         self.assertEqual(pf.get_absolute_url(), '/caf%C3%A9/')
14 15
 
15  
-
  16
+    def test_get_absolute_url_honors_script_prefix(self):
  17
+        pf = FlatPage(title="Tea!", url='/tea/')
  18
+        set_script_prefix('/beverages/')
  19
+        try:
  20
+            self.assertEqual(pf.get_absolute_url(), '/beverages/tea/')
  21
+        finally:
  22
+            clear_script_prefix()
9  django/core/urlresolvers.py
@@ -521,6 +521,15 @@ def get_script_prefix():
521 521
     """
522 522
     return getattr(_prefixes, "value", '/')
523 523
 
  524
+def clear_script_prefix():
  525
+    """
  526
+    Unsets the script prefix for the current thread.
  527
+    """
  528
+    try:
  529
+        del _prefixes.value
  530
+    except AttributeError:
  531
+        pass
  532
+
524 533
 def set_urlconf(urlconf_name):
525 534
     """
526 535
     Sets the URLconf for the current thread (overriding the default one in

0 notes on commit a44531a

Please sign in to comment.
Something went wrong with that request. Please try again.