diff --git a/app/models.py b/app/models.py index 66a1970..ab40883 100755 --- a/app/models.py +++ b/app/models.py @@ -36,7 +36,6 @@ class Book(db.Model): class Author(db.Model): __tablename__ = 'authors' id = db.Column(db.Integer(), primary_key=True) - book_id = db.Column(db.Integer(), db.ForeignKey('books.id')) author_name = db.Column(db.String(50)) diff --git a/app/templates/show_author_detail.html b/app/templates/show_author_detail.html new file mode 100755 index 0000000..cc0e8b6 --- /dev/null +++ b/app/templates/show_author_detail.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block main %} +
+ +

{{ author.author_name }}

+ + +

Book(s): {% for book in author.books %} + +

  • {{ book.title }}
  • + + {% endfor %}

    + +
    +
    + edit + +
    +{% endblock %} diff --git a/app/templates/show_book_detail.html b/app/templates/show_book_detail.html index 3716923..9adea8f 100755 --- a/app/templates/show_book_detail.html +++ b/app/templates/show_book_detail.html @@ -7,11 +7,11 @@ -

    Author(s): {% for author in book.author %} +

    Author(s):

    download {{ book.fileformat }}
    @@ -20,3 +20,5 @@ {% endblock %} + + diff --git a/app/templates/show_books.html b/app/templates/show_books.html index ca0acb1..e7cef45 100755 --- a/app/templates/show_books.html +++ b/app/templates/show_books.html @@ -28,9 +28,9 @@ {{ book.title }} - {% for author in book.author %} + {% for author in book.authors %} -
  • {{ author.author_name }}
  • +
  • {{ author.author_name }}
  • {% endfor %} {{ book.fileformat }} diff --git a/app/views.py b/app/views.py index 4ac30f8..c592a09 100755 --- a/app/views.py +++ b/app/views.py @@ -65,6 +65,7 @@ def show_book_by_id(id): else: return render_template('show_book_detail.html', book=book) + @app.route('/books//delete', methods=['POST', 'GET']) def remove_book_by_id(id): book_to_edit = Book.query.filter_by(id=id).first() @@ -159,6 +160,46 @@ def flash_errors(form): error )) +#Authors + +@app.route('/authors/') +def show_author_by_id(id): + author = Author.query.get(id) + if not author: + abort (404) + else: + return render_template('show_author_detail.html', author=author) + + +@app.route('/authors//edit', methods=['POST', 'GET']) +def edit_author_by_id(id): + book_to_edit = Book.query.filter_by(id=id).first() + user_form = UserForm_Edit(title = book_to_edit.title, author =book_to_edit.author) + + if request.method == 'POST': + if user_form.validate_on_submit(): + # check if the post request has the file part + title = user_form.title.data # You could also have used request.form['name'] + author = user_form.author.data # You could also have used request.form['email'] + # save user to database + #book = Book(title, author, filename, cover, file_extension) + book_to_edit.title = title + db.session.commit() + + book = Book.query.filter_by(title=title).first() + author_table = Author.query.filter_by(user_id=book.id).delete() + for this_author in author: + this_author = Author(this_author.get('author_name')) + book.author.append(this_author) + db.session.commit() + + flash("%s updated" % (title)) + return redirect(url_for('show_books')) + + return render_template('edit_book_detail.html', book=book_to_edit, form=user_form) + + + ### # The API @@ -212,3 +253,6 @@ def page_not_found(error): if __name__ == '__main__': app.run(debug=True,host="0.0.0.0",port="8080") + + + diff --git a/run.py b/run.py index 48257b9..9b4e490 100755 --- a/run.py +++ b/run.py @@ -1,3 +1,3 @@ #! /usr/bin/env python 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)