Browse Source

added photo upload functionality but this is a work in progress

master
crunk 4 years ago
parent
commit
a4986a2e84
  1. 6
      library/csvparser/csvparser.py
  2. 1
      library/csvparser/varlib.csv
  3. 11
      library/page.py
  4. 12
      library/static/css/upload.css
  5. BIN
      library/static/images/image-64.jpg
  6. 12
      library/templates/upload.html
  7. 7
      library/uploadform.py

6
library/csvparser/csvparser.py

@ -54,8 +54,10 @@ def getpublications():
def hasimage(id): def hasimage(id):
image_file = os.path.join(image_dir, "image-{0}.jpg".format(id)) image_jpg = os.path.join(image_dir, "image-{0}.jpg".format(id))
if os.path.exists(image_file): 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 return True
else: else:
return False return False

1
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,,, 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,, 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 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.,

Can't render this file because it has a wrong number of fields in line 10.

11
library/page.py

@ -1,6 +1,7 @@
"""This is the main flask library page""" """This is the main flask library page"""
import os
import flask import flask
from requests import get from requests import get
from icalendar import Calendar from icalendar import Calendar
@ -11,6 +12,8 @@ from flask import (
redirect, redirect,
request, request,
) )
from flask_wtf.csrf import CSRFProtect
from werkzeug.utils import secure_filename
from rnrfeed.rnrfeeder import getevents, getlatestevent from rnrfeed.rnrfeeder import getevents, getlatestevent
from uploadform import PublicationForm from uploadform import PublicationForm
from borrowform import BorrowForm from borrowform import BorrowForm
@ -23,7 +26,7 @@ from csvparser.csvparser import (
writepublication, writepublication,
editborrowedby, editborrowedby,
) )
from flask_wtf.csrf import CSRFProtect
csrf = CSRFProtect() csrf = CSRFProtect()
@ -56,6 +59,7 @@ def upload():
if (uploadform.validate_on_submit() and if (uploadform.validate_on_submit() and
checksecret(uploadform.secret.data)): checksecret(uploadform.secret.data)):
id = writepublication(uploadform) id = writepublication(uploadform)
saveimage(uploadform.image.data, id)
return redirect(str(id), code=303) return redirect(str(id), code=303)
else: else:
return render_template("upload.html", uploadform=uploadform) return render_template("upload.html", uploadform=uploadform)
@ -120,6 +124,11 @@ def upcoming_or_latest():
return dict(upcoming=upcoming) 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): def checksecret(secret):
with open("secret") as f: with open("secret") as f:

12
library/static/css/upload.css

@ -28,6 +28,18 @@ input[type=text], select {
box-sizing: border-box; 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] { input[type=submit] {
background-color: #DD4F77; background-color: #DD4F77;
text-align: right; text-align: right;

BIN
library/static/images/image-64.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

12
library/templates/upload.html

@ -15,7 +15,7 @@
{% endfor %} {% endfor %}
<h2 id="uploadformtitle">Upload a new book</h2> <h2 id="uploadformtitle">Upload a new book</h2>
<form method="POST" action="{{ url_for('upload') }}"> <form method="POST" enctype="multipart/form-data" action="{{ url_for('upload') }}">
{{ uploadform.csrf_token }} {{ uploadform.csrf_token }}
<fieldset class="uploadform-field"> <fieldset class="uploadform-field">
{{ uploadform.uploadpublication.label }} {{ uploadform.uploadpublication.label }}
@ -89,7 +89,15 @@
{{ uploadform.borrowed }} {{ uploadform.borrowed }}
</fieldset> </fieldset>
<fieldset class="borrowform-field"> <fieldset class="fileupload-field">
{{ uploadform.image.label }}
{{ uploadform.image }}
{% for message in uploadform.image.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.secret.label }} {{ uploadform.secret.label }}
{{ uploadform.secret }} {{ uploadform.secret }}
{% for message in uploadform.secret.errors %} {% for message in uploadform.secret.errors %}

7
library/uploadform.py

@ -1,5 +1,8 @@
"""Form object declaration.""" """Form object declaration."""
from flask_wtf import FlaskForm 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 ( from wtforms import (
StringField, StringField,
IntegerField, IntegerField,
@ -7,7 +10,6 @@ from wtforms import (
RadioField, RadioField,
SubmitField, SubmitField,
) )
from wtforms import validators
from wtforms.validators import ( from wtforms.validators import (
Length, Length,
NumberRange, NumberRange,
@ -77,6 +79,9 @@ class PublicationForm(FlaskForm):
highlights = TextField("Highlights from the publication:") highlights = TextField("Highlights from the publication:")
comments = TextField("Comments on the publication:") comments = TextField("Comments on the publication:")
borrowed = StringField("Currently borrowed by:") borrowed = StringField("Currently borrowed by:")
image = FileField('Image of the book:', validators=[
FileAllowed(['jpg', 'png', 'gif'], 'Images only!')
])
secret = StringField( secret = StringField(
"Librarians secret:", "Librarians secret:",
[ [

Loading…
Cancel
Save