Ticket #8278: 8278.querydict.diff

File 8278.querydict.diff, 2.3 KB (added by Julien Phalip, 16 years ago)

Patch and regression tests

  • django/django/http/__init__.py

     
    191191    def update(self, other_dict):
    192192        self._assert_mutable()
    193193        f = lambda s: str_to_unicode(s, self.encoding)
    194         d = dict([(f(k), f(v)) for k, v in other_dict.items()])
     194        d = dict([(f(k), [f(v) for v in values]) for k, values in other_dict.lists()])
    195195        MultiValueDict.update(self, d)
    196196
    197197    def pop(self, key, *args):
  • django/django/utils/datastructures.py

     
    293293            else:
    294294                try:
    295295                    for key, value in other_dict.items():
    296                         self.setlistdefault(key, []).append(value)
     296                        if isinstance(value, list):
     297                            self.setlistdefault(key, []).extend(value)
     298                        else:
     299                            self.setlistdefault(key, []).append(value)
    297300                except TypeError:
    298301                    raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
    299302        for key, value in kwargs.iteritems():
  • django/tests/regressiontests/httpwrappers/tests.py

     
    426426Traceback (most recent call last):
    427427...
    428428UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
    429  
     429
     430
     431#############################################################
     432# Merging 2 QueryDict's with same keys and multiple values  #
     433#############################################################
     434
     435>>> x = QueryDict('a=1&a=2')
     436>>> y = QueryDict('a=3&a=4')
     437>>> x._mutable = True
     438>>> x.update(y)
     439>>> x._mutable=False
     440>>> x
     441<QueryDict: {u'a': [u'1', u'2', u'3', u'4']}>
     442
    430443"""
    431444
    432445from django.http import QueryDict, HttpResponse
Back to Top