diff --git a/library/csvparser/csvparser.py b/library/csvparser/csvparser.py index 4f6d81b..db93946 100644 --- a/library/csvparser/csvparser.py +++ b/library/csvparser/csvparser.py @@ -54,8 +54,10 @@ def getpublications(): def hasimage(id): - image_file = os.path.join(image_dir, "image-{0}.jpg".format(id)) - if os.path.exists(image_file): + image_jpg = os.path.join(image_dir, "image-{0}.jpg".format(id)) + image_png = os.path.join(image_dir, "image-{0}.png".format(id)) + image_gif = os.path.join(image_dir, "image-{0}.gif".format(id)) + if os.path.exists(image_jpg): return True else: return False diff --git a/library/csvparser/varlib.csv b/library/csvparser/varlib.csv index fee5f51..b140e3c 100644 --- a/library/csvparser/varlib.csv +++ b/library/csvparser/varlib.csv @@ -53,3 +53,4 @@ Id,Publication,Author,Year,Custodian,Fields,Type,Publishers,License,LicenseShort 61,Mots de la cage aux ours - woorden uit de berenkuil,Constant,2012,Varia,"words, language, Bruxelles",Softcover,Constant,Copyleft,Copyleft,,, 62,Snake rituals and switching circuits,Florian Cramer,2009,Danny,"mass communication, personal communication, new media",paperback,Piet Zwart Institute,Creative Commons Attribution-Share Alike 3.0,Creative Commons,The function of a medium is ultimately decided by its users and not by its creators,, 63,Magium issue 1: On Eating in isolation,Alice Strete,2020,Varia,"food, sharing, personal stories, consumption",zine,Self Published,Free Art License,Free Art License,,,No one +64,Networks of One's Own: three takes on taking care,"Varia, Constant and Colm O’Neill",2019,Varia,"Software, internet, taking care, homebrew",paperback,Varia,Copyleft,Copyleft,,Networks Of One’s Own is a periodic para-nodal1 publication that is itself collectively within a network2., diff --git a/library/page.py b/library/page.py index 09c5468..ff7220d 100644 --- a/library/page.py +++ b/library/page.py @@ -1,6 +1,7 @@ """This is the main flask library page""" +import os import flask from requests import get from icalendar import Calendar @@ -11,6 +12,8 @@ from flask import ( redirect, request, ) +from flask_wtf.csrf import CSRFProtect +from werkzeug.utils import secure_filename from rnrfeed.rnrfeeder import getevents, getlatestevent from uploadform import PublicationForm from borrowform import BorrowForm @@ -23,7 +26,7 @@ from csvparser.csvparser import ( writepublication, editborrowedby, ) -from flask_wtf.csrf import CSRFProtect + csrf = CSRFProtect() @@ -56,6 +59,7 @@ def upload(): if (uploadform.validate_on_submit() and checksecret(uploadform.secret.data)): id = writepublication(uploadform) + saveimage(uploadform.image.data, id) return redirect(str(id), code=303) else: return render_template("upload.html", uploadform=uploadform) @@ -120,6 +124,11 @@ def upcoming_or_latest(): return dict(upcoming=upcoming) +def saveimage(image, id): + print(image.filename) + filename = secure_filename("image-{0}.jpg".format(id)) + image.save(os.path.join("static/images/", filename)) + def checksecret(secret): with open("secret") as f: diff --git a/library/static/css/upload.css b/library/static/css/upload.css index 1e271c9..4a1af5d 100644 --- a/library/static/css/upload.css +++ b/library/static/css/upload.css @@ -28,6 +28,18 @@ input[type=text], select { box-sizing: border-box; } +input[type="file"] { + width: 100%; + background-color: #F1F1F1; + z-index: -1; + border: none; + margin: 1em 0; + font-size: 17px; + color: black; + cursor: pointer; +} + + input[type=submit] { background-color: #DD4F77; text-align: right; diff --git a/library/static/images/image-64.jpg b/library/static/images/image-64.jpg new file mode 100644 index 0000000..eb52401 Binary files /dev/null and b/library/static/images/image-64.jpg differ diff --git a/library/templates/upload.html b/library/templates/upload.html index 4a040f9..83c4bfd 100644 --- a/library/templates/upload.html +++ b/library/templates/upload.html @@ -15,7 +15,7 @@ {% endfor %}

Upload a new book

-
+ {{ uploadform.csrf_token }}
{{ uploadform.uploadpublication.label }} @@ -89,7 +89,15 @@ {{ uploadform.borrowed }}
-
+
+ {{ uploadform.image.label }} + {{ uploadform.image }} + {% for message in uploadform.image.errors %} +
{{ message }}
+ {% endfor %} +
+ +
{{ uploadform.secret.label }} {{ uploadform.secret }} {% for message in uploadform.secret.errors %} diff --git a/library/uploadform.py b/library/uploadform.py index 9397318..d1b7686 100644 --- a/library/uploadform.py +++ b/library/uploadform.py @@ -1,5 +1,8 @@ """Form object declaration.""" from flask_wtf import FlaskForm +from flask_wtf.file import FileField, FileAllowed +from werkzeug.utils import secure_filename +from wtforms import validators from wtforms import ( StringField, IntegerField, @@ -7,7 +10,6 @@ from wtforms import ( RadioField, SubmitField, ) -from wtforms import validators from wtforms.validators import ( Length, NumberRange, @@ -77,6 +79,9 @@ class PublicationForm(FlaskForm): highlights = TextField("Highlights from the publication:") comments = TextField("Comments on the publication:") borrowed = StringField("Currently borrowed by:") + image = FileField('Image of the book:', validators=[ + FileAllowed(['jpg', 'png', 'gif'], 'Images only!') + ]) secret = StringField( "Librarians secret:", [