diff options
author | Ben Bangert <ben@groovie.org> | 2016-03-29 23:12:15 -0700 |
---|---|---|
committer | Ben Bangert <ben@groovie.org> | 2016-03-29 23:12:15 -0700 |
commit | 7a20c9b4ed0e30c3558c3cfb092d30041c3433bf (patch) | |
tree | 57fdd680824956147b0519a2d0393645320fbf28 | |
parent | 3d87edf1744d0ce6da1feba3a7eddcb31a9b4de4 (diff) | |
parent | 21bc2ea57c5d418f37c528258ebbcf2335e009b6 (diff) | |
download | routes-7a20c9b4ed0e30c3558c3cfb092d30041c3433bf.tar.gz |
Merge pull request #65 from dims/master
Tolerate older usage with mandatory routename and optional path
-rw-r--r-- | CHANGELOG.rst | 5 | ||||
-rw-r--r-- | routes/mapper.py | 20 | ||||
-rw-r--r-- | tests/test_functional/test_submapper.py | 6 |
3 files changed, 21 insertions, 10 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4a21f57..9fe0abc 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Routes Changelog %%%%%%%%%%%%%%%% +Release 2.3.1 (**dev**) +======================= +* Backwards compatability fix - connect should work with mandatory + routename and optional path. Patch by Davanum Srinivas (PR #65). + Release 2.3 (March 28, 2016) ============================ * Fix sub_domain equivalence check. Patch by Nikita Uvarov diff --git a/routes/mapper.py b/routes/mapper.py index 06f09f2..48bba45 100644 --- a/routes/mapper.py +++ b/routes/mapper.py @@ -162,25 +162,25 @@ class SubMapper(SubMapperParent): self.formatted = True self.add_actions(actions or [], **kwargs) - def connect(self, *args, **kwargs): + def connect(self, routename, path=None, **kwargs): newkargs = {} - # newargs = args - routename, path = args + _routename = routename + _path = path for key, value in six.iteritems(self.kwargs): if key == 'path_prefix': - if len(args) > 1: + if path is not None: # if there's a name_prefix, add it to the route name # and if there's a path_prefix - path = ''.join((self.kwargs[key], args[1])) + _path = ''.join((self.kwargs[key], path)) else: - path = ''.join((self.kwargs[key], args[0])) + _path = ''.join((self.kwargs[key], routename)) elif key == 'name_prefix': - if len(args) > 1: + if path is not None: # if there's a name_prefix, add it to the route name # and if there's a path_prefix - routename = ''.join((self.kwargs[key], args[0])) + _routename = ''.join((self.kwargs[key], routename)) else: - routename = None + _routename = None elif key in kwargs: if isinstance(value, dict): newkargs[key] = dict(value, **kwargs[key]) # merge dicts @@ -197,7 +197,7 @@ class SubMapper(SubMapperParent): if key not in self.kwargs: newkargs[key] = kwargs[key] - newargs = (routename, path) + newargs = (_routename, _path) return self.obj.connect(*newargs, **newkargs) def link(self, rel=None, name=None, action=None, method='GET', diff --git a/tests/test_functional/test_submapper.py b/tests/test_functional/test_submapper.py index 1516a58..8821de9 100644 --- a/tests/test_functional/test_submapper.py +++ b/tests/test_functional/test_submapper.py @@ -13,6 +13,12 @@ class TestSubmapper(unittest.TestCase): eq_('/entries/1', url_for('entry', id=1))
assert_raises(Exception, url_for, 'entry', id='foo')
+ def test_submapper_with_no_path(self):
+ m = Mapper()
+ c = m.submapper(path_prefix='/')
+ c.connect('entry')
+ eq_('/entry?id=1', url_for('entry', id=1))
+
def test_submapper_nesting(self):
m = Mapper()
c = m.submapper(path_prefix='/entries', controller='entry',
|