Django

Code

Changeset 791

Show
Ignore:
Timestamp:
10/06/05 09:49:22 (3 years ago)
Author:
rjwittams
Message:

Merged to r789

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/conf/global_settings.py

    r780 r791  
    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. 
     
    100102# is an admin. 
    101103ADMIN_FOR = [] 
     104 
     105# Whether to check the flat-pages table as a last resort for all 404 errors. 
     106USE_FLAT_PAGES = True 
    102107 
    103108# 404s that may be ignored. 
  • django/branches/new-admin/django/core/formfields.py

    r748 r791  
    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_' 
     
    332333 
    333334    def isValidLength(self, data, form): 
    334         if data and self.maxlength and len(data) > self.maxlength: 
     335        if data and self.maxlength and len(data.decode(DEFAULT_CHARSET)) > self.maxlength: 
    335336            raise validators.ValidationError, "Ensure your text is less than %s characters." % self.maxlength 
    336337 
     
    346347            maxlength = 'maxlength="%s" ' % self.maxlength 
    347348        if isinstance(data, unicode): 
    348             data = data.encode('utf-8'
     349            data = data.encode(DEFAULT_CHARSET
    349350        return '<input type="text" id="%s" class="v%s%s" name="%s" size="%s" value="%s" %s/>' % \ 
    350351            (self.get_id(), self.__class__.__name__, self.is_required and ' required' or '', 
     
    375376            data = '' 
    376377        if isinstance(data, unicode): 
    377             data = data.encode('utf-8'
     378            data = data.encode(DEFAULT_CHARSET
    378379        return '<textarea id="%s" class="v%s%s" name="%s" rows="%s" cols="%s">%s</textarea>' % \ 
    379380            (self.get_id(), self.__class__.__name__, self.is_required and ' required' or '', 
  • django/branches/new-admin/django/core/handlers/modpython.py

    r518 r791  
    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/branches/new-admin/django/core/handlers/wsgi.py

    r636 r791  
    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/branches/new-admin/django/core/management.py

    r741 r791  
    1717# Use django.__path__[0] because we don't know which directory django into 
    1818# which has been installed. 
    19 PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf/%s_template') 
    20 ADMIN_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf/admin_templates') 
     19PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', '%s_template') 
     20ADMIN_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', 'admin_templates') 
    2121 
    2222def _get_packages_insert(app_label): 
     
    161161    app_label = mod._MODELS[0]._meta.app_label 
    162162    output.append(_get_packages_insert(app_label)) 
    163     app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '../sql')) 
     163    app_dir = os.path.normpath(os.path.join(os.path.dirname(mod.__file__), '..', 'sql')) 
    164164    for klass in mod._MODELS: 
    165165        opts = klass._meta 
     
    377377    # Populate TEMPLATE_DIRS for the admin templates, based on where Django is 
    378378    # installed. 
    379     admin_settings_file = os.path.join(directory, project_name, 'settings/admin.py') 
     379    admin_settings_file = os.path.join(directory, project_name, 'settings', 'admin.py') 
    380380    settings_contents = open(admin_settings_file, 'r').read() 
    381381    fp = open(admin_settings_file, 'w') 
     
    384384    fp.close() 
    385385    # Create a random SECRET_KEY hash, and put it in the main settings. 
    386     main_settings_file = os.path.join(directory, project_name, 'settings/main.py') 
     386    main_settings_file = os.path.join(directory, project_name, 'settings', 'main.py') 
    387387    settings_contents = open(main_settings_file, 'r').read() 
    388388    fp = open(main_settings_file, 'w') 
     
    398398    # Determine the project_name a bit naively -- by looking at the name of 
    399399    # the parent directory. 
    400     project_dir = os.path.normpath(os.path.join(directory, '../')) 
     400    project_dir = os.path.normpath(os.path.join(directory, '..')) 
    401401    project_name = os.path.basename(project_dir) 
    402402    _start_helper('app', app_name, directory, project_name) 
     
    550550                    e.add(opts, '"admin" attribute, if given, must be set to a meta.Admin() instance.') 
    551551                else: 
    552                     for fn in opts.admin.list_display: 
    553                         try: 
    554                             f = opts.get_field(fn) 
    555                         except meta.FieldDoesNotExist: 
    556                             klass = opts.get_model_module().Klass 
    557                             if not hasattr(klass, fn) or not callable(getattr(klass, fn)): 
    558                                 e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn) 
    559                         else: 
    560                             if isinstance(f, meta.ManyToManyField): 
    561                                 e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) 
     552                    # list_display 
     553                    if not isinstance(opts.admin.list_display, (list, tuple)): 
     554                        e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.') 
     555                    else: 
     556                        for fn in opts.admin.list_display: 
     557                            try: 
     558                                f = opts.get_field(fn) 
     559                            except meta.FieldDoesNotExist: 
     560                                klass = opts.get_model_module().Klass 
     561                                if not hasattr(klass, fn) or not callable(getattr(klass, fn)): 
     562                                    e.add(opts, '"admin.list_display" refers to %r, which isn\'t a field or method.' % fn) 
     563                            else: 
     564                                if isinstance(f, meta.ManyToManyField): 
     565                                    e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) 
     566                    # list_filter 
     567                    if not isinstance(opts.admin.list_filter, (list, tuple)): 
     568                        e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') 
     569                    else: 
     570                        for fn in opts.admin.list_filter: 
     571                            try: 
     572                                f = opts.get_field(fn) 
     573                            except meta.FieldDoesNotExist: 
     574                                e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 
    562575 
    563576            # Check ordering attribute. 
  • django/branches/new-admin/django/core/template.py

    r644 r791  
    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/branches/new-admin/django/middleware/cache.py

    r178 r791  
    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/branches/new-admin/django/middleware/common.py

    r613 r791  
    5555 
    5656    def process_response(self, request, response): 
    57         """ 
    58         Check for a flatfile (for 404s) and calculate the Etag, if needed. 
    59         """ 
     57        "Check for a flat page (for 404s) and calculate the Etag, if needed." 
     58        if response.status_code == 404: 
     59            if settings.USE_FLAT_PAGES: 
     60                try: 
     61                    return flat_file(request, request.path) 
     62                except exceptions.Http404: 
     63                    pass 
    6064 
    61         # If this was a 404, check for a flat file 
    62         if response.status_code == 404: 
    63             try: 
    64                 response = flat_file(request, request.path) 
    65             except exceptions.Http404: 
     65            if settings.SEND_BROKEN_LINK_EMAILS: 
    6666                # If the referrer was from an internal link or a non-search-engine site, 
    6767                # send a note to the managers. 
    68                 if settings.SEND_BROKEN_LINK_EMAILS: 
    69                     domain = request.META['HTTP_HOST'] 
    70                     referer = request.META.get('HTTP_REFERER', None) 
    71                     is_internal = referer and (domain in referer) 
    72                     path = request.get_full_path() 
    73                     if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer): 
    74                         mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain), 
    75                             "Referrer: %s\nRequested URL: %s\n" % (referer, request.get_full_path())) 
    76                 # If there's no flatfile we want to return the original 404 response 
     68                domain = request.META['HTTP_HOST'] 
     69                referer = request.META.get('HTTP_REFERER', None) 
     70                is_internal = referer and (domain in referer) 
     71                path = request.get_full_path() 
     72                if referer and not _is_ignorable_404(path) and (is_internal or '?' not in referer): 
     73                    mail_managers("Broken %slink on %s" % ((is_internal and 'INTERNAL ' or ''), domain), 
     74                        "Referrer: %s\nRequested URL: %s\n" % (referer, request.get_full_path())) 
    7775                return response 
    7876 
    79         # Use ETags, if requested 
     77        # Use ETags, if requested. 
    8078        if settings.USE_ETAGS: 
    81             etag = md5.new(response.get_content_as_string('utf-8')).hexdigest() 
     79            etag = md5.new(response.get_content_as_string(settings.DEFAULT_CHARSET)).hexdigest() 
    8280            if request.META.get('HTTP_IF_NONE_MATCH') == etag: 
    8381                response = httpwrappers.HttpResponseNotModified() 
  • django/branches/new-admin/django/utils/httpwrappers.py

    r711 r791  
    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/branches/new-admin/django/views/admin/main.py

    r783 r791  
    432432                    result_id = getattr(result, pk) 
    433433                    raw_template.append('<th%s><a href="%s/"%s>%s</a></th>' % \ 
    434                         (row_class, result_id, (is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %s); return false;"' % result_id or ''), result_repr)) 
     434                        (row_class, result_id, (is_popup and ' onclick="opener.dismissRelatedLookupPopup(window, %r); return false;"' % result_id or ''), result_repr)) 
    435435                else: 
    436436                    raw_template.append('<td%s>%s</td>' % (row_class, result_repr)) 
  • django/branches/new-admin/django/views/decorators/cache.py

    r175 r791  
    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) 
  • django/branches/new-admin/docs/db-api.txt

    r749 r791  
    573573    * ``"day"`` returns a list of all distinct year/month/day values for the field. 
    574574 
     575Additional, optional keyword arguments, in the format described in 
     576"Field lookups" above, are also accepted. 
     577 
    575578Here's an example, using the ``Poll`` model defined above:: 
    576579 
     
    588591    >>> polls.get_pub_date_list('day') 
    589592    [datetime.datetime(2005, 2, 20), datetime.datetime(2005, 3, 20)] 
     593    >>> polls.get_pub_date_list('day', question__contains='name') 
     594    [datetime.datetime(2005, 3, 20)] 
    590595 
    591596``get_FOO_list()`` also accepts an optional keyword argument ``order``, which