summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2010-03-05 13:48:15 -0800
committerBen Bangert <ben@groovie.org>2010-03-05 13:48:15 -0800
commit6453bb827a66d349116d429335b4b9a68aacbf27 (patch)
treebb66944c318fd232c9b39d3c1954d5d9cfc47bf5
parentc559ef94b39c498c0b95e6e4bf272460c2fc6a46 (diff)
downloadroutes-6453bb827a66d349116d429335b4b9a68aacbf27.tar.gz
* Fix bug with routes not handling sub-domain defaults during generation.
--HG-- branch : trunk
-rw-r--r--CHANGELOG2
-rw-r--r--routes/middleware.py2
-rw-r--r--routes/util.py8
-rw-r--r--tests/test_functional/test_utils.py26
4 files changed, 35 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c9dbf7e..ef4cdb8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,7 +3,7 @@ Routes Changelog
Release 1.13 (**tip**)
======================
-
+* Fix bug with routes not handling sub-domain defaults during generation.
Release 1.12 (February 28, 2010)
================================
diff --git a/routes/middleware.py b/routes/middleware.py
index b772038..d4c005e 100644
--- a/routes/middleware.py
+++ b/routes/middleware.py
@@ -109,7 +109,7 @@ class RoutesMiddleware(object):
if route and route.redirect:
route_name = '_redirect_%s' % id(route)
- location = url_for(route_name, **match)
+ location = url(route_name, **match)
log.debug("Using redirect route, redirect to '%s' with status"
"code: %s", location, route.redirect_status)
start_response(route.redirect_status,
diff --git a/routes/util.py b/routes/util.py
index b2dac6d..37f292c 100644
--- a/routes/util.py
+++ b/routes/util.py
@@ -370,9 +370,15 @@ class URLGenerator(object):
if route.filter:
newargs = route.filter(newargs)
if not route.static or (route.static and not route.external):
- # Handle sub-domains
+ # Handle sub-domains, retain sub_domain if there is one
+ sub = newargs.get('sub_domain', None)
newargs = _subdomain_check(newargs, self.mapper,
self.environ)
+ # If the route requires a sub-domain, and we have it, restore
+ # it
+ if 'sub_domain' in route.defaults:
+ newargs['sub_domain'] = sub
+
elif use_current:
newargs = _screenargs(kargs, self.mapper, self.environ, force_explicit=True)
elif 'sub_domain' in kargs:
diff --git a/tests/test_functional/test_utils.py b/tests/test_functional/test_utils.py
index 8dbcef6..9cdbc80 100644
--- a/tests/test_functional/test_utils.py
+++ b/tests/test_functional/test_utils.py
@@ -675,6 +675,32 @@ class TestUtils(unittest.TestCase):
del self.con.environ['routes.cached_hostinfo']
eq_('http://new.example.com/category', urlobj('category_home', sub_domain='new'))
+ def test_subdomains_with_default(self):
+ base_environ = dict(SCRIPT_NAME='', PATH_INFO='/', HTTP_HOST='example.com:8000', SERVER_NAME='example.com')
+ self.con.mapper_dict = {}
+ self.con.environ = base_environ.copy()
+
+ m = Mapper(explicit=False)
+ m.minimization = True
+ m.sub_domains = True
+ m.connect(':controller/:action/:id')
+ m.connect('category_home', 'category/:section', controller='blog', action='view', section='home',
+ sub_domain='cat', conditions=dict(sub_domain=['cat']))
+ m.connect('building', 'building/:campus/:building/alljacks', controller='building', action='showjacks')
+ m.create_regs(['content','blog','admin/comments','building'])
+ self.con.mapper = m
+
+ urlobj = URLGenerator(m, self.con.environ)
+ self.con.environ['HTTP_HOST'] = 'example.com:8000'
+ eq_('/content/view', urlobj(controller='content', action='view'))
+ eq_('http://cat.example.com:8000/category', urlobj('category_home'))
+
+ self.con.environ['HTTP_HOST'] = 'example.com'
+ del self.con.environ['routes.cached_hostinfo']
+
+ assert_raises(GenerationException, lambda: urlobj('category_home', sub_domain='new'))
+
+
def test_controller_scan(self):
here_dir = os.path.dirname(__file__)
controller_dir = os.path.join(os.path.dirname(here_dir),