Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor add_query_param to use URLObject. Refs #112.
- Loading branch information
1 parent
c8134a6
commit 97c5262
Showing
1 changed file
with
3 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |