From 898181130e094767754e01c77862af7d190410c5 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Fri, 18 Feb 2011 14:42:17 -0500 Subject: [PATCH] Tweaked TargetURLModel.get_reverse_params() to convert kwargs keys to bytestrings to support Python versions prior to 2.6.5 --- models/nodes.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/models/nodes.py b/models/nodes.py index 07a5e0a..3f40205 100644 --- a/models/nodes.py +++ b/models/nodes.py @@ -226,8 +226,17 @@ class TargetURLModel(models.Model): def get_reverse_params(self): params = self.reversing_parameters - args = isinstance(params, list) and params or None - kwargs = isinstance(params, dict) and params or None + args = kwargs = None + if isinstance(params, list): + args = params + elif isinstance(params, dict): + # Convert unicode keys to strings for Python < 2.6.5. Compare + # http://stackoverflow.com/questions/4598604/how-to-pass-unicode-keywords-to-kwargs + kwargs = {} + for key, val in params.items(): + if isinstance(key, unicode): + key = str(key) + kwargs[key] = val return self.url_or_subpath, args, kwargs def get_target_url(self): -- 2.20.1