Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: ability to remove specific values from a URL #7

Open
acdha opened this issue Jan 16, 2013 · 6 comments
Open

Enhancement: ability to remove specific values from a URL #7

acdha opened this issue Jan 16, 2013 · 6 comments

Comments

@acdha
Copy link

acdha commented Jan 16, 2013

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

@j4mie
Copy link
Owner

j4mie commented Jan 17, 2013

Hi,

Does remove_query_param do what you need?

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

@acdha
Copy link
Author

acdha commented Jan 17, 2013

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

@j4mie
Copy link
Owner

j4mie commented Jan 17, 2013

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
Copy link
Owner

j4mie commented Jan 17, 2013

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)

@bashu bashu self-assigned this Aug 16, 2015
@danpaulson
Copy link

Totally necroing this - was this ever implemented?

@edstafford
Copy link
Contributor

Is this still open for a PR to fix this?

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

edstafford added a commit to edstafford/django-spurl that referenced this issue Aug 30, 2018
edstafford added a commit to edstafford/django-spurl that referenced this issue Aug 30, 2018
@edstafford edstafford mentioned this issue Aug 30, 2018
@bashu bashu removed their assignment Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants