File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 22
33from django .db import models
44from django .contrib .sites .models import Site
5+ from django .core .urlresolvers import get_script_prefix
56from django .utils .translation import ugettext_lazy as _
67from django .utils .encoding import iri_to_uri , python_2_unicode_compatible
78
@@ -26,4 +27,5 @@ def __str__(self):
2627 return "%s -- %s" % (self .url , self .title )
2728
2829 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 )
Original file line number Diff line number Diff line change 22
33from __future__ import unicode_literals
44
5+ from django .core .urlresolvers import set_script_prefix , clear_script_prefix
56from django .contrib .flatpages .models import FlatPage
67from django .test import TestCase
78
@@ -12,4 +13,10 @@ def test_get_absolute_url_urlencodes(self):
1213 pf = FlatPage (title = "Café!" , url = '/café/' )
1314 self .assertEqual (pf .get_absolute_url (), '/caf%C3%A9/' )
1415
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 ()
Original file line number Diff line number Diff line change @@ -521,6 +521,15 @@ def get_script_prefix():
521521 """
522522 return getattr (_prefixes , "value" , '/' )
523523
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+
524533def set_urlconf (urlconf_name ):
525534 """
526535 Sets the URLconf for the current thread (overriding the default one in
You can’t perform that action at this time.
0 commit comments