moved display message to base.html, should have done this from the beginning (doh), and then fixed deletion errors/redirections to be moe sensible

This commit is contained in:
2020-12-26 22:19:05 +11:00
parent 80719a3657
commit de860a1319
7 changed files with 19 additions and 32 deletions

14
main.py
View File

@@ -416,10 +416,18 @@ def book(id):
st.SetMessage( "This is a parent book, cannot delete it without deleting sub books first" ) st.SetMessage( "This is a parent book, cannot delete it without deleting sub books first" )
return redirect( '/book/{}'.format(book.id) ) return redirect( '/book/{}'.format(book.id) )
else: else:
st.SetMessage("WARNING: Deleting being tested at present.<br>")
st.AppendMessage("Deleted {}".format(book.title) )
pid = 0
if len(book.parent) > 0:
pid = book.parent[0].id
db.session.delete(book) db.session.delete(book)
db.session.commit() db.session.commit()
st.SetAlert("warning") st.SetAlert("warning")
st.SetMessage("WARNING: Deleting being tested at present") if pid > 0:
return redirect( '/book/{}'.format(pid) )
else:
return redirect( '/' )
elif book_form.validate(): elif book_form.validate():
book = Book.query.get(id) book = Book.query.get(id)
book.title = request.form['title'] book.title = request.form['title']
@@ -458,7 +466,7 @@ def book(id):
## TODO: ## TODO:
# what about series?, subbooks?, loan?, etc. # what about series?, subbooks?, loan?, etc.
db.session.commit() db.session.commit()
st.SetMesage( "Successfully Updated Book (id={})".format(id) ) st.SetMessage( "Successfully Updated Book (id={})".format(id) )
else: else:
st.SetAlert("danger") st.SetAlert("danger")
message="Failed to update Book (id={})".format(id) message="Failed to update Book (id={})".format(id)
@@ -506,7 +514,7 @@ def stats():
@app.route("/", methods=["GET"]) @app.route("/", methods=["GET"])
def main_page(): def main_page():
return render_template("base.html") return render_template("base.html", alert=st.GetAlert(), message=st.GetMessage())
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True) app.run(host="0.0.0.0", debug=True)

View File

@@ -2,12 +2,6 @@
{% block main_content %} {% block main_content %}
<h3>Show All Authors</h3> <h3>Show All Authors</h3>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
{{ ClearStatus() }}
</div>
{% endif %}
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true"> <table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead> <thead>
<tr class="thead-light"><th>Surname</th><th>Firstname(s)</th></tr> <tr class="thead-light"><th>Surname</th><th>Firstname(s)</th></tr>

View File

@@ -75,7 +75,14 @@
</div class="collapse navbar-collapse"> </div class="collapse navbar-collapse">
</nav> </nav>
{% block main_content %}{% endblock main_content %} {% if message|length %}
<div class="row alert alert-{{alert}}">
{{message|safe}}
{{ ClearStatus() }}
</div>
{% endif %}
{% block main_content %}
{% endblock main_content %}
<!-- code to get bootstrap & bootstrap datatable to work --> <!-- code to get bootstrap & bootstrap datatable to work -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

View File

@@ -125,11 +125,6 @@ function AddAuthorToBook(num) {
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %} {% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
<div class="container-fluid"> <div class="container-fluid">
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message|safe}}
</div>
{% endif %}
<div class="row"> <div class="row">
<form role="form" class="form col-lg-10" action="" method="POST"> <form role="form" class="form col-lg-10" action="" method="POST">
{{ book_form.id }} {{ book_form.id }}

View File

@@ -2,12 +2,6 @@
{% block main_content %} {% block main_content %}
<h3>Loans</h3> <h3>Loans</h3>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
{{ ClearStatus() }}
</div>
{% endif %}
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true"> <table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead> <thead>
<tr class="thead-light"><th>Surname</th><th>Firstname(s)</th><th>Date Lent</th><th>Contact Details</th></tr> <tr class="thead-light"><th>Surname</th><th>Firstname(s)</th><th>Date Lent</th><th>Contact Details</th></tr>

View File

@@ -7,11 +7,6 @@
<h3 class="col-lg-6"><center>Books in Series</center></h3> <h3 class="col-lg-6"><center>Books in Series</center></h3>
{% endif %} {% endif %}
</div class="row"> </div class="row">
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6">
<form class="form form-inline col-lg-12" action="" method="POST"> <form class="form form-inline col-lg-12" action="" method="POST">

View File

@@ -2,12 +2,6 @@
{% block main_content %} {% block main_content %}
<h3>{{page_title}}</h3> <h3>{{page_title}}</h3>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
{{ ClearStatus() }}
</div>
{% endif %}
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true"> <table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
<thead> <thead>
<tr class="thead-light"><th>Name</th></tr> <tr class="thead-light"><th>Name</th></tr>