Ticket #8278: 8278.querydict.2.diff

File 8278.querydict.2.diff, 1.7 KB (added by julien, 7 years ago)

2nd attempt. All tests pass.

  • 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()])
    195         MultiValueDict.update(self, d)
     194        try:
     195            for key, _list in other_dict.lists():
     196                for value in _list:
     197                    MultiValueDict.update(self, { f(key): f(value) })
     198        except AttributeError:
     199            d = dict([(f(k), f(v)) for k, v in other_dict.items()])
     200            MultiValueDict.update(self, d)
    196201
    197202    def pop(self, key, *args):
    198203        self._assert_mutable()
  • 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############################################################# 
     433# Merging 2 QueryDict's with same keys and multiple values  # 
     434#############################################################
     435
     436>>> x = QueryDict('a=1&a=2', mutable=True)
     437>>> y = QueryDict('a=3&a=4')
     438>>> x.update(y)
     439>>> x
     440<QueryDict: {u'a': [u'1', u'2', u'3', u'4']}>
     441
    430442"""
    431443
    432444from django.http import QueryDict, HttpResponse
Back to Top