Commits

Anonymous committed 3de191d

Merged contributed remove_params into del_params

  • Participants
  • Parent commits 2a24fc8

Comments (0)

Files changed (3)

File tests/test_remove_params.py

 
 from unittest import TestCase
 
-from url_tools.templatetags.urls import remove_params
+from url_tools.templatetags.urls import del_params
 from url_tools.helper import UrlHelper
 
 
 class RemoveParamsTestCase(TestCase):
     def test_remove_params_basic(self):
         self.assertEqual(
-            remove_params('/search/?q=something&selected_facets=first:foo&selected_facets=second:bar', selected_facets='first'),
+            del_params('/search/?q=something&selected_facets=first:foo&selected_facets=second:bar', selected_facets='first'),
             '/search/?q=something&selected_facets=second%3Abar'
         )
 
     def test_remove_params_takes_helper_instance(self):
         self.assertEqual(
-            remove_params(UrlHelper('/search/?q=something&selected_facets=first:foo&selected_facets=second:bar'), selected_facets='first'),
+            del_params(UrlHelper('/search/?q=something&selected_facets=first:foo&selected_facets=second:bar'), selected_facets='first'),
             '/search/?q=something&selected_facets=second%3Abar'
         )
         

File url_tools/helper.py

             uniques = set(self.query_dict.getlist(key))
             uniques.add(val)
             self.query_dict.setlist(key, list(uniques))
-        return self.path
-
-    def remove_params(self, **kwargs):
-        for key, val in kwargs.iteritems():
-            to_keep = [x for x in self.query_dict.getlist(key) if not x.startswith(val)]
-            self.query_dict.setlist(key, to_keep)
-        return self.path
-
 
     def del_param(self, param):
         try:
             del self.query_dict[param]
         except KeyError:
-            pass # Fail silently
+            pass  # Fail silently
 
-    def del_params(self, *params):
-        if not params:
+    def del_params(self, *params, **kwargs):
+        if not params and not kwargs:
             self.query = {}
             return
-        for param in params:
-            self.del_param(param)
+        if params:
+            for param in params:
+                self.del_param(param)
+        if kwargs:
+            for key, val in kwargs.iteritems():
+                to_keep = [x for x in self.query_dict.getlist(key)
+                           if not x.startswith(val)]
+                self.query_dict.setlist(key, to_keep)
 
     @property
     def hash(self):

File url_tools/templatetags/urls.py

 
 
 @register.simple_tag
-def del_params(url, *args):
+def del_params(url, *args, **kwargs):
     url = UrlHelper(url)
     try:
-        url.del_params(*args)
+        url.del_params(*args, **kwargs)
         return url.get_full_path()
     except:
         return ''
 
-
-@register.filter
-def suppr_param(url, arg):
-    return del_params(url, arg)
-
     
 @register.simple_tag
 def overload_params(url, **kwargs):
     except:
         return ''
 
-@register.simple_tag
-def remove_params(url, **kwargs):
-    url = UrlHelper(url)
-    try:
-        url.remove_params(**kwargs)
-        return url.get_full_path()
-    except:
-        return ''
-
 
 @register.assignment_tag
 def url_params(url, **kwargs):