Browse Source

template for pdf and image upload

main
crunk 3 weeks ago
parent
commit
b6c001b8eb
  1. 15
      library/page.py
  2. 1
      library/static/css/style.css
  3. 34
      library/templates/publication.html

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

1
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;

34
library/templates/publication.html

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

Loading…
Cancel
Save