django-spurl icon indicating copy to clipboard operation
django-spurl copied to clipboard

Enhancement: ability to remove specific values from a URL

Open acdha opened this issue 13 years ago • 6 comments

With faceted search I often need to remove specific key:value pairs from a URL while leaving other values for that key intact – e.g. with ?category=1&category=5 I might want to remove category=1 to produce ?category=5.

I've been using this tag for years and was hoping that django-spurl might be a replacement:

https://github.com/acdha/django-sugar/blob/master/sugar/templatetags/querystring_tags.py

acdha avatar Jan 16 '13 22:01 acdha

Hi,

Does remove_query_param do what you need?

https://github.com/j4mie/django-spurl#remove_query_param

j4mie avatar Jan 17 '13 09:01 j4mie

Based on the documentation, no - what I need is something like:

{% spurl base="http://example.com/?foo=bar&foo=baz" remove_query_param_value="foo","bar" %}

which produces:

http://example.com/?foo=baz

acdha avatar Jan 17 '13 14:01 acdha

Aha, yes, sorry. Misunderstood.

It doesn't look like this functionality is in urlobject. Is it worth adding, @zacharyvoase ?

Otherwise, we could do something along the lines of:

url.set_query_param(key, [val for val in u.query_multi_dict.get(key, []) if val != value_to_remove])

Would you like to have a stab at a pull request @acdha ?

j4mie avatar Jan 17 '13 15:01 j4mie

I think I'd prefer to add this functionality to remove_query_param, by extending it to handle foo=bar as well as just foo as an argument, rather than adding remove_query_param_value (unless you can think of any problems with this)

j4mie avatar Jan 17 '13 15:01 j4mie

Totally necroing this - was this ever implemented?

danpaulson avatar Sep 04 '17 15:09 danpaulson

Is this still open for a PR to fix this?

UrlObject supports this: def del_query_param_value(self, name, value)

edstafford avatar Aug 30 '18 22:08 edstafford