def re_qs(url, key, value):
    parsed = urlparse(url)
    data = parse_qs(parsed.query)
    if value is not None:
        data.update({
            key: [value],
        })
    else:
        if key in data:
            del data[key]

    _data = []
    for key, value in data.iteritems():
        for item in value:
            _data.append((key, item))

    return urlunparse([parsed.scheme, parsed.netloc, parsed.path, parsed.params, urlencode(_data), parsed.fragment])
dataset/ETHPy150Open crate-archive/crate-site/crateweb/apps/search/templatetags/search_utils.py/re_qs/original