template for pdf and image upload

This commit is contained in:
crunk 2024-03-31 12:25:53 +02:00
parent e521349ad5
commit b6c001b8eb
3 changed files with 44 additions and 6 deletions

View File

@ -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,
)

View File

@ -27,6 +27,7 @@ html, body {
#bookshelf {
max-width: 90%;
margin-top: 3em;
margin-bottom: 3em;
margin-left: 1em;
display: block;
columns: 30rem;

View File

@ -64,6 +64,40 @@
<td>File</td>
<td><a href='files/{{fullpublication["Files"]}}'><p>{{ fullpublication["Files"] }}</p></a></td>
</tr>
{% if current_user.is_authenticated %}
<tr>
<td>Upload new</td>
<td>
<form method="POST" enctype="multipart/form-data" action="/{{ publicationID }}">
{{ pdf_uploadform.csrf_token }}
<fieldset class="fileupload-field">
{{ pdf_uploadform.pdf.label }}
{{ pdf_uploadform.pdf }}
{% for message in pdf_uploadform.pdf.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
{{ pdf_uploadform.submit }}
</form>
</td>
</tr>
<tr>
<td>Upload new</td>
<td>
<form method="POST" enctype="multipart/form-data" action="/{{ publicationID }}">
{{ image_uploadform.csrf_token }}
<fieldset class="fileupload-field">
{{ image_uploadform.image.label }}
{{ image_uploadform.image }}
{% for message in image_uploadform.image.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
{{ image_uploadform.submit }}
</form>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>