Commits

Branko Vukelic committed 8fa73a3

Added quote and quote_plus filters and bumped version

Comments (0)

Files changed (3)

     {% 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 %}
+
+quote
+-----
+
+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:"~/" }}
+
+quote_plus
+----------
+
+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
     name='django-url-tools',
     description='Django helpers for dealing with URLs in templates',
     long_description=open('README.rst').read(),
-    version='0.0.5',
+    version='0.0.6',
     packages=['url_tools', 'url_tools.templatetags'],
     author='Monwara LLC',
     author_email='branko@monwara.com',

url_tools/templatetags/urls.py

 from __future__ import absolute_import, unicode_literals
 
+import urllib
+
 from django import template
 
 from ..helper import UrlHelper
     u.update_query_data(**kwargs)
     return u.get_full_path()
 
+
+@register.filter(name='quote')
+def quote_param(value, safe='/'):
+    return urllib.quote(value, safe)
+
+
+@register.filter(name='quote_plus')
+def quote_param_plus(value, safe='/'):
+    return urllib.quote_plus(value, safe)