From 80a72c686a6586706d3cf4c0c23dda947b36ccc8 Mon Sep 17 00:00:00 2001 From: Mike Young Date: Tue, 19 Nov 2019 16:31:47 -0500 Subject: [PATCH] Finalized initial download system --- README.md | 10 ++++++++-- frontend/interface/views.py | 19 +++++++++++++++---- pyproject.toml | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a2bc6e6..45df06a 100755 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ All pyShelf configuration is done in config.py. ### Nginx configuration I have included a default nginx config file pyshelf_nginx.conf. This file should be sufficient to get you up and running. You are required to change the location alias's to reflect your pyshelf install folder leaving everything after /frontend intact. -Further resources for nginx setup may be found @ [nginx, django, & uwsgi](https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html) +Further resources for nginx setup may be found @ [This nginx, django, & uwsgi, guide](https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html) ### uwsgi configuration Inside uwsgi.ini you should make changes to reflect your install directory, and the port you wish uwsgi to listen on. Alternativly you can make the requisite changes to listen on a socket instead. This change would also require a change to the pyshelf_nginx.conf file as well. @@ -39,7 +39,13 @@ User configuration is contained within config.json in the project root. The only ## Current Features Currently pyShelf will recursively scan your collection, extract and store some metadata in the sqlite database. -Django has been implemented to power the frontend experience, and web based database maintenance. The first steps of which are included in this commit. Also the book database has been switched over to reflect this. A properly configured web server is required for hosting the frontend, configuration of which is outside of the scope of this readme. Running via the Django test server might be possible, however due to how file downloads are being handled some changes to the program itself would be required as the current itteration relies on Xsendfile. +Django has been implemented to power the frontend experience, and web based database maintenance. The first steps of which are included in this commit. Also the book database has been switched over to reflect this. A properly configured web server is required for hosting the frontend, configuration of which is outside of the scope of this readme. Running via the Django test server might be possible, albeit not recomended. + +## In Progress + +* UI/UX tweaks, including making the book display responsive. and not so ugly. +* Searching, & further organizational tools. +* Improved cover image storage, and acquisition. ## Future Goals * HTML Frontend for file transfers diff --git a/frontend/interface/views.py b/frontend/interface/views.py index cfbec8d..edefe86 100755 --- a/frontend/interface/views.py +++ b/frontend/interface/views.py @@ -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): diff --git a/pyproject.toml b/pyproject.toml index cbefe56..050adcf 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,4 @@ use_parentheses = true # NOTE: the known_third_party setting is managed by # seed-isort-config and should not be modified directly. # Any changes made to this setting will be overwritten. -known_third_party = ["PIL", "bs4", "django", "interface", "lib", "requests", "xsendfile"] +known_third_party = ["PIL", "bs4", "django", "interface", "lib", "requests"]