mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Refactored for better packaging
This commit is contained in:
32
src/interface/views.py
Executable file
32
src/interface/views.py
Executable file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
from django.shortcuts import HttpResponse, render
|
||||
from django.utils.text import slugify
|
||||
|
||||
from .models import Books
|
||||
|
||||
|
||||
def index(request):
|
||||
return render(request, "index.html", {"Books": Books.objects.all()})
|
||||
|
||||
|
||||
def download(request, pk):
|
||||
_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):
|
||||
r = 20
|
||||
x = _set * r
|
||||
y = x + r
|
||||
books = Books.objects.all()[x:y]
|
||||
return books
|
||||
Reference in New Issue
Block a user