Changeset 3383

Show
Ignore:
Timestamp:
07/26/07 16:53:11 (1 year ago)
Author:
carndt
Message:

Apply patch from #1456

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/controllers.py

    r3368 r3383  
    486486    Query parameters for the URL can be passed in as a dictionary in 
    487487    the second argument *or* as keyword parameters. 
     488 
     489    Values which are a list or a tuple are used to create multiple 
     490    key-value pairs. 
    488491    """ 
    489492    if not isinstance(tgpath, basestring): 
     
    505508        if value is None: 
    506509            continue 
    507         if isinstance(value, unicode): 
    508             value = value.encode("utf8") 
    509         args.append("%s=%s" % (key, urllib.quote(str(value)))) 
     510        if isinstance(value, (list, tuple)): 
     511            pairs = [(key, v) for v in value] 
     512        else: 
     513            pairs = [(key, value)] 
     514        for (k,v) in pairs: 
     515            if isinstance(value, unicode): 
     516                value = value.encode("utf8") 
     517            args.append("%s=%s" % (k, urllib.quote(str(v)))) 
    510518    if args: 
    511519        result += "?" + "&".join(args) 
  • branches/1.0/turbogears/tests/test_controllers.py

    r3368 r3383  
    565565            assert "http://localhost/coolsite/root/subthing/foo" in e.urls 
    566566 
     567    def test_multi_values(self): 
     568        testutil.createRequest("/") 
     569        assert url("/foo", bar=[1,2]) in \ 
     570                ["/foo?bar=1&bar=2", "/foo?bar=2&bar=1"] 
     571        assert url("/foo", bar=("asdf","qwer")) in \ 
     572                ["/foo?bar=qwer&bar=asdf", "/foo?bar=asdf&bar=qwer"] 
    567573 
    568574    def tearDown(self):