Ticket #924: 924.5.diff
File 924.5.diff, 3.3 KB (added by , 18 years ago) |
---|
-
django/template/defaultfilters.py
19 19 20 20 def capfirst(value): 21 21 "Capitalizes the first character of the value" 22 value = str(value) 23 return value and value[0].upper() + value[1:] 22 if not value: 23 return value 24 else: 25 value = str(value).decode(settings.DEFAULT_CHARSET) 26 value = value[0].upper() + value[1:] 27 return value.encode(settings.DEFAULT_CHARSET) 24 28 25 29 def fix_ampersands(value): 26 30 "Replaces ampersands with ``&`` entities" … … 54 58 55 59 def lower(value): 56 60 "Converts a string into all lowercase" 57 return value.lower()61 return str(value).decode(settings.DEFAULT_CHARSET).lower().encode(settings.DEFAULT_CHARSET) 58 62 59 63 def make_list(value): 60 64 """ … … 84 88 85 89 def title(value): 86 90 "Converts a string into titlecase" 87 return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())91 return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), str(value).decode(settings.DEFAULT_CHARSET).title()).encode(settings.DEFAULT_CHARSET) 88 92 89 93 def truncatewords(value, arg): 90 94 """ … … 97 101 length = int(arg) 98 102 except ValueError: # invalid literal for int() 99 103 return value # Fail silently. 100 if not isinstance(value, basestring): 101 value = str(value) 102 return truncate_words(value, length) 104 return truncate_words(str(value).decode(settings.DEFAULT_CHARSET), length).encode(settings.DEFAULT_CHARSET) 103 105 104 106 def upper(value): 105 107 "Converts a string into all uppercase" 106 return value.upper()108 return str(value).decode(settings.DEFAULT_CHARSET).upper().encode(settings.DEFAULT_CHARSET) 107 109 108 110 def urlencode(value): 109 111 "Escapes a value for use in a URL" … … 136 138 Argument: number of characters to wrap the text at. 137 139 """ 138 140 from django.utils.text import wrap 139 return wrap(str(value) , int(arg))141 return wrap(str(value).decode(settings.DEFAULT_CHARSET), int(arg)).encode(settings.DEFAULT_CHARSET) 140 142 141 143 def ljust(value, arg): 142 144 """ … … 144 146 145 147 Argument: field size 146 148 """ 147 return str(value). ljust(int(arg))149 return str(value).decode(settings.DEFAULT_CHARSET).ljust(int(arg)).encode(settings.DEFAULT_CHARSET) 148 150 149 151 def rjust(value, arg): 150 152 """ … … 152 154 153 155 Argument: field size 154 156 """ 155 return str(value). rjust(int(arg))157 return str(value).decode(settings.DEFAULT_CHARSET).rjust(int(arg)).encode(settings.DEFAULT_CHARSET) 156 158 157 159 def center(value, arg): 158 160 "Centers the value in a field of a given width" 159 return str(value). center(int(arg))161 return str(value).decode(settings.DEFAULT_CHARSET).center(int(arg)).encode(settings.DEFAULT_CHARSET) 160 162 161 163 def cut(value, arg): 162 164 "Removes all values of arg from the given string" … … 236 238 237 239 def length(value): 238 240 "Returns the length of the value - useful for lists" 241 if isinstance(value,str): 242 value=value.decode(settings.DEFAULT_CHARSET) 239 243 return len(value) 240 244 241 245 def length_is(value, arg): 242 246 "Returns a boolean of whether the value's length is the argument" 247 if isinstance(value,str): 248 value=value.decode(settings.DEFAULT_CHARSET) 243 249 return len(value) == int(arg) 244 250 245 251 def random(value):