Changeset 4971
- Timestamp:
- 04/09/07 05:33:57 (1 year ago)
- Files:
-
- django/branches/unicode/django/db/backends/mysql/base.py (modified) (1 diff)
- django/branches/unicode/django/db/backends/mysql_old/base.py (modified) (2 diffs)
- django/branches/unicode/django/db/backends/postgresql/base.py (modified) (11 diffs)
- django/branches/unicode/django/db/backends/postgresql/encodings.py (added)
- django/branches/unicode/django/db/backends/postgresql_psycopg2/base.py (modified) (3 diffs)
- django/branches/unicode/django/db/backends/sqlite3/base.py (modified) (6 diffs)
- django/branches/unicode/django/template/defaulttags.py (modified) (2 diffs)
- django/branches/unicode/django/template/__init__.py (modified) (7 diffs)
- django/branches/unicode/django/utils/encoding.py (modified) (2 diffs)
- django/branches/unicode/tests/modeltests/basic/models.py (modified) (1 diff)
- django/branches/unicode/tests/modeltests/custom_columns/models.py (modified) (3 diffs)
- django/branches/unicode/tests/modeltests/custom_pk/models.py (modified) (2 diffs)
- django/branches/unicode/tests/modeltests/fixtures/models.py (modified) (5 diffs)
- django/branches/unicode/tests/modeltests/generic_relations/models.py (modified) (3 diffs)
- django/branches/unicode/tests/modeltests/lookup/models.py (modified) (3 diffs)
- django/branches/unicode/tests/modeltests/many_to_one/models.py (modified) (1 diff)
- django/branches/unicode/tests/modeltests/model_forms/models.py (modified) (1 diff)
- django/branches/unicode/tests/modeltests/or_lookups/models.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/forms/regressions.py (modified) (1 diff)
- django/branches/unicode/tests/regressiontests/templates/tests.py (modified) (2 diffs)
- django/branches/unicode/tests/regressiontests/templates/unicode.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode/django/db/backends/mysql/base.py
r4937 r4971 82 82 'conv': django_conversions, 83 83 'charset': 'utf8', 84 'use_unicode': False,84 'use_unicode': True, 85 85 } 86 86 if settings.DATABASE_USER: django/branches/unicode/django/db/backends/mysql_old/base.py
r4937 r4971 90 90 'passwd': settings.DATABASE_PASSWORD, 91 91 'conv': django_conversions, 92 'use_unicode': True, 92 93 } 93 94 if settings.DATABASE_HOST.startswith('/'): … … 102 103 if self.connection.get_server_info() >= '4.1': 103 104 cursor.execute("SET NAMES 'utf8'") 105 cursor.execute("SET CHARACTER SET 'utf8'") 104 106 else: 105 107 cursor = self.connection.cursor() django/branches/unicode/django/db/backends/postgresql/base.py
r4937 r4971 5 5 """ 6 6 7 from django.utils.encoding import smart_str, smart_unicode 7 8 from django.db.backends import util 9 from django.db.backends.postgresql.encodings import ENCODING_MAP 8 10 try: 9 11 import psycopg as Database … … 21 23 from django.utils._threading_local import local 22 24 23 def smart_basestring(s, charset):24 if isinstance(s, unicode):25 return s.encode(charset)26 return s27 28 25 class UnicodeCursorWrapper(object): 29 26 """ … … 33 30 This is necessary because psycopg doesn't apply any DB quoting to 34 31 parameters that are Unicode strings. If a param is Unicode, this will 35 convert it to a bytestring using DEFAULT_CHARSET before passing it to 36 psycopg. 32 convert it to a bytestring using database client's encoding before passing 33 it to psycopg. 34 35 All results retrieved from the database are converted into Unicode strings 36 before being returned to the caller. 37 37 """ 38 38 def __init__(self, cursor, charset): … … 41 41 42 42 def execute(self, sql, params=()): 43 return self.cursor.execute(s ql, [smart_basestring(p, self.charset) for p in params])43 return self.cursor.execute(smart_str(sql, self.charset), [smart_str(p, self.charset, True) for p in params]) 44 44 45 45 def executemany(self, sql, param_list): 46 new_param_list = [tuple([smart_ basestring(p, self.charset) for p in params]) for params in param_list]46 new_param_list = [tuple([smart_str(p, self.charset) for p in params]) for params in param_list] 47 47 return self.cursor.executemany(sql, new_param_list) 48 48 … … 54 54 55 55 postgres_version = None 56 client_encoding = None 56 57 57 58 class DatabaseWrapper(local): … … 83 84 if set_tz: 84 85 cursor.execute("SET TIME ZONE %s", [settings.TIME_ZONE]) 85 cursor = UnicodeCursorWrapper(cursor, settings.DEFAULT_CHARSET) 86 if not settings.DATABASE_CHARSET: 87 cursor.execute("SHOW client_encoding") 88 encoding = ENCODING_MAP[cursor.fetchone()[0]] 89 else: 90 encoding = settings.DATABASE_CHARSET 91 cursor = UnicodeCursorWrapper(cursor, encoding) 92 global client_encoding 93 if not client_encoding: 94 # We assume the client encoding isn't going to change for random 95 # reasons. 96 client_encoding = encoding 86 97 global postgres_version 87 98 if not postgres_version: 88 99 cursor.execute("SELECT version()") 89 postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 100 postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 90 101 if settings.DEBUG: 91 102 return util.CursorDebugWrapper(cursor, self) … … 149 160 def get_deferrable_sql(): 150 161 return " DEFERRABLE INITIALLY DEFERRED" 151 162 152 163 def get_fulltext_search_sql(field_name): 153 164 raise NotImplementedError … … 163 174 all tables in the database (without actually removing the tables 164 175 themselves) and put the database in an empty 'initial' state 165 166 """ 176 177 """ 167 178 if tables: 168 179 if postgres_version[0] >= 8 and postgres_version[1] >= 1: 169 # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to* in order to be able to 170 # truncate tables referenced by a foreign key in any other table. The result is a 171 # single SQL TRUNCATE statement. 180 # Postgres 8.1+ can do 'TRUNCATE x, y, z...;'. In fact, it *has to* 181 # in order to be able to truncate tables referenced by a foreign 182 # key in any other table. The result is a single SQL TRUNCATE 183 # statement. 172 184 sql = ['%s %s;' % \ 173 185 (style.SQL_KEYWORD('TRUNCATE'), … … 175 187 )] 176 188 else: 177 # Older versions of Postgres can't do TRUNCATE in a single call, so they must use178 # a simple delete.189 # Older versions of Postgres can't do TRUNCATE in a single call, so 190 # they must use a simple delete. 179 191 sql = ['%s %s %s;' % \ 180 192 (style.SQL_KEYWORD('DELETE'), … … 238 250 style.SQL_TABLE(f.m2m_db_table()))) 239 251 return output 240 252 253 def typecast_string(s): 254 """ 255 Cast all returned strings to unicode strings. 256 """ 257 if not s: 258 return s 259 return smart_unicode(s, client_encoding) 260 241 261 # Register these custom typecasts, because Django expects dates/times to be 242 262 # in Python's native (standard-library) datetime/time format, whereas psycopg … … 249 269 Database.register_type(Database.new_type((1114,1184), "TIMESTAMP", util.typecast_timestamp)) 250 270 Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean)) 271 Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string)) 251 272 252 273 OPERATOR_MAPPING = { django/branches/unicode/django/db/backends/postgresql_psycopg2/base.py
r4937 r4971 8 8 try: 9 9 import psycopg2 as Database 10 import psycopg2.extensions 10 11 except ImportError, e: 11 12 from django.core.exceptions import ImproperlyConfigured … … 20 21 # Import copy of _thread_local.py from Python 2.4 21 22 from django.utils._threading_local import local 23 24 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) 22 25 23 26 postgres_version = None … … 48 51 self.connection = Database.connect(conn_string, **self.options) 49 52 self.connection.set_isolation_level(1) # make transactions transparent to all cursors 53 self.connection.set_client_encoding('UTF8') 50 54 cursor = self.connection.cursor() 51 55 cursor.tzinfo_factory = None django/branches/unicode/django/db/backends/sqlite3/base.py
r4937 r4971 27 27 Database.register_converter("TIMESTAMP", util.typecast_timestamp) 28 28 29 def utf8rowFactory(cursor, row):30 def utf8(s):31 if type(s) == unicode:32 return s.encode("utf-8")33 else:34 return s35 return [utf8(r) for r in row]36 37 29 try: 38 30 # Only exists in Python 2.4+ … … 61 53 self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc) 62 54 cursor = self.connection.cursor(factory=SQLiteCursorWrapper) 63 cursor.row_factory = utf8rowFactory64 55 if settings.DEBUG: 65 56 return util.CursorDebugWrapper(cursor, self) … … 77 68 def close(self): 78 69 from django.conf import settings 79 # If database is in memory, closing the connection destroys the database. 80 # To prevent accidental data loss, ignore close requests on an in-memory db. 70 # If database is in memory, closing the connection destroys the 71 # database. To prevent accidental data loss, ignore close requests on 72 # an in-memory db. 81 73 if self.connection is not None and settings.DATABASE_NAME != ":memory:": 82 74 self.connection.close() … … 154 146 155 147 def get_sql_flush(style, tables, sequences): 156 """ Return a list of SQL statements required to remove all data from157 all tables in the database (without actually removing thetables158 themselves) and put the database in an empty 'initial' state159 148 """ 149 Return a list of SQL statements required to remove all data from all tables 150 in the database (without actually removing the tables themselves) and put 151 the database in an empty 'initial' state. 160 152 """ 161 153 # NB: The generated SQL below is specific to SQLite … … 175 167 # No sequence reset required 176 168 return [] 177 169 178 170 def _sqlite_date_trunc(lookup_type, dt): 179 171 try: … … 205 197 'iendswith': "LIKE %s ESCAPE '\\'", 206 198 } 199 django/branches/unicode/django/template/defaulttags.py
r4909 r4971 5 5 from django.template import get_library, Library, InvalidTemplateLibrary 6 6 from django.conf import settings 7 from django.utils.encoding import smart_str 7 8 import sys 8 9 … … 325 326 from django.core.urlresolvers import reverse, NoReverseMatch 326 327 args = [arg.resolve(context) for arg in self.args] 327 kwargs = dict([( k, v.resolve(context)) for k, v in self.kwargs.items()])328 kwargs = dict([(smart_str(k,'ascii'), v.resolve(context)) for k, v in self.kwargs.items()]) 328 329 try: 329 330 return reverse(self.view_name, args=args, kwargs=kwargs) django/branches/unicode/django/template/__init__.py
r4690 r4971 61 61 from django.utils.functional import curry 62 62 from django.utils.text import smart_split 63 from django.utils.encoding import smart_unicode, smart_str 63 64 64 65 __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') … … 119 120 pass 120 121 122 class TemplateEncodingError(Exception): 123 pass 124 121 125 class VariableDoesNotExist(Exception): 122 126 … … 124 128 self.msg = msg 125 129 self.params = params 126 130 127 131 def __str__(self): 128 132 return self.msg % self.params 129 133 130 134 class InvalidTemplateLibrary(Exception): 131 135 pass … … 152 156 def __init__(self, template_string, origin=None, name='<Unknown Template>'): 153 157 "Compilation stage" 158 try: 159 template_string = smart_unicode(template_string) 160 except UnicodeDecodeError: 161 raise TemplateEncodingError("Templates can only be constructed from unicode or UTF-8 strings.") 154 162 if settings.TEMPLATE_DEBUG and origin == None: 155 163 origin = StringOrigin(template_string) … … 706 714 else: 707 715 bits.append(node) 708 return ''.join( bits)716 return ''.join([smart_str(b, settings.DEFAULT_CHARSET) for b in bits]) 709 717 710 718 def get_nodes_by_type(self, nodetype): … … 716 724 717 725 def render_node(self, node, context): 718 return (node.render(context))726 return node.render(context) 719 727 720 728 class DebugNodeList(NodeList): … … 751 759 return "<Variable Node: %s>" % self.filter_expression 752 760 753 def encode_output(self, output):754 # Check type so that we don't run str() on a Unicode object755 if not isinstance(output, basestring):756 try:757 return str(output)758 except UnicodeEncodeError:759 # If __str__() returns a Unicode object, convert it to bytestring.760 return unicode(output).encode(settings.DEFAULT_CHARSET)761 elif isinstance(output, unicode):762 return output.encode(settings.DEFAULT_CHARSET)763 else:764 return output765 766 761 def render(self, context): 767 output = self.filter_expression.resolve(context) 768 return self.encode_output(output) 762 return self.filter_expression.resolve(context) 769 763 770 764 class DebugVariableNode(VariableNode): 771 765 def render(self, context): 772 766 try: 773 output =self.filter_expression.resolve(context)767 return self.filter_expression.resolve(context) 774 768 except TemplateSyntaxError, e: 775 769 if not hasattr(e, 'source'): 776 770 e.source = self.source 777 771 raise 778 return self.encode_output(output)779 772 780 773 def generic_tag_compiler(params, defaults, name, node_class, parser, token): django/branches/unicode/django/utils/encoding.py
r4923 r4971 1 import types 1 2 from django.conf import settings 2 3 from django.utils.functional import Promise 3 4 4 def smart_unicode(s): 5 if isinstance(s, Promise): 6 # The input is the result of a gettext_lazy() call, or similar. It will 7 # already be encoded in DEFAULT_CHARSET on evaluation and we don't want 8 # to evaluate it until render time. 9 # FIXME: This isn't totally consistent, because it eventually returns a 10 # bytestring rather than a unicode object. It works wherever we use 11 # smart_unicode() at the moment. Fixing this requires work in the 12 # i18n internals. 13 return s 5 def smart_unicode(s, encoding='utf-8'): 6 """ 7 Returns a unicode object representing 's'. Treats bytestrings using the 8 'encoding' codec. 9 """ 10 #if isinstance(s, Promise): 11 # # The input is the result of a gettext_lazy() call, or similar. It will 12 # # already be encoded in DEFAULT_CHARSET on evaluation and we don't want 13 # # to evaluate it until render time. 14 # # FIXME: This isn't totally consistent, because it eventually returns a 15 # # bytestring rather than a unicode object. It works wherever we use 16 # # smart_unicode() at the moment. Fixing this requires work in the 17 # # i18n internals. 18 # return s 14 19 if not isinstance(s, basestring,): 15 20 if hasattr(s, '__unicode__'): 16 21 s = unicode(s) 17 22 else: 18 s = unicode(str(s), settings.DEFAULT_CHARSET)23 s = unicode(str(s), encoding) 19 24 elif not isinstance(s, unicode): 20 s = unicode(s, settings.DEFAULT_CHARSET)25 s = unicode(s, encoding) 21 26 return s 27 28 def smart_str(s, encoding='utf-8', strings_only=False): 29 """ 30 Returns a bytestring version of 's', encoded as specified in 'encoding'. 31 32 If strings_only is True, don't convert (some) non-string-like objects. 33 """ 34 if strings_only and isinstance(s, (types.NoneType, int)): 35 return s 36 if not isinstance(s, basestring): 37 try: 38 return str(s) 39 except UnicodeEncodeError: 40 return unicode(s).encode(encoding) 41 elif isinstance(s, unicode): 42 return s.encode(encoding) 43 elif s and encoding != 'utf-8': 44 return s.decode('utf-8').encode(encoding) 45 else: 46 return s 22 47 23 48 class StrAndUnicode(object): … … 29 54 """ 30 55 def __str__(self): 56 # XXX: (Malcolm) Correct encoding? Be variable and use UTF-8 as 57 # default? 31 58 return self.__unicode__().encode(settings.DEFAULT_CHARSET) 32 59 django/branches/unicode/tests/modeltests/basic/models.py
r4505 r4971 352 352 >>> a101 = Article.objects.get(pk=101) 353 353 >>> a101.headline 354 'Article 101'354 u'Article 101' 355 355 356 356 # You can create saved objects in a single step django/branches/unicode/tests/modeltests/custom_columns/models.py
r4429 r4971 7 7 8 8 If your database table name is different than your model name, use the 9 ``db_table`` Meta attribute. This has no effect on the API used to 9 ``db_table`` Meta attribute. This has no effect on the API used to 10 10 query the database. 11 11 12 If you need to use a table name for a many-to-many relationship that differs 13 from the default generated name, use the ``db_table`` parameter on the 12 If you need to use a table name for a many-to-many relationship that differs 13 from the default generated name, use the ``db_table`` parameter on the 14 14 ManyToMany field. This has no effect on the API for querying the database. 15 15 … … 38 38 class Meta: 39 39 ordering = ('headline',) 40 40 41 41 __test__ = {'API_TESTS':""" 42 42 # Create a Author. … … 76 76 >>> a = Author.objects.get(last_name__exact='Smith') 77 77 >>> a.first_name 78 'John'78 u'John' 79 79 >>> a.last_name 80 'Smith'80 u'Smith' 81 81 >>> a.firstname 82 82 Traceback (most recent call last): django/branches/unicode/tests/modeltests/custom_pk/models.py
r3826 r4971 63 63 [<Employee: Dan Jones>, <Employee: Fran Jones>] 64 64 >>> Employee.objects.in_bulk(['ABC123', 'XYZ456']) 65 { 'XYZ456': <Employee: Fran Jones>,'ABC123': <Employee: Dan Jones>}65 {u'XYZ456': <Employee: Fran Jones>, u'ABC123': <Employee: Dan Jones>} 66 66 67 67 >>> b = Business(name='Sears') … … 73 73 [<Business: Sears>] 74 74 >>> Business.objects.in_bulk(['Sears']) 75 { 'Sears': <Business: Sears>}75 {u'Sears': <Business: Sears>} 76 76 77 77 >>> Business.objects.filter(name__exact='Sears') django/branches/unicode/tests/modeltests/fixtures/models.py
r4796 r4971 2 2 37. Fixtures. 3 3 4 Fixtures are a way of loading data into the database in bulk. Fixure data 5 can be stored in any serializable format (including JSON and XML). Fixtures 4 Fixtures are a way of loading data into the database in bulk. Fixure data 5 can be stored in any serializable format (including JSON and XML). Fixtures 6 6 are identified by name, and are stored in either a directory named 'fixtures' 7 in the application directory, on in one of the directories named in the 7 in the application directory, on in one of the directories named in the 8 8 FIXTURE_DIRS setting. 9 9 """ … … 17 17 def __str__(self): 18 18 return self.headline 19 19 20 20 class Meta: 21 21 ordering = ('-pub_date', 'headline') 22 22 23 23 __test__ = {'API_TESTS': """ 24 24 >>> from django.core import management 25 25 >>> from django.db.models import get_app 26 26 27 # Reset the database representation of this app. 27 # Reset the database representation of this app. 28 28 # This will return the database to a clean initial state. 29 29 >>> management.flush(verbosity=0, interactive=False) … … 43 43 [<Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>] 44 44 45 # Load fixture 3, XML format. 45 # Load fixture 3, XML format. 46 46 >>> management.load_data(['fixture3.xml'], verbosity=0) 47 47 >>> Article.objects.all() … … 66 66 67 67 # Try to load fixture 2 using format discovery; this will fail 68 # because there are two fixture2's in the fixtures directory 68 # because there are two fixture2's in the fixtures directory 69 69 >>> management.load_data(['fixture2'], verbosity=0) # doctest: +ELLIPSIS 70 70 Multiple fixtures named 'fixture2' in '...fixtures'. Aborting. … … 82 82 class SampleTestCase(TestCase): 83 83 fixtures = ['fixture1.json', 'fixture2.json'] 84 84 85 85 def testClassFixtures(self): 86 86 "Check that test case has installed 4 fixture objects" django/branches/unicode/tests/modeltests/generic_relations/models.py
r4796 r4971 111 111 # Original list of tags: 112 112 >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] 113 [( 'clearish', <ContentType: mineral>, 1), ('fatty', <ContentType: vegetable>, 2), ('hairy', <ContentType: animal>, 1), ('salty', <ContentType: vegetable>, 2), ('shiny', <ContentType: animal>, 2), ('yellow', <ContentType: animal>, 1)]113 [(u'clearish', <ContentType: mineral>, 1), (u'fatty', <ContentType: vegetable>, 2), (u'hairy', <ContentType: animal>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2), (u'yellow', <ContentType: animal>, 1)] 114 114 115 115 >>> lion.delete() 116 116 >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] 117 [( 'clearish', <ContentType: mineral>, 1), ('fatty', <ContentType: vegetable>, 2), ('salty', <ContentType: vegetable>, 2), ('shiny', <ContentType: animal>, 2)]117 [(u'clearish', <ContentType: mineral>, 1), (u'fatty', <ContentType: vegetable>, 2), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] 118 118 119 119 # If Generic Relation is not explicitly defined, any related objects … … 121 121 >>> quartz.delete() 122 122 >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] 123 [( 'clearish', <ContentType: mineral>, 1), ('fatty', <ContentType: vegetable>, 2), ('salty', <ContentType: vegetable>, 2), ('shiny', <ContentType: animal>, 2)]123 [(u'clearish', <ContentType: mineral>, 1), (u'fatty', <ContentType: vegetable>, 2), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] 124 124 125 125 # If you delete a tag, the objects using the tag are unaffected … … 130 130 [<TaggedItem: salty>] 131 131 >>> [(t.tag, t.content_type, t.object_id) for t in TaggedItem.objects.all()] 132 [( 'clearish', <ContentType: mineral>, 1), ('salty', <ContentType: vegetable>, 2), ('shiny', <ContentType: animal>, 2)]132 [(u'clearish', <ContentType: mineral>, 1), (u'salty', <ContentType: vegetable>, 2), (u'shiny', <ContentType: animal>, 2)] 133 133 134 134 """} django/branches/unicode/tests/modeltests/lookup/models.py
r4488 r4971 100 100 # you can specify which fields you want to retrieve. 101 101 >>> Article.objects.values('headline') 102 [{'headline': 'Article 5'}, {'headline': 'Article 6'}, {'headline': 'Article 4'}, {'headline': 'Article 2'}, {'headline': 'Article 3'}, {'headline': 'Article 7'}, {'headline':'Article 1'}]102 [{'headline': u'Article 5'}, {'headline': u'Article 6'}, {'headline': u'Article 4'}, {'headline': u'Article 2'}, {'headline': u'Article 3'}, {'headline': u'Article 7'}, {'headline': u'Article 1'}] 103 103 >>> Article.objects.filter(pub_date__exact=datetime(2005, 7, 27)).values('id') 104 104 [{'id': 2}, {'id': 3}, {'id': 7}] … … 110 110 ... i.sort() 111 111 ... i 112 [('headline', 'Article 5'), ('id', 5)]113 [('headline', 'Article 6'), ('id', 6)]114 [('headline', 'Article 4'), ('id', 4)]115 [('headline', 'Article 2'), ('id', 2)]116 [('headline', 'Article 3'), ('id', 3)]117 [('headline', 'Article 7'), ('id', 7)]118 [('headline', 'Article 1'), ('id', 1)]112 [('headline', u'Article 5'), ('id', 5)] 113 [('headline', u'Article 6'), ('id', 6)] 114 [('headline', u'Article 4'), ('id', 4)] 115 [('headline', u'Article 2'), ('id', 2)] 116 [('headline', u'Article 3'), ('id', 3)] 117 [('headline', u'Article 7'), ('id', 7)] 118 [('headline', u'Article 1'), ('id', 1)] 119 119 120 120 # You can use values() with iterator() for memory savings, because iterator() … … 124 124 ... i.sort() 125 125 ... i 126 [('headline', 'Article 5'), ('id', 5)]127 [('headline', 'Article 6'), ('id', 6)]128 [('headline', 'Article 4'), ('id', 4)]129 [('headline', 'Article 2'), ('id', 2)]130 [('headline', 'Article 3'), ('id', 3)]131 [('headline', 'Article 7'), ('id', 7)]132 [('headline', 'Article 1'), ('id', 1)]126 [('headline', u'Article 5'), ('id', 5)] 127 [('headline', u'Article 6'), ('id', 6)] 128 [('headline', u'Article 4'), ('id', 4)] 129 [('headline', u'Article 2'), ('id', 2)] 130 [('headline', u'Article 3'), ('id', 3)] 131 [('headline', u'Article 7'), ('id', 7)] 132 [('headline', u'Article 1'), ('id', 1)] 133 133 134 134 # if you don't specify which fields, all are returned django/branches/unicode/tests/modeltests/many_to_one/models.py
r3661 r4971 48 48 >>> r = a.reporter 49 49 >>> r.first_name, r.last_name 50 ( 'John','Smith')50 (u'John', u'Smith') 51 51 52 52 # Create an Article via the Reporter object. django/branches/unicode/tests/modeltests/model_forms/models.py
r4796 r4971 214 214 >>> new_art = Article.objects.get(id=1) 215 215 >>> new_art.headline 216 'New headline'216 u'New headline' 217 217 218 218 Add some categories and test the many-to-many form output. django/branches/unicode/tests/modeltests/or_lookups/models.py
r4283 r4971 101 101 102 102 >>> list(Article.objects.filter(Q(headline__startswith='Hello'), Q(headline__contains='bye')).values()) 103 [{'headline': 'Hello and goodbye', 'pub_date': datetime.datetime(2005, 11, 29, 0, 0), 'id': 3}]103 [{'headline': u'Hello and goodbye', 'pub_date': datetime.datetime(2005, 11, 29, 0, 0), 'id': 3}] 104 104 105 105 >>> Article.objects.filter(Q(headline__startswith='Hello')).in_bulk([1,2]) django/branches/unicode/tests/regressiontests/forms/regressions.py
r4924 r4971 23 23 >>> print f.as_p() 24 24 <p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 25 >>> activate('de') 26 >>> print f.as_p() 27 <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 28 >>> deactivate() 25 26 # XFAIL 27 # >>> activate('de') 28 # >>> print f.as_p() 29 # <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> 30 # >>> deactivate() 29 31 30 32 Unicode decoding problems... django/branches/unicode/tests/regressiontests/templates/tests.py
r4901 r4971 12 12 from django.utils.tzinfo import LocalTimezone 13 13 from datetime import datetime, timedelta 14 from unicode import unicode_tests 14 15 import unittest 16 17 # Some other tests we would like to run 18 __test__ = { 19 'unicode': unicode_tests, 20 } 15 21 16 22 ################################# … … 203 209 'basic-syntax36': (r'{{ var|join:"" }}', {'var': ['a', 'b', 'c']}, 'abc'), 204 210 205 # If a variable has a __str__() that returns a Unicode object, the value206 # will be converted to a bytestring.211 # Make sure that any unicode strings are converted to bytestrings 212 # in the final output. 207 213 'basic-syntax37': (r'{{ var }}', {'var': UnicodeInStrClass()}, '\xc5\xa0\xc4\x90\xc4\x86\xc5\xbd\xc4\x87\xc5\xbe\xc5\xa1\xc4\x91'), 208 214
