diff --git a/author.py b/author.py index 1e4ac7a..6a0891d 100644 --- a/author.py +++ b/author.py @@ -44,7 +44,7 @@ class AuthorForm(FlaskForm): @app.route("/authors", methods=["GET"]) @login_required def authors(): - authors = Author.query.all() + authors = Author.query.order_by(Author.surname, Author.firstnames).all() return render_template("authors.html", authors=authors, alert=st.GetAlert(), message=st.GetMessage() ) @@ -97,10 +97,49 @@ def author(id): st.SetMessage( f"Failed to modify Author: {e.orig}" ) return render_template("edit_id_name.html", form=form, page_title=page_title, alert=st.GetAlert(), message=st.GetMessage() ) else: + print(id) author = Author.query.get(id) form = AuthorForm(request.values, obj=author) return render_template("edit_id_name.html", object=author, form=form, page_title = page_title, alert=st.GetAlert(), message=st.GetMessage() ) +@app.route("/author//books", methods=["GET"]) +@login_required +def authors_books(author_id): + """ show all the books written by the specified author """ + from main import Book, Book_Author_Link + books=Book.query.join(Book_Author_Link,Author).filter(Author.id==author_id).order_by(Book.title).all() + + # now need to re-order books to cater for sub-book ordering + ordered_books=[] + processed=[] + for b in books: + if b.id not in processed: + if b.IsParent(): + ordered_books.append(b) + processed.append( b.id ) + for bb in b.child_ref: + tmp=Book.query.get(bb.sub_book_id) + ordered_books.append( tmp ) + processed.append( bb.sub_book_id ) + elif b.IsChild(): + ordered_books.append(b.parent[0]) + processed.append( b.parent[0].id ) + cnt=1 + for bb in b.parent[0].child_ref: + tmp=Book.query.get(bb.sub_book_id) + # need to set parent_id and sub_book_num for indenting to work in html + tmp.parent_id=b.parent[0].id + tmp.sub_book_num=cnt + ordered_books.append( tmp ) + processed.append( bb.sub_book_id ) + cnt+=1 + else: + ordered_books.append(b) + processed.append( b.id ) + a=Author.query.get(author_id) + return render_template("books.html", books=ordered_books, page_title=f"All {a.surname}, {a.firstnames} books:", no_navbar=True ) + + ################################################################################ # helper fund to GetAuthors -> author_list -> jinja2 for author drop-down in book.html ################################################################################ diff --git a/templates/base.html b/templates/base.html index b55193e..2170e0d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -18,6 +18,8 @@ + {% if not no_navbar %} + + {% endif %} {% if message is defined and message|length %}
{{message|safe}} {{ ClearStatus() }}
- {% endif %} + {% endif %} {% endif %} {% block main_content %} {% endblock main_content %} -{% if not InDBox %} +{% if not InDBox and not no_navbar %} diff --git a/templates/edit_id_name.html b/templates/edit_id_name.html index aba7ad3..b07871a 100644 --- a/templates/edit_id_name.html +++ b/templates/edit_id_name.html @@ -24,4 +24,16 @@ + {% if page_title == 'Edit Author' %} +
+
+
+
+ {% endif %} {% endblock main_content %} + +{% block script_content %} + +{% endblock script_content %}