Commit 8c9357796879845b0d6c23e14fb13f547fdfa5d7
Exists in
master
and in
39 other branches
Merge branch 'haystack'
Showing
1 changed file
with
9 additions
and
19 deletions
Show diff stats
src/super_archives/utils/url.py
| @@ -12,23 +12,13 @@ def append_to_get(path, query=None, **kwargs): | @@ -12,23 +12,13 @@ def append_to_get(path, query=None, **kwargs): | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | def pop_from_get(path, query=None, **kwargs): | 14 | def pop_from_get(path, query=None, **kwargs): |
| 15 | - # Getting the path with the query | ||
| 16 | - print query | ||
| 17 | - | ||
| 18 | - current_url = u'{}?{}'.format( | ||
| 19 | - path, | ||
| 20 | - query, | ||
| 21 | - ) | 15 | + query_dict = dict(urlparse.parse_qsl(query)) |
| 22 | for key, value in kwargs.items(): | 16 | for key, value in kwargs.items(): |
| 23 | - popitem = u'{}={}'.format(key, value) | ||
| 24 | - if query == popitem: | ||
| 25 | - return path | ||
| 26 | - | ||
| 27 | - if key not in current_url: | ||
| 28 | - return current_url | ||
| 29 | - | ||
| 30 | - first_path, end_path = current_url.split(key) | ||
| 31 | - end_path_without_element = end_path.split(value, 1) | ||
| 32 | - path_list = first_path + end_path_without_element | ||
| 33 | - print path_list | ||
| 34 | - return u''.join(path_list) | 17 | + if not query_dict.has_key(key): |
| 18 | + continue | ||
| 19 | + if query_dict[key] == value: | ||
| 20 | + del query_dict[key] | ||
| 21 | + continue | ||
| 22 | + if not query_dict: | ||
| 23 | + return u'{}?q='.format(path) | ||
| 24 | + return u'{}?{}'.format(path, urllib.urlencode(query_dict)) |