add helper function GetGenreList - passes all genres to *.html, so horizontal "list" of checkboxes for book can be created
This commit is contained in:
7
main.py
7
main.py
@@ -2,7 +2,7 @@ from flask import Flask, render_template, request
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_marshmallow import Marshmallow
|
||||
from flask_bootstrap import Bootstrap
|
||||
from wtforms import SubmitField, StringField, HiddenField, SelectField, validators, Form
|
||||
from wtforms import SubmitField, StringField, HiddenField, SelectField, validators
|
||||
from flask_wtf import FlaskForm
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -17,7 +17,7 @@ Bootstrap(app)
|
||||
|
||||
from author import Author, AuthorForm, AuthorSchema
|
||||
from publisher import Publisher, PublisherForm, PublisherSchema
|
||||
from genre import Genre, GenreForm, GenreSchema
|
||||
from genre import Genre, GenreForm, GenreSchema, GetGenreList
|
||||
from condition import Condition, ConditionForm, ConditionSchema
|
||||
from covertype import Covertype, CovertypeForm, CovertypeSchema
|
||||
from owned import Owned, OwnedForm, OwnedSchema
|
||||
@@ -164,7 +164,8 @@ def book(id):
|
||||
book_form.owned.default = book.owned
|
||||
book_form.rating.default = book.rating
|
||||
book_form.process()
|
||||
return render_template("book.html", books=book_s, subs=sub_book, book_form=book_form )
|
||||
genre_list = GetGenreList()
|
||||
return render_template("book.html", books=book_s, subs=sub_book, book_form=book_form, genre_list=genre_list )
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
def main_page():
|
||||
|
||||
@@ -6,7 +6,26 @@
|
||||
<div class="row">
|
||||
<form class="form col-lg-12">
|
||||
{% for key in keys %}
|
||||
{% if key == "condition" or key == "covertype" or key == "owned" or key == "rating" %}
|
||||
{% if key == "genre" %}
|
||||
<div class="form-row">
|
||||
<label class="col-lg-2 col-form-label">{{key}}:</label>
|
||||
<div class="form-row col-lg-10">
|
||||
{% for genre in genre_list %}
|
||||
{% set gname=genre.name %}
|
||||
<div class="form-control col" style="margin-left:5px;margin-right:-5px;">
|
||||
<input id="{{gname}}" name="{{gname}}" type="checkbox"
|
||||
{% for book_g in books.genre %}
|
||||
{% if book_g['name'] == gname %}
|
||||
checked
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
></input>
|
||||
<label style="display:inline" for="{{gname}}" class="col-form-label">{{gname}}</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div class="form-row">
|
||||
{% elif key == "condition" or key == "covertype" or key == "owned" or key == "rating" %}
|
||||
<div class="form-row">
|
||||
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
|
||||
<div class="col-lg-10">
|
||||
@@ -56,8 +75,11 @@
|
||||
{% if books.sub_book|length %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
{% if books.subs|length %}
|
||||
<p>subs is defined {{ books.subs }}</p>
|
||||
{% endif %}
|
||||
{% if books.loan|length %}
|
||||
<p>loan is defined: {{books.loan}}</p>
|
||||
{% endif %}
|
||||
{{ books.subs }}
|
||||
|
||||
{% endblock main_content %}
|
||||
|
||||
Reference in New Issue
Block a user