From b6c001b8eb05e738d980ee72494a08ff478f1574 Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 31 Mar 2024 12:25:53 +0200 Subject: [PATCH] template for pdf and image upload --- library/page.py | 15 +++++++------ library/static/css/style.css | 1 + library/templates/publication.html | 34 ++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/library/page.py b/library/page.py index e47a961..57b2398 100644 --- a/library/page.py +++ b/library/page.py @@ -26,6 +26,8 @@ from app import create_app, login_manager from application.search import search from application.csvparser import CsvParser from application.forms.borrowform import BorrowForm +from application.forms.image_uploadform import ImageUploadForm +from application.forms.pdf_uploadform import PdfUploadForm from application.forms.publicationform import PublicationForm from application.models.usermodel import User from application.user.forgotpassword import ForgotPassword @@ -88,22 +90,23 @@ def show_book(publicationID): """route for a single publication, shows full info and allows borrowing""" fullpublication = csvparser.getfullpublication(publicationID) borrowform = BorrowForm() + image_uploadform = ImageUploadForm() + pdf_uploadform = PdfUploadForm() if request.method == "POST": if borrowform.validate_on_submit(): editborrowedby(publicationID, borrowform.borrowed.data) fullpublication["Borrowed"] = borrowform.borrowed.data - return render_template( - "publication.html", - fullpublication=fullpublication, - publicationID=publicationID, - borrowform=borrowform, - ) + if image_uploadform.validate_on_submit(): + saveimage(image_uploadform.image.data, fullpublication.id) + # return a full publication with or without form errors return render_template( "publication.html", fullpublication=fullpublication, publicationID=publicationID, borrowform=borrowform, + image_uploadform=image_uploadform, + pdf_uploadform=pdf_uploadform, ) diff --git a/library/static/css/style.css b/library/static/css/style.css index dac02ba..e6ddc0d 100644 --- a/library/static/css/style.css +++ b/library/static/css/style.css @@ -27,6 +27,7 @@ html, body { #bookshelf { max-width: 90%; margin-top: 3em; + margin-bottom: 3em; margin-left: 1em; display: block; columns: 30rem; diff --git a/library/templates/publication.html b/library/templates/publication.html index 65775c8..073f5b9 100644 --- a/library/templates/publication.html +++ b/library/templates/publication.html @@ -64,6 +64,40 @@ File

{{ fullpublication["Files"] }}

+ {% if current_user.is_authenticated %} + + Upload new + +
+ {{ pdf_uploadform.csrf_token }} +
+ {{ pdf_uploadform.pdf.label }} + {{ pdf_uploadform.pdf }} + {% for message in pdf_uploadform.pdf.errors %} +
{{ message }}
+ {% endfor %} +
+ {{ pdf_uploadform.submit }} +
+ + + + Upload new + +
+ {{ image_uploadform.csrf_token }} +
+ {{ image_uploadform.image.label }} + {{ image_uploadform.image }} + {% for message in image_uploadform.image.errors %} +
{{ message }}
+ {% endfor %} +
+ {{ image_uploadform.submit }} +
+ + + {% endif %}