removed clever code around publiseher/author, etc. it was just too cryptic, and it does not need to be so generic
This commit is contained in:
18
main.py
18
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
|
||||
from wtforms import SubmitField, StringField, HiddenField, SelectField, IntegerField, TextAreaField, validators
|
||||
from flask_wtf import FlaskForm
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -96,14 +96,18 @@ class BookSchema(ma.SQLAlchemyAutoSchema):
|
||||
# To be completed
|
||||
#
|
||||
class BookForm(FlaskForm):
|
||||
# I think I'll have to skip setting default on create, and using jquery to
|
||||
# change it when I create the from? (or maybe I could use a default=set_me
|
||||
# in the line below, then when I set create set_me = book.condition before
|
||||
# bf=BookForm()
|
||||
condition = SelectField( 'condition', choices=[(c.id, c.name) for c in Condition.query.order_by('id')] )
|
||||
covertype = SelectField( 'covertype', choices=[(c.id, c.name) for c in Covertype.query.order_by('id')] )
|
||||
id = HiddenField()
|
||||
title = StringField('Title:', [validators.DataRequired()])
|
||||
# author built by hand
|
||||
# publiser built by hand
|
||||
# genre built by hand
|
||||
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')] )
|
||||
year_published = IntegerField('Year Published:', [validators.NumberRange(min=1900, max=2100)] )
|
||||
rating = SelectField( 'rating', choices=[(c.id, c.name) for c in Rating.query.order_by('id')] )
|
||||
notes = TextAreaField('Notes:')
|
||||
blurb = TextAreaField('Blurb:')
|
||||
|
||||
|
||||
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
||||
|
||||
@@ -1,77 +1,58 @@
|
||||
{% extends "base.html" %}
|
||||
{% block main_content %}
|
||||
|
||||
<h3><center>View/Edit Book</center></h1>
|
||||
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<form class="form col-lg-12">
|
||||
{% for key in keys %}
|
||||
<div class="container"><div class="row"><form class="form col-lg-12">
|
||||
{% for key in keys %}
|
||||
<div class="form-row">
|
||||
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
|
||||
{% 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>
|
||||
<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">
|
||||
{{book_form[key](class="form-control")}}
|
||||
</div class="col-lg-10">
|
||||
</div class="form-row">
|
||||
{% else %}
|
||||
<div class="form-row">
|
||||
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
|
||||
<div class="col-lg-10">
|
||||
{% if books[key] is iterable and books[key] is not string %}
|
||||
{% elif key == "publisher" %}
|
||||
<div class="col-lg-10">
|
||||
<div class="form-row" style="margin-left:0px; margin-right:0px;">
|
||||
{% set cnt = namespace(idx=0, val=0) %}
|
||||
{% for objects in books[key] %}
|
||||
{% set cnt.val = 0 %}
|
||||
{% set str = namespace(val="") %}
|
||||
{% for attr in objects %}
|
||||
{% if attr != "id" %}
|
||||
{% if cnt.val > 0 %}
|
||||
{% set str.val=str.val+", "+objects[attr] %}
|
||||
{% else %}
|
||||
{% set str.val=str.val+objects[attr] %}
|
||||
{% endif %}
|
||||
{% set cnt.val = cnt.val + 1 %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<span class="form-control col" id="{{key}}[{{cnt.idx}}]">
|
||||
<a href="{{url_for(key, id=books[key][cnt.idx].id)}}">{{str.val}}</a>
|
||||
<span class="form-control col" id="{{key}}[0]">
|
||||
<a href="{{url_for(key, id=books[key][0].id)}}">{{books[key][0].name}}</a>
|
||||
</span>
|
||||
{% set cnt.idx = cnt.idx+1 %}
|
||||
{% endfor %}
|
||||
</div class="row">
|
||||
{% else %}
|
||||
{% if key == "notes" or key == "blurb" %}
|
||||
<textarea rows="5" type="text" class="form-control input-lg" id="{{key}}">{{books[key]}}</textarea>
|
||||
{% else %}
|
||||
<input type="text" class="form-control input-lg" id="{{key}}" value="{{books[key]}}">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div class="col-lg-10">
|
||||
</div class="form-row">
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div class="row">
|
||||
</div class="container">
|
||||
</div class="col-lg-10">
|
||||
{% elif key == "author" %}
|
||||
<div class="col-lg-10">
|
||||
<div class="form-row" style="margin-left:0px; margin-right:0px;">
|
||||
{% set cnt = namespace(idx=0) %}
|
||||
{% for objects in books[key] %}
|
||||
<span class="form-control col" id="{{key}}[{{cnt.idx}}]">
|
||||
<a href="{{url_for(key, id=books[key][cnt.idx].id)}}">
|
||||
{{books.author[cnt.idx].surname + ", " + books.author[cnt.idx].firstnames}}
|
||||
</a>
|
||||
</span>
|
||||
{% set cnt.idx = cnt.idx+1 %}
|
||||
{% endfor %}
|
||||
</div class="row">
|
||||
</div class="col-lg-10">
|
||||
{% else %}
|
||||
<div class="col-lg-10">
|
||||
{{book_form[key](class="form-control", value=books[key], rows="5" )}}
|
||||
</div class="col-lg-10">
|
||||
{% endif %}
|
||||
</div class="form-row">
|
||||
{% endfor %}
|
||||
</form></div class="row"></div class="container">
|
||||
{% if books.sub_book|length %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user