From 8d51759dd14e2e4fc86c74a884b7a7c766141266 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 1 Jul 2011 12:29:42 +0100 Subject: [PATCH] Fix bitbucket issue 39. All further issues should be on github --- AUTHORS | 1 + README | 2 +- djangorestframework/serializer.py | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0da0bca82..d2f3611ee 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ Carles Barrobés - HEAD support. Michael Fötsch - File format support. David Larlet - OAuth support. Andrew Straw - Bugfixes. + - Bugfixes. THANKS TO: diff --git a/README b/README index 3c7404866..0a14556ee 100644 --- a/README +++ b/README @@ -6,7 +6,7 @@ To install django-rest-framework in a virtualenv environment hg clone https://tomchristie@bitbucket.org/tomchristie/django-rest-framework cd django-rest-framework/ virtualenv --no-site-packages --distribute --python=python2.6 env - source ./env/bin/activate + source env/bin/activate pip install -r requirements.txt # django, coverage diff --git a/djangorestframework/serializer.py b/djangorestframework/serializer.py index da8036e94..82aeb53f2 100644 --- a/djangorestframework/serializer.py +++ b/djangorestframework/serializer.py @@ -4,7 +4,7 @@ Customizable serialization. from django.db import models from django.db.models.query import QuerySet from django.db.models.fields.related import RelatedField -from django.utils.encoding import smart_unicode, is_protected_type +from django.utils.encoding import smart_unicode, is_protected_type, smart_str import decimal import inspect @@ -177,7 +177,7 @@ class Serializer(object): Keys serialize to their string value, unless they exist in the `rename` dict. """ - return getattr(self.rename, key, key) + return getattr(self.rename, smart_str(key), smart_str(key)) def serialize_val(self, key, obj): @@ -228,12 +228,12 @@ class Serializer(object): # serialize each required field for fname in fields: - if hasattr(self, fname): + if hasattr(self, smart_str(fname)): # check for a method 'fname' on self first meth = getattr(self, fname) if inspect.ismethod(meth) and len(inspect.getargspec(meth)[0]) == 2: obj = meth(instance) - elif hasattr(instance, fname): + elif hasattr(instance, smart_str(fname)): # now check for an attribute 'fname' on the instance obj = getattr(instance, fname) elif fname in instance: