Code

Ticket #2489: capfirst.diff

File capfirst.diff, 671 bytes (added by nesh <nesh [at] studioquattro [dot] co [dot] yu>, 7 years ago)

small fix for capfirst filter to enable unicode strings

Line 
1Index: /www-libs/django/django/template/defaultfilters.py
2===================================================================
3--- /www-libs/django/django/template/defaultfilters.py  (revision 4300)
4+++ /www-libs/django/django/template/defaultfilters.py  (working copy)
5@@ -19,7 +19,11 @@
6 
7 def capfirst(value):
8     "Capitalizes the first character of the value"
9-    value = str(value)
10+    if isinstance(value, str):
11+        # convert to unicode string
12+        value = unicode(value, settings.DEFAULT_CHARSET)
13+    elif not isinstance(value, basestring):
14+        value = unicode(value)
15     return value and value[0].upper() + value[1:]
16 
17 def fix_ampersands(value):