Django

Code

Changeset 786

Show
Ignore:
Timestamp:
10/05/05 21:27:08 (3 years ago)
Author:
adrian
Message:

Fixed #333 and #440 -- Split DEFAULT_MIME_TYPE setting into DEFAULT_CONTENT_TYPE and DEFAULT_CHARSET. Thanks, Maniac.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/global_settings.py

    r782 r786  
    3333MANAGERS = ADMINS 
    3434 
    35 # Default MIME type to use for all HttpResponse objects, if a MIME type 
    36 # isn't manually specified. This is directly used as the Content-Type header. 
    37 DEFAULT_MIME_TYPE = 'text/html; charset=utf-8' 
     35# Default content type and charset to use for all HttpResponse objects, if a 
     36# MIME type isn't manually specified. These are used to construct the 
     37# Content-Type header. 
     38DEFAULT_CONTENT_TYPE = 'text/html' 
     39DEFAULT_CHARSET = 'utf-8' 
    3840 
    3941# E-mail address that error messages come from. 
  • django/trunk/django/core/formfields.py

    r702 r786  
    22from django.core.exceptions import PermissionDenied 
    33from django.utils.html import escape 
     4from django.conf.settings import DEFAULT_CHARSET 
    45 
    56FORM_FIELD_ID_PREFIX = 'id_' 
     
    222223 
    223224    def isValidLength(self, data, form): 
    224         if data and self.maxlength and len(data) > self.maxlength: 
     225        if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength: 
    225226            raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength 
    226227 
     
    236237            maxlength = 'maxlength="%s" ' % self.maxlength 
    237238        if isinstance(data, unicode): 
    238             data = data.encode('utf-8'
     239            data = data.encode(DEFAULT_CHARSET
    239240        return '<input type="text" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 
    240241            (FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '', 
     
    265266            data = '' 
    266267        if isinstance(data, unicode): 
    267             data = data.encode('utf-8'
     268            data = data.encode(DEFAULT_CHARSET
    268269        return '<textarea id="%s" class="v%s%s" name="%s" rows="%s" cols="%s">%s</textarea>' % \ 
    269270            (FORM_FIELD_ID_PREFIX + self.field_name, self.__class__.__name__, self.is_required and ' required' or '', 
  • django/trunk/django/core/handlers/modpython.py

    r518 r786  
    151151def populate_apache_request(http_response, mod_python_req): 
    152152    "Populates the mod_python request object with an HttpResponse" 
    153     mod_python_req.content_type = http_response['Content-Type'] or httpwrappers.DEFAULT_MIME_TYPE 
     153    from django.conf import settings 
     154    mod_python_req.content_type = http_response['Content-Type'] 
    154155    for key, value in http_response.headers.items(): 
    155156        if key != 'Content-Type': 
     
    158159        mod_python_req.headers_out.add('Set-Cookie', c.output(header='')) 
    159160    mod_python_req.status = http_response.status_code 
    160     mod_python_req.write(http_response.get_content_as_string('utf-8')) 
     161    mod_python_req.write(http_response.get_content_as_string(settings.DEFAULT_CHARSET)) 
    161162 
    162163def handler(req): 
  • django/trunk/django/core/handlers/wsgi.py

    r636 r786  
    168168        for c in response.cookies.values(): 
    169169            response_headers.append(('Set-Cookie', c.output(header=''))) 
    170         output = [response.get_content_as_string('utf-8')] 
     170        output = [response.get_content_as_string(settings.DEFAULT_CHARSET)] 
    171171        start_response(status, response_headers) 
    172172        return output 
  • django/trunk/django/core/template.py

    r644 r786  
    5656""" 
    5757import re 
     58from django.conf.settings import DEFAULT_CHARSET 
    5859 
    5960__all__ = ('Template','Context','compile_string') 
     
    475476            output = str(output) 
    476477        elif isinstance(output, unicode): 
    477             output = output.encode('utf-8'
     478            output = output.encode(DEFAULT_CHARSET
    478479        return output 
    479480 
  • django/trunk/django/middleware/cache.py

    r178 r786  
    7777        """ 
    7878        if request._cache_middleware_set_cache: 
    79             content = response.get_content_as_string('utf-8'
     79            content = response.get_content_as_string(settings.DEFAULT_CHARSET
    8080            if request._cache_middleware_accepts_gzip: 
    8181                content = compress_string(content) 
  • django/trunk/django/middleware/common.py

    r782 r786  
    7777        # Use ETags, if requested. 
    7878        if settings.USE_ETAGS: 
    79             etag = md5.new(response.get_content_as_string('utf-8')).hexdigest() 
     79            etag = md5.new(response.get_content_as_string(settings.DEFAULT_CHARSET)).hexdigest() 
    8080            if request.META.get('HTTP_IF_NONE_MATCH') == etag: 
    8181                response = httpwrappers.HttpResponseNotModified() 
  • django/trunk/django/utils/httpwrappers.py

    r711 r786  
    22from pprint import pformat 
    33from urllib import urlencode 
    4 import datastructures 
     4from django.utils import datastructures 
    55 
    66class HttpRequest(object): # needs to be new-style class because subclasses define "property"s 
     
    140140    def __init__(self, content='', mimetype=None): 
    141141        if not mimetype: 
    142             from django.conf.settings import DEFAULT_MIME_TYPE 
    143             mimetype = DEFAULT_MIME_TYPE 
     142            from django.conf.settings import DEFAULT_CONTENT_TYPE, DEFAULT_CHARSET 
     143            mimetype = "%s; charset=%s" % (DEFAULT_CONTENT_TYPE, DEFAULT_CHARSET) 
    144144        self.content = content 
    145145        self.headers = {'Content-Type':mimetype} 
  • django/trunk/django/views/decorators/cache.py

    r175 r786  
    22from django.utils.httpwrappers import HttpResponseNotModified 
    33from django.utils.text import compress_string 
     4from django.conf.settings import DEFAULT_CHARSET 
    45import datetime, md5 
    56 
     
    2627        if response is None: 
    2728            response = view_func(request, *args, **kwargs) 
    28             content = response.get_content_as_string('utf-8'
     29            content = response.get_content_as_string(DEFAULT_CHARSET
    2930            if accepts_gzip: 
    3031                content = compress_string(content)