csv writer! you can add books now

This commit is contained in:
crunk 2021-04-05 21:42:43 +02:00
parent ab84fc8229
commit dc1e3ce99f
6 changed files with 142 additions and 23 deletions

View File

@ -6,6 +6,21 @@ import os
script_dir = os.path.dirname(__file__)
image_dir = os.path.abspath(os.path.join(script_dir, "../static/images"))
fieldnames = [
'Id',
'Publication',
'Author',
'Year',
'Custodian',
'Fields',
'Type',
'Publishers',
'License',
'LicenseShort',
'Highlights',
'Comments',
'Currently borrowed by',
]
def parsecsv():
@ -139,4 +154,38 @@ def getfullpublication(pubid):
return pubinfo
# print(getlicenses())
def generatenewpublicationid():
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r")
allidsincsv = []
with libcsv:
csv_as_dict = csv.DictReader(libcsv)
for row in csv_as_dict:
allidsincsv.append(int(row["Id"]))
return str(max(allidsincsv) + 1)
def writepublication(uploadform):
id = generatenewpublicationid()
with open(
os.path.join(script_dir, "varlib.csv"),
'a',
newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writerow(
{
"Id": id,
"Publication": uploadform.uploadpublication.data,
"Author": uploadform.author.data,
"Year": uploadform.year.data,
"Custodian": uploadform.custodian.data,
"Fields": uploadform.fields.data,
"Type": uploadform.type.data,
"Publishers": uploadform.publishers.data,
"License": uploadform.license.data,
"LicenseShort": uploadform.licenseshort.data,
"Highlights": uploadform.highlights.data,
"Comments": uploadform.comments.data,
"Currently borrowed by": uploadform.borrowed.data,
})
print("succesfully written book to csv")
return id

View File

@ -13,8 +13,6 @@ Id,Publication,Author,Year,Custodian,Fields,Type,Publishers,License,LicenseShort
12,Abolish restaurants,Prole.info,2010,Varia,"Labour, Food industry",Paperback,Pm Press,Copyright 2010,Copyright,Drawing on a range of anti-capitalist ideas as well as a heaping plate of personal experience,,
13,"Elk Woord Een Vonk: Verboden Teksten, verwerpelijke vervolging: de zaak Joke Kaviaar",Steungroep 13 September,2014,Varia (or Luke?),"Joke Kaviaar, Immigration, Activism, Forbidden Texts, Incarceration",Softcover,Self-published,Copyleft,Copyleft,,https://13-september.nl,
14,A NO BORDERS manifesto,Ill Will Editions,2015,Varia,Migrant justice,Zine,Self-published,No license mentioned,No license mentioned,,,
15,Short Circuit: Towards an Arnarchist to Gentrification,,,Varia,"Gentrification, Anarchism",Zine,Self-published,No license mentioned,No license mentioned,"Anarchists understandably feel an intrinsic and visceral opposition to gentrification
",,
16,Futur Musique,De fanfare voor vooruit strevende volksmuziek,2018,Varia,"Musical Instruments, DIY",Zine,Self-published,No license mentioned,No license mentioned,Copied instructions on building one's own musical instruments,,
17,Franchir le cap,Quentin Juhel,2019,Varia,Convivial computation,Zine,Self-publsihed,Creative commons CC-BY-SA,Creative commons,,,
18,Consensus: Decision Making,Seeds For Change UK,2010,Varia,"Decision making, Consensus",Zine,Self-published,No license mentioned,No license mentioned,Short guide ,,
@ -48,8 +46,9 @@ Id,Publication,Author,Year,Custodian,Fields,Type,Publishers,License,LicenseShort
54,Xavan et Jaluka - The Death of the Authors 1946,Peter Westenberg,2018,Varia,Public domain,Zine,Constant Verlag,Copyleft,Copyleft,,,
55,Spreekt U Sint-Gillis? Parlez-vous Saint-Gillois?,,,Varia,"Bruxelles, Language, Sint-Gillis",Softcover,Constant Verlag,Copyleft,Copyleft,,,
56,Mondothèque: a radiated book,"André Castro , Sînziana Păltineanu , Dennis Pohl , Dick Reckard , Natacha Roussel , Femke Snelting , Alexia de Visscher",2016,Varia,"Archive, Otlet, Library science, Mondaneum, Google, Mons",Softcover,Constant,Copyleft,Copyleft,,,
,"The Death of the Authors: 'James Joyce, Rabindranath Tagore & Their Return to Life in Four Seasons",A Constant Remix,2013,Varia,"James Joyce, Ulysses",Softcover,Constant,Public domain,Public domain,,'generated from Public domain sources,
57,"The Death of the Authors: 'James Joyce, Rabindranath Tagore & Their Return to Life in Four Seasons",A Constant Remix,2013,Varia,"James Joyce, Ulysses",Softcover,Constant,Public domain,Public domain,,'generated from Public domain sources,
58,Verbindingen/Jonctions 10 : Tracks in electr(on)ic fields,Constant,2009,Varia,"Art, activism, technological culture",Softcover,Constant,Copyleft,Copyleft,,,
59,Conversations,Constant,2014,Varia,"Software studies, Libre graphics",Softcover,Constant Verlag,Copyleft,Copyleft,,,
60,Networks of one's own #1: Etherbox,"Michael Murtaugh, An Mertens, Roel Roscam Abbing, Femke Snelting",2018,Varia,"Networks, Digital Infrastructures, DIY, DIWO, Executable publication, Experimental Publishing, wireless",Paperback,Constant Verlag,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,,

1 Id Publication Author Year Custodian Fields Type Publishers License LicenseShort Highlights Comments Currently borrowed by
13 12 Abolish restaurants Prole.info 2010 Varia Labour, Food industry Paperback Pm Press Copyright 2010 Copyright Drawing on a range of anti-capitalist ideas as well as a heaping plate of personal experience
14 13 Elk Woord Een Vonk: Verboden Teksten, verwerpelijke vervolging: de zaak Joke Kaviaar Steungroep 13 September 2014 Varia (or Luke?) Joke Kaviaar, Immigration, Activism, Forbidden Texts, Incarceration Softcover Self-published Copyleft Copyleft https://13-september.nl
15 14 A NO BORDERS manifesto Ill Will Editions 2015 Varia Migrant justice Zine Self-published No license mentioned No license mentioned
15 Short Circuit: Towards an Arnarchist to Gentrification Varia Gentrification, Anarchism Zine Self-published No license mentioned No license mentioned Anarchists understandably feel an intrinsic and visceral opposition to gentrification
16 Futur Musique De fanfare voor vooruit strevende volksmuziek 2018 Varia Musical Instruments, DIY Zine Self-published No license mentioned No license mentioned Copied instructions on building one's own musical instruments
16 17 16 Franchir le cap Futur Musique Quentin Juhel De fanfare voor vooruit strevende volksmuziek 2019 2018 Varia Convivial computation Musical Instruments, DIY Zine Self-publsihed Self-published Creative commons CC-BY-SA No license mentioned Creative commons No license mentioned Copied instructions on building one's own musical instruments
17 18 17 Consensus: Decision Making Franchir le cap Seeds For Change UK Quentin Juhel 2010 2019 Varia Decision making, Consensus Convivial computation Zine Self-published Self-publsihed No license mentioned Creative commons CC-BY-SA No license mentioned Creative commons Short guide
18 19 18 Waar ook op gestemd wordt, wij laten ons niet regeren Consensus: Decision Making Anarchistische Groep Nijmegen Seeds For Change UK 2014 2010 Varia Democracy Decision making, Consensus Zine Self-published No license mentioned No license mentioned Short guide
46 55 54 Spreekt U Sint-Gillis? Parlez-vous Saint-Gillois? Xavan et Jaluka - The Death of the Authors 1946 Peter Westenberg 2018 Varia Bruxelles, Language, Sint-Gillis Public domain Softcover Zine Constant Verlag Copyleft Copyleft
47 56 55 Mondothèque: a radiated book Spreekt U Sint-Gillis? Parlez-vous Saint-Gillois? André Castro , Sînziana Păltineanu , Dennis Pohl , Dick Reckard , Natacha Roussel , Femke Snelting , Alexia de Visscher 2016 Varia Archive, Otlet, Library science, Mondaneum, Google, Mons Bruxelles, Language, Sint-Gillis Softcover Constant Constant Verlag Copyleft Copyleft
48 56 The Death of the Authors: 'James Joyce, Rabindranath Tagore & Their Return to Life in Four Seasons Mondothèque: a radiated book A Constant Remix André Castro , Sînziana Păltineanu , Dennis Pohl , Dick Reckard , Natacha Roussel , Femke Snelting , Alexia de Visscher 2013 2016 Varia James Joyce, Ulysses Archive, Otlet, Library science, Mondaneum, Google, Mons Softcover Constant Public domain Copyleft Public domain Copyleft 'generated from Public domain sources
49 58 57 Verbindingen/Jonctions 10 : Tracks in electr(on)ic fields The Death of the Authors: 'James Joyce, Rabindranath Tagore & Their Return to Life in Four Seasons Constant A Constant Remix 2009 2013 Varia Art, activism, technological culture James Joyce, Ulysses Softcover Constant Copyleft Public domain Copyleft Public domain 'generated from Public domain sources
50 59 58 Conversations Verbindingen/Jonctions 10 : Tracks in electr(on)ic fields Constant 2014 2009 Varia Software studies, Libre graphics Art, activism, technological culture Softcover Constant Verlag Constant Copyleft Copyleft
51 60 59 Networks of one's own #1: Etherbox Conversations Michael Murtaugh, An Mertens, Roel Roscam Abbing, Femke Snelting Constant 2018 2014 Varia Networks, Digital Infrastructures, DIY, DIWO, Executable publication, Experimental Publishing, wireless Software studies, Libre graphics Paperback Softcover Constant Verlag Copyleft Copyleft
52 61 60 Mots de la cage aux ours - woorden uit de berenkuil Networks of one's own #1: Etherbox Constant Michael Murtaugh, An Mertens, Roel Roscam Abbing, Femke Snelting 2012 2018 Varia words, language, Bruxelles Networks, Digital Infrastructures, DIY, DIWO, Executable publication, Experimental Publishing, wireless Softcover Paperback Constant Constant Verlag Copyleft Copyleft
53 61 Mots de la cage aux ours - woorden uit de berenkuil Constant 2012 Varia words, language, Bruxelles Softcover Constant Copyleft Copyleft
54 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

View File

@ -5,7 +5,11 @@ import flask
from requests import get
from icalendar import Calendar
import datetime
from flask import render_template
from flask import (
render_template,
redirect,
request,
)
from rnrfeed.rnrfeeder import getevents, getlatestevent
from uploadform import PublicationForm
from csvparser.csvparser import (
@ -14,6 +18,7 @@ from csvparser.csvparser import (
gettypes,
getyears,
getfullpublication,
writepublication,
)
from flask_wtf.csrf import CSRFProtect
@ -41,9 +46,16 @@ def index():
return template
@APP.route("/upload")
@APP.route("/upload", methods=["GET", "POST"])
def upload():
uploadform = PublicationForm()
if request.method == 'POST':
if uploadform.validate_on_submit():
id = writepublication(uploadform)
return redirect(str(id), code=303)
else:
return render_template("upload.html", uploadform=uploadform)
print("test")
return render_template("upload.html", uploadform=uploadform)

View File

@ -135,3 +135,7 @@ td {
width: 100%;
height: 100%;
}
.error{
color: #ff1111;
}

View File

@ -5,27 +5,45 @@
<button><a href="/upload">Upload</a></button>
</div>
<div id="uploadform">
{% for message in uploadform.uploadpublication.errors %}
<div>{{ message }}</div>
{% endfor %}
{% for message in uploadform.author.errors %}
<div>{{ message }}</div>
{% endfor %}
<h2 id="uploadformtitle">Upload a new book</h2>
<form method="POST" action="{{ url_for('upload') }}">
{{ uploadform.csrf_token }}
<fieldset class="uploadform-field">
{{ uploadform.uploadpublication.label }}
{{ uploadform.uploadpublication(size=20) }}
{{ uploadform.uploadpublication }}
{% for message in uploadform.uploadpublication.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.author.label }}
{{ uploadform.author }}
{% for message in uploadform.author.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.year.label }}
{{ uploadform.year }}
{% for message in uploadform.year.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.custodian.label }}
{{ uploadform.custodian(size=20) }}
{{ uploadform.custodian }}
</fieldset>
<fieldset class="uploadform-field">
@ -36,11 +54,14 @@
<fieldset class="uploadform-field">
{{ uploadform.type.label }}
{{ uploadform.type }}
{% for message in uploadform.type.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="uploadform-field">
{{ uploadform.publishers.label }}
{{ uploadform.publishers(size=20) }}
{{ uploadform.publishers }}
</fieldset>
<fieldset class="uploadform-field">
@ -55,7 +76,7 @@
<fieldset class="uploadform-field">
{{ uploadform.highlights.label }}
{{ uploadform.highlights(size=20) }}
{{ uploadform.highlights }}
</fieldset>
<fieldset class="uploadform-field">
@ -72,5 +93,4 @@
</form>
</div>
<script src="{{ url_for('static', filename='js/dropdown.js')}}"></script>
{% endblock %}

View File

@ -7,22 +7,57 @@ from wtforms import (
RadioField,
SubmitField,
)
from wtforms.validators import DataRequired, Length
from wtforms import validators
from wtforms.validators import (
Length,
NumberRange,
)
class PublicationForm(FlaskForm):
"""Contact form."""
"""Publication upload form."""
uploadpublication = StringField(
"Title of the publication:", [DataRequired()]
"Title of the publication:",
[
validators.InputRequired(),
Length(
min=3, message="A publication in the library needs a title."
),
],
)
author = StringField("The author or editor:", [DataRequired()])
year = IntegerField("Year:", [DataRequired()])
custodian = StringField("Custodian:", [DataRequired()])
fields = StringField("Fields:", [DataRequired()])
type = StringField("Type:", [DataRequired()])
publishers = StringField("Publishers:", [DataRequired()])
license = StringField("License:", [DataRequired()])
author = StringField(
"The author or editor:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"If the author or editor is not known just type unkown."
),
),
],
)
year = IntegerField(
"Year:", [validators.InputRequired(), NumberRange(min=0, max=2050)]
)
custodian = StringField("Custodian:")
fields = StringField("Fields:")
type = StringField(
"Type of publication:",
[
validators.InputRequired(),
Length(
min=3,
message=(
"Here you can use terms such as zine, paperback,"
" hardcover."
),
),
],
)
publishers = StringField("Publishers:")
license = StringField("License:")
licenseshort = RadioField(
"Select the closest license type:",
choices=[