1. Branko Vukelic
  2. django-url-tools


Branko Vukelic  committed 8fa73a3

Added quote and quote_plus filters and bumped version

  • Participants
  • Parent commits de2082b
  • Branches master
  • Tags 0.0.6

Comments (0)

Files changed (3)

File README.rst

View file
     {% url_params current_url page=2 %}
     {# this works for both ``/foo?page=1`` and just ``/foo`` #}
+Template filters
+URL tools also include filters for manipulating data that will be used as part
+of URLs. To use them, you need to load the ``urls`` library first::
+    {% load urls %}
+The ``quote`` filter quotes URL parameters. It accepts optional safe characters
+that can be used to prevent quoting of certain characters. This filter uses
+`urllib.quote`_ for quoting. Safe characters inlude only the slash ``/`` by
+default. ::
+    {{ value|quote:"~/" }}
+The ``quote_plus`` filter is similart ot the `quote`_ filter, except that it
+converts all spaces to ``+``. This filter also takes optional safe 
+characters. The filter uses `urllib.quote_plus`_ for quoting. ::
+    {{ value|quote_plus }}
 Reporting bugs
 .. _Django documentation on QueryDict: https://docs.djangoproject.com/en/dev/ref/request-response/?from=olddocs#querydict-objects
 .. _issue tracker: https://bitbucket.org/monwara/django-url-tools/issues
+.. _urllib.quote: http://docs.python.org/2/library/urllib.html#urllib.quote
+.. _urllib.quote_plus: http://docs.python.org/2/library/urllib.html#urllib.quote_plus

File setup.py

View file
     description='Django helpers for dealing with URLs in templates',
-    version='0.0.5',
+    version='0.0.6',
     packages=['url_tools', 'url_tools.templatetags'],
     author='Monwara LLC',

File url_tools/templatetags/urls.py

View file
 from __future__ import absolute_import, unicode_literals
+import urllib
 from django import template
 from ..helper import UrlHelper
     return u.get_full_path()
+def quote_param(value, safe='/'):
+    return urllib.quote(value, safe)
+def quote_param_plus(value, safe='/'):
+    return urllib.quote_plus(value, safe)