Commit 5ff6fac9 by benjaoming

Fix #160 by allowing django-sendfile to be plugged in through settings.USE_SENDFILE

parent 04186424
from testproject.settings import *
from testproject.settings.local import *
#Django Haystack
INSTALLED_APPS += ['sendfile']
WIKI_ATTACHMENTS_USE_SENDFILE = True
SENDFILE_BACKEND = 'sendfile.backends.development'
#SENDFILE_URL = '/protected'
# Whoosh backend is completely broken
# https://github.com/toastdriven/django-haystack/issues/522
# https://github.com/toastdriven/django-haystack/issues/382
# https://github.com/toastdriven/django-haystack/issues/447
#HAYSTACK_CONNECTIONS = {
# 'default': {
# 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
# 'PATH': os.path.join(PROJECT_PATH, 'whoosh_index'),
# },
#}
......@@ -158,6 +158,8 @@ REVISIONS_MINUTES_LOOKBACK = getattr( django_settings, 'WIKI_REVISIONS_MINUTES_L
from django.core.files.storage import default_storage
STORAGE_BACKEND = getattr(django_settings, 'WIKI_STORAGE_BACKEND', default_storage)
USE_SENDFILE = getattr(django_settings, 'WIKI_ATTACHMENTS_USE_SENDFILE', False)
####################
# PLANNED SETTINGS #
####################
......
......@@ -6,6 +6,13 @@ from django.http import HttpResponse
from django.utils.http import http_date
from django.utils import dateformat
from wiki.conf import settings
def django_sendfile_response(request, filepath):
from sendfile import sendfile
return sendfile(request, filepath)
def send_file(request, filepath, last_modified=None, filename=None):
fullpath = filepath
# Respect the If-Modified-Since header.
......@@ -16,7 +23,11 @@ def send_file(request, filepath, last_modified=None, filename=None):
mimetype, encoding = mimetypes.guess_type(fullpath)
mimetype = mimetype or 'application/octet-stream'
response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
if settings.USE_SENDFILE:
response = django_sendfile_response(request, filepath)
else:
response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
if not last_modified:
response["Last-Modified"] = http_date(statobj.st_mtime)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment