From 942ef428ab9a31655c90dd3396a260c92189fad1 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Mon, 21 Feb 2011 13:47:48 -0500 Subject: [PATCH] Corrected JSONValue.__unicode__ to return unicode instead of bytestrings... not sure what it was being modeled on. Tweaked TargetURLModel to use smart_str instead of str to construct the Python < 2.6.5 kwargs to get a more consistent byte string. --- models/base.py | 4 ++-- models/nodes.py | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/models/base.py b/models/base.py index 8370bb7..836fe4a 100644 --- a/models/base.py +++ b/models/base.py @@ -5,7 +5,7 @@ from django.contrib.contenttypes import generic from django.core.exceptions import ObjectDoesNotExist from django.core.validators import RegexValidator from django.utils import simplejson as json -from django.utils.encoding import smart_str +from django.utils.encoding import force_unicode from philo.exceptions import AncestorDoesNotExist from philo.models.fields import JSONField from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter @@ -84,7 +84,7 @@ class JSONValue(AttributeValue): value = JSONField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.', default='null', db_index=True) def __unicode__(self): - return smart_str(self.value) + return force_unicode(self.value) def value_formfields(self): kwargs = {'initial': self.value_json} diff --git a/models/nodes.py b/models/nodes.py index 3f40205..99be196 100644 --- a/models/nodes.py +++ b/models/nodes.py @@ -7,6 +7,7 @@ from django.core.exceptions import ValidationError from django.core.servers.basehttp import FileWrapper from django.core.urlresolvers import resolve, clear_url_caches, reverse, NoReverseMatch from django.template import add_to_builtins as register_templatetags +from django.utils.encoding import smart_str from inspect import getargspec from philo.exceptions import MIDDLEWARE_NOT_CONFIGURED from philo.models.base import TreeEntity, Entity, QuerySetMapper, register_value_model @@ -210,7 +211,6 @@ class TargetURLModel(models.Model): reversing_parameters = JSONField(blank=True, help_text="If reversing parameters are defined, url_or_subpath will instead be interpreted as the view name to be reversed.") def clean(self): - # Should this be enforced? Not enforcing it would allow creation of "headers" in the navbar. if not self.target_node and not self.url_or_subpath: raise ValidationError("Either a target node or a url must be defined.") @@ -232,11 +232,7 @@ class TargetURLModel(models.Model): 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 + kwargs = dict([(smart_str(k, 'ascii'), v) for k, v in params.items()]) return self.url_or_subpath, args, kwargs def get_target_url(self): @@ -263,7 +259,7 @@ class TargetURLModel(models.Model): abstract = True -class Redirect(View, TargetURLModel): +class Redirect(TargetURLModel, View): STATUS_CODES = ( (302, 'Temporary'), (301, 'Permanent'), -- 2.20.1