From fc1b8d704502c75f0b612b45eba8ed883dc479c4 Mon Sep 17 00:00:00 2001 From: crunk Date: Fri, 11 Dec 2020 18:12:52 +0100 Subject: [PATCH] individual links to books are IDs from the csv file, main page is now author ant title --- library/csvparser/csvparser.py | 7 +++++-- library/page.py | 4 ++-- library/templates/index.html | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/library/csvparser/csvparser.py b/library/csvparser/csvparser.py index 7d1ebe8..fa69760 100644 --- a/library/csvparser/csvparser.py +++ b/library/csvparser/csvparser.py @@ -16,9 +16,12 @@ def getpublications(): with libcsv: csv_as_dict = csv.DictReader(libcsv) listofbooks = [] + listofids = [] for row in csv_as_dict: - listofbooks.append(row["Publication"]) - return listofbooks + book = "{} - {}".format(row["Author"], row["Publication"]) + listofbooks.append(book) + listofids.append(row["Id"]) + return listofids, listofbooks parsecsv() diff --git a/library/page.py b/library/page.py index b054710..dd09dfd 100644 --- a/library/page.py +++ b/library/page.py @@ -13,8 +13,8 @@ APP = flask.Flask(__name__, static_folder="static") def index(): """Main path""" # parse csv, render template with a few elements from the csv - titles = getpublications() - return render_template("index.html", titles=titles) + ids, titles = getpublications() + return render_template("index.html", publications=zip(ids, titles)) @APP.route("/") diff --git a/library/templates/index.html b/library/templates/index.html index 49cb90a..ab79ce9 100644 --- a/library/templates/index.html +++ b/library/templates/index.html @@ -1,9 +1,9 @@ {% extends "base.html" %} {% block main %} - -{% for titles in titles %} - {{ titles }} + {% endblock %}