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:
11
main.py
11
main.py
@@ -165,8 +165,8 @@ class BookForm(FlaskForm):
|
||||
id = HiddenField()
|
||||
title = StringField('Title:', [validators.DataRequired()])
|
||||
# author built by hand
|
||||
# publiser 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')] )
|
||||
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')] )
|
||||
@@ -332,11 +332,11 @@ def book(id):
|
||||
message=""
|
||||
book_form = BookForm(request.form)
|
||||
book = Book.query.get(id)
|
||||
if request.method == 'POST' and book_form.validate():
|
||||
if request.method == 'POST':
|
||||
if 'delete' in request.form:
|
||||
alert="danger"
|
||||
message="Sorry, Deleting unsupported at present"
|
||||
else:
|
||||
elif book_form.validate():
|
||||
book.title = request.form['title']
|
||||
book.owned = request.form['owned']
|
||||
book.covertype = request.form['covertype']
|
||||
@@ -349,9 +349,14 @@ def book(id):
|
||||
# process author, genre, publisher & series?, subbooks?, loan?, etc.
|
||||
db.session.commit()
|
||||
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:
|
||||
book_form=BookForm(request.form)
|
||||
# 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.covertype.default = book.covertype
|
||||
book_form.owned.default = book.owned
|
||||
|
||||
@@ -32,24 +32,6 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
</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" %}
|
||||
<div class="form-row col" style="margin-left:0px;margin-right:0px">
|
||||
{% set cnt = namespace(idx=0) %}
|
||||
@@ -62,11 +44,6 @@
|
||||
</button>
|
||||
</div>
|
||||
{% 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}}]">
|
||||
{% for auth in author_list %}
|
||||
{% set aname=auth.surname+", "+auth.firstnames %}
|
||||
|
||||
Reference in New Issue
Block a user