Snippet List
This filter truncates words like the original truncate words Django filter, but instead of being based on the number of words, it's based on the number of characters. I found the need for this when building a website where i'd have to show labels on really small text boxes and truncating by words didn't always gave me the best results (and truncating by character is...well...not that elegant).
Usage example:
{{var|truncatewords_by_chars:"16 2 4"}}
If string lenght is higher than 16, truncates by 2 words, if lesser, truncates by 4 words.
- filter
- truncate
- character
- word
There is a commonly encountered problem with Django and character sets. Windows applications such as Word/Outlook add characters that are not valid ISO-8859-1 and this results in problems saving a Django model to a database with a Latin 1 encoding. These characters should also be converted to avoid any display issues for the end users even if you are using a UTF-8 database encoding.
The topic is well covered at [Effbot](http://effbot.org/zone/unicode-gremlins.htm) and contains a list of appropriate conversions for each of hte problem characters.
Correcting this for all of your Django models is another issue. Do you handle the re-encoding during the form validation? The save for each model? Create a base class that all your models need to inherit from?
The simplest solution I have created leverages [Signals](http://code.djangoproject.com/wiki/Signals)
Combining the re-encoding method suggested at Effbot and the pre_save signal gives you the ability to convert all the problem characters right before the save occurs for any model.
**kill_gremlins method replaced with Gabor's suggestion**
- django
- python
- unicode
- latin1
- character
- encoding
2 snippets posted so far.