remove edit buttons on author/publisher, in fact publisher is now a standard field with a BookForm SelectField, and showing, updating publisher works in book.html

This commit is contained in:
2020-12-02 19:48:51 +11:00
parent b5e9c41cfd
commit 93383c3bc0
2 changed files with 8 additions and 26 deletions

11
main.py
View File

@@ -165,8 +165,8 @@ class BookForm(FlaskForm):
id = HiddenField() id = HiddenField()
title = StringField('Title:', [validators.DataRequired()]) title = StringField('Title:', [validators.DataRequired()])
# author built by hand # author built by hand
# publiser built by hand
# genre built by hand # genre built by hand
publisher = SelectField( 'publisher', choices=[(c.id, c.name) for c in Publisher.query.order_by('id')] )
owned = SelectField( 'owned', choices=[(c.id, c.name) for c in Owned.query.order_by('id')] ) owned = SelectField( 'owned', choices=[(c.id, c.name) for c in Owned.query.order_by('id')] )
covertype = SelectField( 'covertype', choices=[(c.id, c.name) for c in Covertype.query.order_by('id')] ) covertype = SelectField( 'covertype', choices=[(c.id, c.name) for c in Covertype.query.order_by('id')] )
condition = SelectField( 'condition', choices=[(c.id, c.name) for c in Condition.query.order_by('id')] ) condition = SelectField( 'condition', choices=[(c.id, c.name) for c in Condition.query.order_by('id')] )
@@ -332,11 +332,11 @@ def book(id):
message="" message=""
book_form = BookForm(request.form) book_form = BookForm(request.form)
book = Book.query.get(id) book = Book.query.get(id)
if request.method == 'POST' and book_form.validate(): if request.method == 'POST':
if 'delete' in request.form: if 'delete' in request.form:
alert="danger" alert="danger"
message="Sorry, Deleting unsupported at present" message="Sorry, Deleting unsupported at present"
else: elif book_form.validate():
book.title = request.form['title'] book.title = request.form['title']
book.owned = request.form['owned'] book.owned = request.form['owned']
book.covertype = request.form['covertype'] book.covertype = request.form['covertype']
@@ -349,9 +349,14 @@ def book(id):
# process author, genre, publisher & series?, subbooks?, loan?, etc. # process author, genre, publisher & series?, subbooks?, loan?, etc.
db.session.commit() db.session.commit()
message="Successfully Updated Book (id={})".format(id) message="Successfully Updated Book (id={})".format(id)
else:
alert="danger"
print( book_form)
message="Shit broke in update of Book (id={}) {}".format(id, book_form.owned.data)
else: else:
book_form=BookForm(request.form) book_form=BookForm(request.form)
# set defaults for drop-down's based on this book # set defaults for drop-down's based on this book
book_form.publisher.default = book.publisher[0].id
book_form.condition.default = book.condition book_form.condition.default = book.condition
book_form.covertype.default = book.covertype book_form.covertype.default = book.covertype
book_form.owned.default = book.owned book_form.owned.default = book.owned

View File

@@ -32,24 +32,6 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% elif key == "publisher" %}
<div class="form-row col input-group" style="margin-left:0px; margin-right:0px;">
<div class="input-group-prepend">
<button class="btn btn-outline-primary" type="button">
<a style="color:inherit" href="{{url_for(key, id=books[key][0].id)}}"><i class="far fa-edit"></i></a>
</button>
</div>
<select class="form-control" id="publisher">
{% for pub in publisher_list %}
{% set pname=pub.name %}
<option id="{{pub.id}}" value="{{pub.id}}"
{% if books.publisher[0].name == pname %}
selected
{% endif %}
>{{pname}}</option>
{% endfor %}
</select>
</div class="row">
{% elif key == "author" %} {% elif key == "author" %}
<div class="form-row col" style="margin-left:0px;margin-right:0px"> <div class="form-row col" style="margin-left:0px;margin-right:0px">
{% set cnt = namespace(idx=0) %} {% set cnt = namespace(idx=0) %}
@@ -62,11 +44,6 @@
</button> </button>
</div> </div>
{% endif %} {% endif %}
<div class="input-group-prepend">
<button class="btn btn-outline-primary" type="button">
<a style="color:inherit" href="{{url_for(key, id=books[key][cnt.idx].id)}}"><i class="far fa-edit"></i></a>
</button>
</div>
<select class="form-control" id="author[{{cnt.idx}}]"> <select class="form-control" id="author[{{cnt.idx}}]">
{% for auth in author_list %} {% for auth in author_list %}
{% set aname=auth.surname+", "+auth.firstnames %} {% set aname=auth.surname+", "+auth.firstnames %}