Django

Code

Changeset 782

Show
Ignore:
Timestamp:
10/05/05 18:36:17 (3 years ago)
Author:
adrian
Message:

Added USE_FLAT_PAGES setting, which defaults to True.

Files:

Legend:

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

    r774 r782  
    101101ADMIN_FOR = [] 
    102102 
     103# Whether to check the flat-pages table as a last resort for all 404 errors. 
     104USE_FLAT_PAGES = True 
     105 
    103106# 404s that may be ignored. 
    104107IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf') 
  • django/trunk/django/middleware/common.py

    r613 r782  
    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: 
    8179            etag = md5.new(response.get_content_as_string('utf-8')).hexdigest()