Changes between Version 7 and Version 8 of UnicodeBranch


Ignore:
Timestamp:
05/12/2007 05:14:53 AM (8 years ago)
Author:
mtredinnick
Comment:

Cheatsheet update.

Legend:

Unmodified
Added
Removed
Modified
  • UnicodeBranch

    v7 v8  
    5555A 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:
    5656
    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.
     57 1. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed.
    5858
    59  2. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed.
     59 2. Look for any {{{str()}}} calls in your code that operate on model fields. These should almost always be changed to {{{smart_unicode()}}} calls (which is imported from {{{django.utils.encoding}}}).
    6060
    61  3. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded.
     61 3. 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.
     62
     63 4. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded.
    6264
    6365That is all. Enjoy!
     
    7779 * 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.
    7880
    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.
     81 * 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___}}} or {{{__str__}}} 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.
    8082
    8183=== Databases ===
Back to Top