Commits

Branko Vukelic committed 52fa20e

Allow usage of UrlHelper instance in add_param tag

Comments (0)

Files changed (2)

tests/test_add_params.py

 from unittest import TestCase
 
 from url_tools.templatetags.urls import add_params
+from url_tools.helper import UrlHelper
 
 
 class AddParamsTestCase(TestCase):
             add_params('/foo/bar?baz=0#frag', foo=1, bar=2),
             '/foo/bar?bar=2&foo=1&baz=0#frag'
         )
+
+    def test_add_parasm_with_helper_instance(self):
+        self.assertEqual(
+            add_params(UrlHelper('/foo/bar?baz=0#frag'), foo=1, bar=2),
+            '/foo/bar?bar=2&foo=1&baz=0#frag'
+        )

url_tools/templatetags/urls.py

 
 @register.simple_tag
 def add_params(url, **kwargs):
-    url = UrlHelper(url)
+    if type(url) in [str, unicode]:
+        url = UrlHelper(url)
     url.update_query_data(**kwargs)
     return url.get_full_path()