From 994714d8cc68701abb5190c1fd9d8c3015744797 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 12 May 2007 15:07:17 +0000 Subject: [PATCH] unicode: Added some more unicode conversions in django.db.models.*. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5203 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/base.py | 5 +-- django/db/models/fields/__init__.py | 25 ++++++++------- django/db/models/fields/related.py | 3 +- django/db/models/query.py | 3 +- tests/modeltests/validation/models.py | 2 +- tests/regressiontests/string_lookup/models.py | 32 ++++++++++++------- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/django/db/models/base.py b/django/db/models/base.py index de47730403..645ee7eb95 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -12,6 +12,7 @@ from django.db.models.loading import register_models, get_model from django.dispatch import dispatcher from django.utils.datastructures import SortedDict from django.utils.functional import curry +from django.utils.encoding import smart_str from django.conf import settings from itertools import izip import types @@ -83,7 +84,7 @@ class Model(object): return getattr(self, self._meta.pk.attname) def __repr__(self): - return '<%s: %s>' % (self.__class__.__name__, self) + return smart_str(u'<%s: %s>' % (self.__class__.__name__, self)) def __str__(self): if hasattr(self, '__unicode__'): @@ -326,7 +327,7 @@ class Model(object): where = '(%s %s %%s OR (%s = %%s AND %s.%s %s %%s))' % \ (backend.quote_name(field.column), op, backend.quote_name(field.column), backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op) - param = str(getattr(self, field.attname)) + param = smart_str(getattr(self, field.attname)) q = self.__class__._default_manager.filter(**kwargs).order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name) q._where.append(where) q._params.extend([param, param, getattr(self, self._meta.pk.attname)]) diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 350ffc99f5..aa3596403e 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -9,6 +9,7 @@ from django.utils.functional import curry from django.utils.itercompat import tee from django.utils.text import capfirst from django.utils.translation import ugettext, ugettext_lazy +from django.utils.encoding import smart_unicode import datetime, os, time class NOT_PROVIDED: @@ -22,7 +23,7 @@ BLANK_CHOICE_DASH = [("", "---------")] BLANK_CHOICE_NONE = [("", "None")] # prepares a value for use in a LIKE query -prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") +prep_for_like_query = lambda x: smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") # returns the