Changeset 5203
- Timestamp:
- 05/12/07 10:07:17 (1 year ago)
- Files:
-
- django/branches/unicode/django/db/models/base.py (modified) (3 diffs)
- django/branches/unicode/django/db/models/fields/__init__.py (modified) (8 diffs)
- django/branches/unicode/django/db/models/fields/related.py (modified) (2 diffs)
- django/branches/unicode/django/db/models/query.py (modified) (2 diffs)
- django/branches/unicode/tests/modeltests/validation/models.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/string_lookup/models.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode/django/db/models/base.py
r5185 r5203 13 13 from django.utils.datastructures import SortedDict 14 14 from django.utils.functional import curry 15 from django.utils.encoding import smart_str 15 16 from django.conf import settings 16 17 from itertools import izip … … 84 85 85 86 def __repr__(self): 86 return '<%s: %s>' % (self.__class__.__name__, self)87 return smart_str(u'<%s: %s>' % (self.__class__.__name__, self)) 87 88 88 89 def __str__(self): … … 327 328 (backend.quote_name(field.column), op, backend.quote_name(field.column), 328 329 backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column), op) 329 param = s tr(getattr(self, field.attname))330 param = smart_str(getattr(self, field.attname)) 330 331 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) 331 332 q._where.append(where) django/branches/unicode/django/db/models/fields/__init__.py
r5151 r5203 10 10 from django.utils.text import capfirst 11 11 from django.utils.translation import ugettext, ugettext_lazy 12 from django.utils.encoding import smart_unicode 12 13 import datetime, os, time 13 14 … … 23 24 24 25 # prepares a value for use in a LIKE query 25 prep_for_like_query = lambda x: s tr(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")26 prep_for_like_query = lambda x: smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 26 27 27 28 # returns the <ul> class for a given radio_admin value … … 300 301 rel_model = self.rel.to 301 302 if hasattr(self.rel, 'get_related_field'): 302 lst = [(getattr(x, self.rel.get_related_field().attname), s tr(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]303 else: 304 lst = [(x._get_pk_val(), s tr(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]303 lst = [(getattr(x, self.rel.get_related_field().attname), smart_unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 304 else: 305 lst = [(x._get_pk_val(), smart_unicode(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)] 305 306 return first_choice + lst 306 307 … … 424 425 else: 425 426 raise validators.ValidationError, ugettext_lazy("This field cannot be null.") 426 return s tr(value)427 return smart_unicode(value) 427 428 428 429 def formfield(self, **kwargs): … … 461 462 def get_db_prep_lookup(self, lookup_type, value): 462 463 if lookup_type == 'range': 463 value = [s tr(v) for v in value]464 value = [smart_unicode(v) for v in value] 464 465 elif lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte') and hasattr(value, 'strftime'): 465 466 value = value.strftime('%Y-%m-%d') 466 467 else: 467 value = s tr(value)468 value = smart_unicode(value) 468 469 return Field.get_db_prep_lookup(self, lookup_type, value) 469 470 … … 535 536 if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): 536 537 value = value.replace(microsecond=0) 537 value = s tr(value)538 value = smart_unicode(value) 538 539 return Field.get_db_prep_save(self, value) 539 540 540 541 def get_db_prep_lookup(self, lookup_type, value): 541 542 if lookup_type == 'range': 542 value = [s tr(v) for v in value]543 else: 544 value = s tr(value)543 value = [smart_unicode(v) for v in value] 544 else: 545 value = smart_unicode(value) 545 546 return Field.get_db_prep_lookup(self, lookup_type, value) 546 547 … … 812 813 def get_db_prep_lookup(self, lookup_type, value): 813 814 if lookup_type == 'range': 814 value = [s tr(v) for v in value]815 else: 816 value = s tr(value)815 value = [smart_unicode(v) for v in value] 816 else: 817 value = smart_unicode(value) 817 818 return Field.get_db_prep_lookup(self, lookup_type, value) 818 819 … … 832 833 if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): 833 834 value = value.replace(microsecond=0) 834 value = s tr(value)835 value = smart_unicode(value) 835 836 return Field.get_db_prep_save(self, value) 836 837 django/branches/unicode/django/db/models/fields/related.py
r5126 r5203 6 6 from django.utils.translation import gettext_lazy, string_concat, ngettext 7 7 from django.utils.functional import curry 8 from django.utils.encoding import smart_unicode 8 9 from django.core import validators 9 10 from django import oldforms … … 700 701 instance_ids = [instance._get_pk_val() for instance in getattr(obj, self.name).all()] 701 702 if self.rel.raw_id_admin: 702 new_data[self.name] = ",".join([str(id) for id in instance_ids])703 new_data[self.name] = u",".join([smart_unicode(id) for id in instance_ids]) 703 704 else: 704 705 new_data[self.name] = instance_ids django/branches/unicode/django/db/models/query.py
r5185 r5203 4 4 from django.dispatch import dispatcher 5 5 from django.utils.datastructures import SortedDict 6 from django.utils.encoding import smart_unicode 6 7 from django.contrib.contenttypes import generic 7 8 import operator … … 49 50 else: 50 51 import warnings 51 new_order_list = [LEGACY_ORDERING_MAPPING[j.upper()].replace('_', s tr(i)) for i, j in order_list]52 new_order_list = [LEGACY_ORDERING_MAPPING[j.upper()].replace('_', smart_unicode(i)) for i, j in order_list] 52 53 warnings.warn("%r ordering syntax is deprecated. Use %r instead." % (order_list, new_order_list), DeprecationWarning) 53 54 return new_order_list django/branches/unicode/tests/modeltests/validation/models.py
r5082 r5203 89 89 {} 90 90 >>> p.name 91 '227'91 u'227' 92 92 93 93 >>> p = Person(**dict(valid_params, birthdate=datetime.date(2000, 5, 3))) django/branches/unicode/tests/regressiontests/string_lookup/models.py
r3661 r5203 1 # -*- coding: utf-8 -*- 1 2 from django.db import models 2 3 3 4 class Foo(models.Model): 4 5 name = models.CharField(maxlength=50) 6 viking = models.CharField(maxlength=50, blank=True) 5 7 6 def __ str__(self):8 def __unicode__(self): 7 9 return "Foo %s" % self.name 8 10 … … 13 15 back = models.ForeignKey("Foo") 14 16 15 def __ str__(self):17 def __unicode__(self): 16 18 return "Bar %s" % self.place.name 17 19 … … 19 21 name = models.CharField(maxlength = 50) 20 22 21 def __ str__(self):23 def __unicode__(self): 22 24 return "Whiz %s" % self.name 23 25 … … 26 28 name = models.CharField(maxlength = 50) 27 29 28 def __ str__(self):30 def __unicode__(self): 29 31 return "Child %s" % self.name 30 32 31 33 class Base(models.Model): 32 34 name = models.CharField(maxlength = 50) 33 35 34 def __ str__(self):36 def __unicode__(self): 35 37 return "Base %s" % self.name 36 38 37 __test__ = {'API_TESTS': """38 # Regression test for #1661 and #1662: Check that string form referencing of models works,39 # both as pre and post reference, on all RelatedField types.39 __test__ = {'API_TESTS': ur""" 40 # Regression test for #1661 and #1662: Check that string form referencing of 41 # models works, both as pre and post reference, on all RelatedField types. 40 42 41 43 >>> f1 = Foo(name="Foo1") 42 44 >>> f1.save() 43 >>> f2 = Foo(name="Foo 1")45 >>> f2 = Foo(name="Foo2") 44 46 >>> f2.save() 45 47 … … 57 59 58 60 >>> b1.back 59 <Foo: Foo Foo 1>61 <Foo: Foo Foo2> 60 62 61 63 >>> base1 = Base(name="Base1") … … 67 69 >>> child1.parent 68 70 <Base: Base Base1> 71 72 # Regression tests for #3937: make sure we can use unicode characters in 73 # queries. 74 75 >>> fx = Foo(name='Bjorn', viking=u'Freydís Eiríksdóttir') 76 >>> fx.save() 77 >>> Foo.objects.get(viking__contains=u'\xf3') 78 <Foo: Foo Bjorn> 69 79 """}
