Changes between Version 6 and Version 7 of UnicodeBranch
- Timestamp:
- May 12, 2007, 2:29:45 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
UnicodeBranch
v6 v7 49 49 Finally, some documentation needs to be written describing good practices for creating unicode-aware Django apps. 50 50 51 == Porting Applications ==51 == Porting Applications (The Quick Checklist) == 52 52 53 53 One of the design goals of the Unicode branch is that very litte significant changes to existing third-party code should be required. However, there are some thigns that developers should be aware of when writing applications designed to handle international input. 54 55 A detailed list of things you might wish to think about when writing your code is given below. However, for the programmer on a deadline, here is the cheatsheet version: 56 57 1. Make sure your database can store all the data you will send to it. Usually, this means ensuring it is using UTF-8 (or similar) encoding internally. 58 59 2. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed. 60 61 3. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded. 62 63 That is all. Enjoy! 64 65 == Things To Consider When Writing Applications == 54 66 55 67 '''** This section is no doubt incomplete. User experiences are welcome. If you discover something that is necessary to change, please add a bullet-point to the list (although we may edit the list periodically to be more coherent). **''' … … 64 76 65 77 * Field sizes for text fields such as !TextField and !CharField are specified in terms of characters, not the number of bytes used in the encoding in the database. All databases supported by Django can handle this (i.e. their ''VARCHAR'' fields are sized in terms of characaters and can store unicode characters). So you do '''not''' need to worry about how many bytes the encoded version of your data will take up when working with lengths. 78 79 * You might find the functions {{{django.utils.encoding.smart_string()}}} and {{{dhango.utils.encoding.smart_unicode()}}} useful in your application code. Particularly the latter is handy: it takes a bytestring or unicode string and returns a unicode string. It also knows to convert objects with a {{{__unicode___}} method into unicode strings. So if you have a string that is either a bytestring or unicode and you wish to make it uniform -- always a unicode string -- call {{{smart_unicode()}}} on the object. 66 80 67 81 === Databases ===