router map_static, thanks Jonathan
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.00.0 (2012-08-07 16:53:00) dev
|
||||
Version 2.00.0 (2012-08-07 19:39:42) dev
|
||||
|
||||
+25
-7
@@ -43,6 +43,7 @@ def _router_default():
|
||||
default_language = None,
|
||||
languages = None,
|
||||
root_static = ['favicon.ico', 'robots.txt'],
|
||||
map_static = None,
|
||||
domains = None,
|
||||
exclusive_domain = False,
|
||||
map_hyphen = False,
|
||||
@@ -1083,6 +1084,7 @@ class MapUrlOut(object):
|
||||
self.env = env
|
||||
self.application = application
|
||||
self.controller = controller
|
||||
self.is_static = (controller == 'static' or controller.startswith('static/'))
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.other = other
|
||||
@@ -1188,7 +1190,7 @@ class MapUrlOut(object):
|
||||
# handle static as a special case
|
||||
# (easier for external static handling)
|
||||
#
|
||||
if self.controller == 'static' or self.controller.startswith('static/'):
|
||||
if self.is_static:
|
||||
if not self.map_static:
|
||||
self.omit_application = False
|
||||
if self.language:
|
||||
@@ -1206,10 +1208,14 @@ class MapUrlOut(object):
|
||||
self.function = self.function.replace('_', '-')
|
||||
if not self.omit_application:
|
||||
acf += '/' + self.application
|
||||
if not self.omit_language:
|
||||
acf += '/' + self.language
|
||||
if not self.omit_controller:
|
||||
acf += '/' + self.controller
|
||||
# handle case of flipping lang/static/file to static/lang/file for external rewrite
|
||||
if self.is_static and self.map_static is False and not self.omit_language:
|
||||
acf += '/' + self.controller + '/' + self.language
|
||||
else:
|
||||
if not self.omit_language:
|
||||
acf += '/' + self.language
|
||||
if not self.omit_controller:
|
||||
acf += '/' + self.controller
|
||||
if not self.omit_function:
|
||||
acf += '/' + self.function
|
||||
if self.path_prefix:
|
||||
@@ -1249,9 +1255,21 @@ def map_url_in(request, env, app=False):
|
||||
root_static_file = map.map_root_static() # handle root-static files
|
||||
if root_static_file:
|
||||
return (root_static_file, map.env)
|
||||
map.map_language()
|
||||
map.map_controller()
|
||||
# handle mapping of lang/static to static/lang in externally-rewritten URLs
|
||||
# in case we have to handle them ourselves
|
||||
if map.languages and map.map_static is False and map.arg0 == 'static' and map.args(1) in map.languages:
|
||||
if 'es' in map.languages:
|
||||
print 'handle static/lang %s' % map.args(1)
|
||||
map.map_controller()
|
||||
map.map_language()
|
||||
else:
|
||||
if 'es' in map.languages:
|
||||
print 'NO handle static/lang %s' % map.args(1)
|
||||
map.map_language()
|
||||
map.map_controller()
|
||||
static_file = map.map_static()
|
||||
if 'es' in map.languages:
|
||||
print 'static_file=%s' % static_file
|
||||
if static_file:
|
||||
return (static_file, map.env)
|
||||
map.map_function()
|
||||
|
||||
@@ -542,7 +542,7 @@ class TestRouter(unittest.TestCase):
|
||||
self.assertEqual(filter_url('https://domain.com/init/static/file', out=True), "/static/file")
|
||||
self.assertEqual(filter_url('https://domain.com/init/static/index', out=True), "/static/index")
|
||||
|
||||
router_out['init']['map_static'] = False
|
||||
router_out['init']['map_static'] = None
|
||||
load(rdict=router_out)
|
||||
self.assertEqual(filter_url('https://domain.com/init/static/file', out=True), "/init/static/file")
|
||||
self.assertEqual(filter_url('https://domain.com/init/static/index', out=True), "/init/static/index")
|
||||
@@ -744,6 +744,28 @@ class TestRouter(unittest.TestCase):
|
||||
self.assertEqual(filter_url('https://domain.com/welcome/ctr/fcn', lang='it', out=True), "/welcome/ctr/fcn")
|
||||
self.assertEqual(filter_url('https://domain.com/welcome/ctr/fcn', lang='es', out=True), "/welcome/ctr/fcn")
|
||||
|
||||
router_lang['admin']['map_static'] = False
|
||||
router_lang['examples']['map_static'] = False
|
||||
load(rdict=router_lang)
|
||||
self.assertEqual(filter_url('https://domain.com/admin/ctr/fcn', lang='en', out=True), "/ctr/fcn")
|
||||
self.assertEqual(filter_url('https://domain.com/admin/ctr/fcn', lang='it', out=True), "/it/ctr/fcn")
|
||||
self.assertEqual(filter_url('https://domain.com/admin/ctr/fcn', lang='it-it', out=True), "/it-it/ctr/fcn")
|
||||
self.assertEqual(filter_url('https://domain.com/admin/static/file', lang='en', out=True), "/admin/static/en/file")
|
||||
self.assertEqual(filter_url('https://domain.com/admin/static/file', lang='it', out=True), "/admin/static/it/file")
|
||||
self.assertEqual(filter_url('https://domain.com/admin/static/file', lang='it-it', out=True), "/admin/static/it-it/file")
|
||||
self.assertEqual(filter_url('https://domain.com/welcome/ctr/fcn', lang='it', out=True), "/welcome/ctr/fcn")
|
||||
self.assertEqual(filter_url('https://domain.com/welcome/ctr/fcn', lang='es', out=True), "/welcome/ctr/fcn")
|
||||
self.assertEqual(filter_url('http://domain.com/static/file'), "%s/applications/admin/static/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/en/static/file'), "%s/applications/admin/static/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/en/static/file'), "%s/applications/examples/static/en/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/static/file'), "%s/applications/examples/static/en/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/it/static/file'), "%s/applications/examples/static/it/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/it-it/static/file'), "%s/applications/examples/static/file" % root)
|
||||
|
||||
self.assertEqual(filter_url('http://domain.com/examples/static/en/file'), "%s/applications/examples/static/en/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/static/it/file'), "%s/applications/examples/static/it/file" % root)
|
||||
self.assertEqual(filter_url('http://domain.com/examples/static/it-it/file'), "%s/applications/examples/static/it-it/file" % root)
|
||||
|
||||
def test_router_get_effective(self):
|
||||
'''
|
||||
Test get_effective_router
|
||||
|
||||
+3
-1
@@ -61,8 +61,9 @@
|
||||
# map_hyphen: If True (default is False), hyphens in incoming /a/c/f fields are converted
|
||||
# to underscores, and back to hyphens in outgoing URLs.
|
||||
# Language, args and the query string are not affected.
|
||||
# map_static: By default, the default application is not stripped from static URLs.
|
||||
# map_static: By default (None), the default application is not stripped from static URLs.
|
||||
# Set map_static=True to override this policy.
|
||||
# Set map_static=False to map lang/static/file to static/lang/file
|
||||
# acfe_match: regex for valid application, controller, function, extension /a/c/f.e
|
||||
# file_match: regex for valid subpath (used for static file paths)
|
||||
# if file_match does not contain '/', it is uses to validate each element of a static file subpath,
|
||||
@@ -84,6 +85,7 @@
|
||||
# default_language = None,
|
||||
# languages = None,
|
||||
# root_static = ['favicon.ico', 'robots.txt'],
|
||||
# map_static = None,
|
||||
# domains = None,
|
||||
# map_hyphen = False,
|
||||
# acfe_match = r'\w+$', # legal app/ctlr/fcn/ext
|
||||
|
||||
Reference in New Issue
Block a user