okay adding/removing authors is functional, ordering of it is NQR, also moved to bookstrap margin/padding classes where it worked
This commit is contained in:
11
main.py
11
main.py
@@ -361,15 +361,14 @@ def book(id):
|
||||
if "genre-{}".format(genre.id) in request.form:
|
||||
book.genre.append( genre )
|
||||
# set book author (empty list, in form they are in author-0, author-1, ... author-n)
|
||||
# so use while to find them all and append them back to now empty list
|
||||
acnt=0
|
||||
# so use find them all and append them back to now empty list
|
||||
book.author=[]
|
||||
while "author-{}".format( acnt ) in request.form:
|
||||
book.author.append( Author.query.get( request.form["author-{}".format( acnt )] ) )
|
||||
acnt = acnt + 1
|
||||
for el in request.form:
|
||||
if 'author-' in el:
|
||||
book.author.append( Author.query.get( request.form[el] ) )
|
||||
|
||||
## TODO:
|
||||
# what about add/remove author, series?, subbooks?, loan?, etc.
|
||||
# what about series?, subbooks?, loan?, etc.
|
||||
db.session.commit()
|
||||
message="Successfully Updated Book (id={})".format(id)
|
||||
else:
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
{% extends "base.html" %}
|
||||
{% block main_content %}
|
||||
|
||||
<script>
|
||||
function RemoveAuthorFromBook(num) {
|
||||
console.log("remove an author at slot: " + num )
|
||||
$('#auth-div-'+num).remove()
|
||||
}
|
||||
function AddAuthorToBook(num) {
|
||||
console.log("insert a new author at slot: " + num )
|
||||
div = `
|
||||
<div id="auth-div-NUM" class="col input-group px-0">
|
||||
<div class="input-group-prepend">
|
||||
<button class="btn btn-outline-danger" type="button" onClick="RemoveAuthorFromBook(NUM)"><i class="fas fa-minus"></i></button>
|
||||
</div>
|
||||
<select class="form-control" name="author-NUM" id="author-NUM">
|
||||
{% for auth in author_list %}
|
||||
{% set aname=auth.surname+", "+auth.firstnames %}
|
||||
<option value="{{auth.id}}">{{aname}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
`
|
||||
div=div.replace( /NUM/g, num )
|
||||
$('#auth-div-'+(num-1)).after( div )
|
||||
new_add_func_str='AddAuthorToBook('+(num+1)+')'
|
||||
$('#author-plus').attr( 'onclick', new_add_func_str )
|
||||
}
|
||||
</script>
|
||||
|
||||
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||
<div class="container-fluid">
|
||||
{% if message|length %}
|
||||
@@ -41,15 +68,13 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% elif key == "author" %}
|
||||
<div class="form-row col" style="margin-left:0px;margin-right:0px">
|
||||
<div class="form-row col mx-0">
|
||||
{% set cnt = namespace(idx=0) %}
|
||||
{% for objects in books[key] %}
|
||||
<div class="col input-group" style="padding-left:0px;padding-right:0px">
|
||||
<div id="auth-div-{{cnt.idx}}" class="col input-group px-0">
|
||||
{% if cnt.idx > 0 %}
|
||||
<div class="input-group-prepend">
|
||||
<button class="btn btn-outline-danger" type="button">
|
||||
<a style="color:inherit" href="{{url_for(key, id=-1)}}"><i class="fas fa-minus"></i></a>
|
||||
</button>
|
||||
<button class="btn btn-outline-danger" type="button" onClick="RemoveAuthorFromBook({{cnt.idx}})"><i class="fas fa-minus"></i></button>
|
||||
</div>
|
||||
{% endif %}
|
||||
<select class="form-control" name="author-{{cnt.idx}}" id="author-{{cnt.idx}}">
|
||||
@@ -66,9 +91,7 @@
|
||||
{% set cnt.idx = cnt.idx+1 %}
|
||||
{% endfor %}
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-success" type="button">
|
||||
<a style="color:inherit" href="{{url_for(key, id=-1)}}"><i class="fas fa-plus"></i></a>
|
||||
</button>
|
||||
<button id="author-plus" class="btn btn-outline-success" type="button" onClick="AddAuthorToBook({{cnt.idx}})"><i class="fas fa-plus"></i></button>
|
||||
</div>
|
||||
</div class="form-row">
|
||||
{% else %}
|
||||
@@ -118,7 +141,7 @@
|
||||
</form>
|
||||
{% if books.loan|length %}
|
||||
<div class="col">
|
||||
<div class="card border-primary" style="max-width: 18rem;">
|
||||
<div class="card border-primary">
|
||||
<div class="card-header bg-primary text-white">Loaned to</div>
|
||||
<div class="card-body text-primary">
|
||||
<h5 class="card-title">{{books.loan[0].firstnames}} {{books.loan[0].surname}}</h5>
|
||||
|
||||
Reference in New Issue
Block a user