From 97c5262e9ca318d0ff62d44a1f2d3ea31120d282 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 11 Jan 2012 13:50:43 +0000 Subject: [PATCH] Refactor add_query_param to use URLObject. Refs #112. --- djangorestframework/templatetags/add_query_param.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/djangorestframework/templatetags/add_query_param.py b/djangorestframework/templatetags/add_query_param.py index 94833bced..ce175b810 100644 --- a/djangorestframework/templatetags/add_query_param.py +++ b/djangorestframework/templatetags/add_query_param.py @@ -1,17 +1,11 @@ from django.template import Library -from urlparse import urlparse, urlunparse -from urllib import quote +from urlobject import URLObject register = Library() + def add_query_param(url, param): (key, sep, val) = param.partition('=') - param = '%s=%s' % (key, quote(val)) - (scheme, netloc, path, params, query, fragment) = urlparse(url) - if query: - query += "&" + param - else: - query = param - return urlunparse((scheme, netloc, path, params, query, fragment)) + return unicode(URLObject(url) & (key, val)) register.filter('add_query_param', add_query_param)