mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Finalized initial download system
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user