This commit is contained in:
Alex 2018-05-23 18:11:17 +02:00
commit 4fce8cc5c5
5 changed files with 24 additions and 8 deletions

View File

@ -6,11 +6,15 @@
<h1 class="header">{{ author.author_name }}</h1> <h1 class="header">{{ author.author_name }}</h1>
<p>Books: {% for book in author.books %} <p>Book(s): {% for book in author.books %}
<li> {{ book.title }}</li> <li> <a href="{{url_for('show_book_by_id', id=book.id)}}">{{ book.title }}</a> </li>
{% endfor %}</p> {% endfor %}</p>
<br>
<br>
<a href="{{ url_for('edit_author_by_id', id=author.id )}}">edit</a>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -7,11 +7,11 @@
<img src="../uploads/cover/{{ book.cover }}" width="200"> <img src="../uploads/cover/{{ book.cover }}" width="200">
<p>Author(s): {% for author in book.authors %} <p>Author(s): <ul>{% for author in book.authors %}
<li> {{ author.author_name }}</li> <li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
{% endfor %}</p> {% endfor %}</ul></p>
<a href="../uploads/{{ book.file }}">download {{ book.fileformat }}</a> <a href="../uploads/{{ book.file }}">download {{ book.fileformat }}</a>
<br> <br>

View File

@ -30,7 +30,7 @@
<td> {% for author in book.authors %} <td> {% for author in book.authors %}
<li> <a href ="authors/{{ author.id }}">{{ author.author_name }}</a></li> <li><a href="{{url_for('show_author_by_id', id=author.id)}}">{{ author.author_name }}</a> </li>
{% endfor %}</td> {% endfor %}</td>
<td>{{ book.fileformat }}</td> <td>{{ book.fileformat }}</td>

View File

@ -65,6 +65,7 @@ def show_book_by_id(id):
else: else:
return render_template('show_book_detail.html', book=book) return render_template('show_book_detail.html', book=book)
@app.route('/books/<int:id>/delete', methods=['POST', 'GET']) @app.route('/books/<int:id>/delete', methods=['POST', 'GET'])
def remove_book_by_id(id): def remove_book_by_id(id):
book_to_edit = Book.query.filter_by(id=id).first() book_to_edit = Book.query.filter_by(id=id).first()
@ -162,14 +163,25 @@ def flash_errors(form):
error error
)) ))
#Authors
@app.route('/authors/<int:id>') @app.route('/authors/<int:id>')
def show_author_by_id(id): def show_author_by_id(id):
author = Author.query.get(id) author = Author.query.get(id)
if not author: if not author:
abort(404) abort (404)
else: else:
return render_template('show_author_detail.html', author=author) return render_template('show_author_detail.html', author=author)
@app.route('/authors/<int:id>/edit', methods=['POST', 'GET'])
def edit_author_by_id(id):
#EDIT AUTHOR TO DO
return None
### ###
# The API # The API
### ###

2
run.py
View File

@ -1,3 +1,3 @@
#! /usr/bin/env python #! /usr/bin/env python
from app import app from app import app
app.run(debug=True,host="0.0.0.0",port=8080) app.run(debug=True,host="0.0.0.0",port=8000)