mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
Refactor add_query_param to use URLObject. Refs #112.
This commit is contained in:
parent
c8134a6340
commit
97c5262e9c
|
@ -1,17 +1,11 @@
|
||||||
from django.template import Library
|
from django.template import Library
|
||||||
from urlparse import urlparse, urlunparse
|
from urlobject import URLObject
|
||||||
from urllib import quote
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
def add_query_param(url, param):
|
def add_query_param(url, param):
|
||||||
(key, sep, val) = param.partition('=')
|
(key, sep, val) = param.partition('=')
|
||||||
param = '%s=%s' % (key, quote(val))
|
return unicode(URLObject(url) & (key, val))
|
||||||
(scheme, netloc, path, params, query, fragment) = urlparse(url)
|
|
||||||
if query:
|
|
||||||
query += "&" + param
|
|
||||||
else:
|
|
||||||
query = param
|
|
||||||
return urlunparse((scheme, netloc, path, params, query, fragment))
|
|
||||||
|
|
||||||
|
|
||||||
register.filter('add_query_param', add_query_param)
|
register.filter('add_query_param', add_query_param)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user