Browse Source

individual links to books are IDs from the csv file, main page is now author ant title

master
crunk 3 years ago
parent
commit
fc1b8d7045
  1. 7
      library/csvparser/csvparser.py
  2. 4
      library/page.py
  3. 8
      library/templates/index.html

7
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()

4
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("/<publication>")

8
library/templates/index.html

@ -1,9 +1,9 @@
{% extends "base.html" %}
{% block main %}
{% for titles in titles %}
<a href="{{ titles }}">{{ titles }}</a>
<ul>
{% for id, title in publications %}
<li><a href="{{ id }}">{{ title }}</a></li>
{% endfor%}
</ul>
{% endblock %}

Loading…
Cancel
Save