From 52a21117c40361cfaed335fb59312bb4de3b8d6c Mon Sep 17 00:00:00 2001 From: Michael Elsdoerfer Date: Fri, 27 Jun 2008 02:17:17 +0200 Subject: [PATCH] fixed bug in set_url_param when used with order_by values or similar structures --- django_tables/app/templatetags/tables.py | 2 +- tests/test_templates.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/django_tables/app/templatetags/tables.py b/django_tables/app/templatetags/tables.py index 2e60f8e..fe03ef8 100644 --- a/django_tables/app/templatetags/tables.py +++ b/django_tables/app/templatetags/tables.py @@ -34,7 +34,7 @@ class SetUrlParamNode(template.Node): for key, newvalue in self.changes.items(): newvalue = newvalue.resolve(context) if newvalue=='' or newvalue is None: params.pop(key, False) - else: params[key] = newvalue + else: params[key] = unicode(newvalue) # ``urlencode`` chokes on unicode input, so convert everything to # utf8. Note that if some query arguments passed to the site have # their non-ascii characters screwed up when passed though this, diff --git a/tests/test_templates.py b/tests/test_templates.py index 3b59aeb..80c4f41 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -7,6 +7,8 @@ via templates or otherwise. Whether a test belongs here or, say, in """ from py.test import raises +from django.template import Template, Context, add_to_builtins +from django.http import HttpRequest import django_tables as tables def test_order_by(): @@ -84,8 +86,6 @@ def test_render(): {'name': 'Netherlands', 'capital': 'Amsterdam', 'calling_code': '31'}, {'name': 'Austria', 'calling_code': 43, 'currency': 'Euro (€)', 'population': 8}]) - from django.template import Template, Context - assert Template("{% for column in countries.columns %}{{ column }}/{{ column.name }} {% endfor %}").\ render(Context({'countries': countries})) == \ "Name/name Capital/capital Population Size/population Phone Ext./cc " @@ -96,4 +96,15 @@ def test_render(): print Template("{% for row in countries %}{% if countries.columns.name.visible %}{{ row.name }} {% endif %}{% if countries.columns.tld.visible %}{{ row.tld }} {% endif %}{% endfor %}").\ render(Context({'countries': countries})) == \ - "Germany France Netherlands Austria" \ No newline at end of file + "Germany France Netherlands Austria" + +def test_templatetags(): + add_to_builtins('django_tables.app.templatetags.tables') + + # [bug] set url param tag handles an order_by tuple with multiple columns + class MyTable(tables.Table): + f1 = tables.Column() + f2 = tables.Column() + t = Template('{% set_url_param x=table.order_by %}') + table = MyTable([], order_by=('f1', 'f2')) + assert t.render({'request': HttpRequest(), 'table': table}) == '?x=f1%2Cf2' -- 2.26.2