Ticket #440: 440.2.patch

File 440.2.patch, 2.5 KB (added by Maniac@…, 19 years ago)

Patch with parametrized charset

  • utils/httpwrappers.py

     
    11from Cookie import SimpleCookie
    22from pprint import pformat
    33import datastructures
     4from django.conf import settings
    45
    56DEFAULT_MIME_TYPE = 'text/html'
    67
     
    131132    "A basic HTTP response, with content and dictionary-accessed headers"
    132133    def __init__(self, content='', mimetype=DEFAULT_MIME_TYPE):
    133134        self.content = content
    134         self.headers = {'Content-Type':mimetype}
     135        self.headers = {'Content-Type':mimetype + '; charset=' + settings.DEFAULT_CHARSET}
    135136        self.cookies = SimpleCookie()
    136137        self.status_code = 200
    137138
  • conf/project_template/settings/main.py

     
    99MANAGERS = ADMINS
    1010
    1111LANGUAGE_CODE = 'en-us'
     12DEFAULT_CHARSET = 'utf-8'
    1213
    1314DATABASE_ENGINE = 'postgresql' # 'postgresql', 'mysql', or 'sqlite3'.
    1415DATABASE_NAME = ''             # Or path to database file if using sqlite3.
  • conf/settings.py

     
    5050# move the time zone info into os.environ
    5151os.environ['TZ'] = me.TIME_ZONE
    5252
     53# if charset is not set, use utf-8
     54if not hasattr(me, 'DEFAULT_CHARSET'):
     55    me.DEFAULT_CHARSET='utf-8'
     56
    5357# finally, clean up my namespace
    5458for k in dir(me):
    5559    if not k.startswith('_') and k != 'me' and k != k.upper():
  • core/formfields.py

     
    22from django.core.exceptions import PermissionDenied
    33from django.utils.html import escape
    44from django.utils.text import fix_microsoft_characters
     5from django.conf import settings
    56
    67FORM_FIELD_ID_PREFIX = 'id_'
    78
     
    222223        self.validator_list = [self.isValidLength, self.hasNoNewlines] + validator_list
    223224
    224225    def isValidLength(self, data, form):
    225         if data and self.maxlength and len(data) > self.maxlength:
     226        if data and self.maxlength and len(data.decode(settings.DEFAULT_CHARSET)) > self.maxlength:
    226227            raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength
    227228
    228229    def hasNoNewlines(self, data, form):
Back to Top