added year filter and cleaned the code some more
This commit is contained in:
parent
230f242af5
commit
d0dac94911
@ -1,3 +1,6 @@
|
||||
"""This parses the varlib.csv but only in a way
|
||||
that is actually useful for the site"""
|
||||
|
||||
import csv
|
||||
import os
|
||||
|
||||
@ -17,10 +20,14 @@ def getpublications():
|
||||
csv_as_dict = csv.DictReader(libcsv)
|
||||
publications = {}
|
||||
for row in csv_as_dict:
|
||||
year = row["Year"]
|
||||
if not year:
|
||||
year = "Unknown"
|
||||
pubinfo = {
|
||||
"Title": row["Publication"],
|
||||
"Author": row["Author"],
|
||||
"Type": row["Type"],
|
||||
"Year": year,
|
||||
}
|
||||
publications[row["Id"]] = pubinfo
|
||||
return publications
|
||||
@ -44,8 +51,12 @@ def getyears():
|
||||
csv_as_dict = csv.DictReader(libcsv)
|
||||
listofyears = []
|
||||
for row in csv_as_dict:
|
||||
if row["Year"] not in listofyears:
|
||||
listofyears.append(row["Year"])
|
||||
uniqueyear = row["Year"]
|
||||
if not uniqueyear:
|
||||
uniqueyear = "Unknown"
|
||||
if uniqueyear not in listofyears:
|
||||
listofyears.append(uniqueyear)
|
||||
listofyears.sort()
|
||||
return listofyears
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""This is the main flask page code"""
|
||||
"""This is the main flask library page"""
|
||||
|
||||
|
||||
import flask
|
||||
@ -11,8 +11,7 @@ APP = flask.Flask(__name__, static_folder="static")
|
||||
|
||||
@APP.route("/")
|
||||
def index():
|
||||
"""Main route"""
|
||||
# parse csv, render template with a few elements from the csv
|
||||
"""Main route, shows all the books and you can filter them, a bit"""
|
||||
pubtypes = gettypes()
|
||||
pubyears = getyears()
|
||||
publicatons = getpublications()
|
||||
@ -27,15 +26,14 @@ def index():
|
||||
|
||||
@APP.route("/<publicationID>")
|
||||
def show_book(publicationID):
|
||||
"""route for a publication"""
|
||||
"""route for a publication, still needs to be made"""
|
||||
# parse csv, render template with full list.
|
||||
return render_template("publication.html")
|
||||
|
||||
|
||||
@APP.route("/<publication>")
|
||||
def upload_book(publication):
|
||||
"""upload a new book"""
|
||||
#
|
||||
"""upload a new book, still needs to be made"""
|
||||
return render_template("upload.html")
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<div id="main">
|
||||
<ul>
|
||||
{% for id, pubinfo in publications.items() %}
|
||||
<li class='filter {{ pubinfo["Type"] }}'><a href='{{ id }}'>{{ pubinfo["Author"] }} - {{ pubinfo["Title"] }}</a></li>
|
||||
<li class='filter {{ pubinfo["Type"] }} {{ pubinfo["Year"] }}'><a href='{{ id }}'>{{ pubinfo["Author"] }} - {{ pubinfo["Title"] }}</a></li>
|
||||
{% endfor%}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -5,7 +5,15 @@
|
||||
<button class="dropbtn">Type</button>
|
||||
<div class="dropdown-content">
|
||||
{% for pubtype in pubtypes %}
|
||||
<button type="button" name="button" onclick="filterSelection('{{ pubtype.title() }}')" >{{ pubtype }}</button>
|
||||
<button type="button" name="button" onclick="filterSelection('{{ pubtype }}')" >{{ pubtype.title() }}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="dropdown">
|
||||
<button class="dropbtn">Year</button>
|
||||
<div class="dropdown-content">
|
||||
{% for pubyear in pubyears %}
|
||||
<button type="button" name="button" onclick="filterSelection('{{ pubyear }}')" >{{ pubyear }}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user