Browse Source

added year filter and cleaned the code some more

master
crunk 3 years ago
parent
commit
d0dac94911
  1. 15
      library/csvparser/csvparser.py
  2. 10
      library/page.py
  3. 2
      library/templates/index.html
  4. 10
      library/templates/menu.html

15
library/csvparser/csvparser.py

@ -1,3 +1,6 @@
"""This parses the varlib.csv but only in a way
that is actually useful for the site"""
import csv import csv
import os import os
@ -17,10 +20,14 @@ def getpublications():
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
publications = {} publications = {}
for row in csv_as_dict: for row in csv_as_dict:
year = row["Year"]
if not year:
year = "Unknown"
pubinfo = { pubinfo = {
"Title": row["Publication"], "Title": row["Publication"],
"Author": row["Author"], "Author": row["Author"],
"Type": row["Type"], "Type": row["Type"],
"Year": year,
} }
publications[row["Id"]] = pubinfo publications[row["Id"]] = pubinfo
return publications return publications
@ -44,8 +51,12 @@ def getyears():
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
listofyears = [] listofyears = []
for row in csv_as_dict: for row in csv_as_dict:
if row["Year"] not in listofyears: uniqueyear = row["Year"]
listofyears.append(row["Year"]) if not uniqueyear:
uniqueyear = "Unknown"
if uniqueyear not in listofyears:
listofyears.append(uniqueyear)
listofyears.sort()
return listofyears return listofyears

10
library/page.py

@ -1,4 +1,4 @@
"""This is the main flask page code""" """This is the main flask library page"""
import flask import flask
@ -11,8 +11,7 @@ APP = flask.Flask(__name__, static_folder="static")
@APP.route("/") @APP.route("/")
def index(): def index():
"""Main route""" """Main route, shows all the books and you can filter them, a bit"""
# parse csv, render template with a few elements from the csv
pubtypes = gettypes() pubtypes = gettypes()
pubyears = getyears() pubyears = getyears()
publicatons = getpublications() publicatons = getpublications()
@ -27,15 +26,14 @@ def index():
@APP.route("/<publicationID>") @APP.route("/<publicationID>")
def show_book(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. # parse csv, render template with full list.
return render_template("publication.html") return render_template("publication.html")
@APP.route("/<publication>") @APP.route("/<publication>")
def upload_book(publication): def upload_book(publication):
"""upload a new book""" """upload a new book, still needs to be made"""
#
return render_template("upload.html") return render_template("upload.html")

2
library/templates/index.html

@ -7,7 +7,7 @@
<div id="main"> <div id="main">
<ul> <ul>
{% for id, pubinfo in publications.items() %} {% 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%} {% endfor%}
</ul> </ul>
</div> </div>

10
library/templates/menu.html

@ -5,8 +5,16 @@
<button class="dropbtn">Type</button> <button class="dropbtn">Type</button>
<div class="dropdown-content"> <div class="dropdown-content">
{% for pubtype in pubtypes %} {% 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 %} {% endfor %}
</div> </div>
</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>
{% endblock menu %} {% endblock menu %}

Loading…
Cancel
Save