Finalized initial download system

This commit is contained in:
Mike Young
2019-11-19 16:31:47 -05:00
parent 59b4ddb0ef
commit 80a72c686a
3 changed files with 24 additions and 7 deletions

View File

@@ -1,5 +1,7 @@
import xsendfile
from django.shortcuts import render
import os
from django.shortcuts import HttpResponse, render
from django.utils.text import slugify
from .models import Books
@@ -9,8 +11,17 @@ def index(request):
def download(request, pk):
_fp = Books.objects.all().filter(pk=pk)[0].file_name
return xsendfile.XSendfile('"' + _fp + '"')
_book = Books.objects.all().filter(pk=pk)[0]
_fn = hr_name(_book)
response = HttpResponse(
open(os.path.abspath(_book.file_name), "rb"), content_type="application/zip"
)
response["Content-Disposition"] = "attachment; filename=%s" % _fn
return response
def hr_name(book):
return "{0}.{1}".format(slugify(book.title), book.file_name.split(".")[1])
def book_set(_set):