Changes between Version 6 and Version 7 of UnicodeBranch

05/12/2007 02:29:45 AM (11 years ago)
Malcolm Tredinnick

The porting section looked too scary. Added a cheatsheet version as well.


  • UnicodeBranch

    v6 v7  
    4949Finally, some documentation needs to be written describing good practices for creating unicode-aware Django apps.
    51 == Porting Applications ==
     51== Porting Applications (The Quick Checklist) ==
    5353One 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.
     55A 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:
     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.
     59 2. Change the {{{__str__}}} methods on your models to be {{{__unicode__}}} methods. Just change the name. Usually, nothing else will be needed.
     61 3. Use the {{{FILE_CHARSET}}} setting if your on-disk template files are not UTF-8 encoded.
     63That is all. Enjoy!
     65== Things To Consider When Writing Applications ==
    5567'''** 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). **'''
    6577 * 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.
     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.
    6781=== Databases ===
Back to Top