moved to using a Get*ById() in condition, covertype, owned files and exposing them in jinja and using them in books.html to fix-up the fact those columns were now raw forein keys (ids)
This commit is contained in:
@@ -65,3 +65,7 @@ def condition(id):
|
||||
condition_form = ConditionForm(request.values, obj=condition)
|
||||
message=""
|
||||
return render_template("edit_id_name.html", condition=condition, alert=alert, message=message, form=condition_form, page_title='Edit Condition')
|
||||
|
||||
def GetConditionById(id):
|
||||
return Condition.query.get(id).name
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ def covertypes():
|
||||
covertypes = Covertype.query.order_by('id').all()
|
||||
return render_template( "show_id_name.html", objects=covertypes, page_title='Show All Covertypes', url_base='covertype')
|
||||
|
||||
def GetCovertypes():
|
||||
covertypes = Covertype.query.order_by('name').all()
|
||||
cs = CovertypeSchema(many=True)
|
||||
return cs.dump( covertypes )
|
||||
|
||||
################################################################################
|
||||
# /covertype/<id> -> GET/POST(save or delete) -> shows/edits/delets a single
|
||||
# covertype
|
||||
@@ -65,3 +70,6 @@ def covertype(id):
|
||||
covertype_form = CovertypeForm(request.values, obj=covertype)
|
||||
message=""
|
||||
return render_template("edit_id_name.html", covertype=covertype, alert=alert, message=message, form=covertype_form, page_title='Edit Covertype')
|
||||
|
||||
def GetCovertypeById(id):
|
||||
return Covertype.query.get(id).name
|
||||
|
||||
13
main.py
13
main.py
@@ -18,12 +18,17 @@ Bootstrap(app)
|
||||
from author import Author, AuthorForm, AuthorSchema
|
||||
from publisher import Publisher, PublisherForm, PublisherSchema, GetPublishers
|
||||
from genre import Genre, GenreForm, GenreSchema, GetGenres
|
||||
from condition import Condition, ConditionForm, ConditionSchema
|
||||
from covertype import Covertype, CovertypeForm, CovertypeSchema
|
||||
from owned import Owned, OwnedForm, OwnedSchema
|
||||
from condition import Condition, ConditionForm, ConditionSchema, GetConditionById
|
||||
from covertype import Covertype, CovertypeForm, CovertypeSchema, GetCovertypeById
|
||||
from owned import Owned, OwnedForm, OwnedSchema, GetOwnedById
|
||||
from rating import Rating, RatingForm, RatingSchema
|
||||
from loan import Loan, LoanForm, LoanSchema
|
||||
|
||||
# allow jinja2 to call this python function
|
||||
app.jinja_env.globals['GetCovertypeById'] = GetCovertypeById
|
||||
app.jinja_env.globals['GetOwnedById'] = GetOwnedById
|
||||
app.jinja_env.globals['GetConditionById'] = GetConditionById
|
||||
|
||||
####################################### CLASSES / DB model #######################################
|
||||
book_author_link = db.Table('book_author_link', db.Model.metadata,
|
||||
db.Column('book_id', db.Integer, db.ForeignKey('book.id')),
|
||||
@@ -170,7 +175,7 @@ def book(id):
|
||||
book_form.process()
|
||||
genre_list = GetGenres()
|
||||
publisher_list = GetPublishers()
|
||||
return render_template("book.html", books=book_s, subs=sub_book, book_form=book_form, genre_list=genre_list, publisher_list=publisher_list )
|
||||
return render_template("book.html", books=book_s, subs=sub_book, book_form=book_form, genre_list=genre_list, publisher_list=publisher_list, covertype_list=covertypes )
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def main_page():
|
||||
|
||||
3
owned.py
3
owned.py
@@ -65,3 +65,6 @@ def owned(id):
|
||||
owned_form = OwnedForm(request.values, obj=owned)
|
||||
message=""
|
||||
return render_template("edit_id_name.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Edit Owned Type' )
|
||||
|
||||
def GetOwnedById(id):
|
||||
return Owned.query.get(id).name
|
||||
|
||||
@@ -16,16 +16,17 @@
|
||||
<td>{{ book.author[0]['surname'] }}, {{book.author[0]['firstnames']}}</td>
|
||||
<td>{{ book.publisher[0]['name']}}</td>
|
||||
<td align="center">
|
||||
{% if book.condition == "Good" %}
|
||||
{% set cond = GetConditionById(book.condition) %}
|
||||
{% if cond == "Good" %}
|
||||
<i class="fas fa-book" style="color:black"></i>
|
||||
{% elif book.condition == "Average" %}
|
||||
{% elif cond == "Average" %}
|
||||
<i class="fas fa-book" style="color:orange"></i>
|
||||
{% else %}
|
||||
<i class="fas fa-book" style="color:red"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ book.owned}}</td>
|
||||
<td>{{ book.covertype}}</td>
|
||||
<td>{{ GetOwnedById(book.owned)}}</td>
|
||||
<td>{{ GetCovertypeById(book.covertype) }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user