Ticket #6485: 0010-Split-off-file-serving-capability.patch

File 0010-Split-off-file-serving-capability.patch, 1.5 KB (added by Bastian Kleineidam <calvin@…>, 17 years ago)
  • django/views/static.py

    From c2de944401886d1474973ac3bb035f9e1fc22335 Mon Sep 17 00:00:00 2001
    From: Bastian Kleineidam <calvin@debian.org>
    Date: Fri, 25 Jan 2008 17:42:37 +0100
    Subject: Split off file-serving capability
    
    Split the file-serving capability of the Django static view into a
    separate function, and add the ability to set the mimetype manually.
    
    Signed-off-by: Bastian Kleineidam <calvin@debian.org>
    
    diff --git a/django/views/static.py b/django/views/static.py
    index 80c9bff..79b6192 100644
    a b def serve(request, path, document_root=None, show_indexes=False):  
    6363        if show_indexes:
    6464            return directory_index(newpath, fullpath)
    6565        raise Http404, "Directory indexes are not allowed here."
     66    return serve_file(request, fullpath)
     67
     68def serve_file (request, fullpath, mimetype=None):
    6669    if not os.path.exists(fullpath):
    6770        raise Http404, '"%s" does not exist' % fullpath
    6871    # Respect the If-Modified-Since header.
    def serve(request, path, document_root=None, show_indexes=False):  
    7073    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
    7174                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
    7275        return HttpResponseNotModified()
    73     mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream'
     76    if mimetype is None:
     77        mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream'
    7478    f = open(fullpath, 'rb')
    7579    try:
    7680        contents = f.read()
Back to Top