created generic id_name_form.html and made condition, covertype, genre, owned, publisher & rating use it for single edit page

This commit is contained in:
2020-11-18 12:09:02 +11:00
parent 8ebf9b73cb
commit 5f46636298
15 changed files with 34 additions and 147 deletions

View File

@@ -1,4 +1,5 @@
from wtforms import SubmitField, StringField, HiddenField, validators, Form
from flask_wtf import FlaskForm
from flask import request, render_template
from __main__ import db, app, ma
@@ -24,7 +25,7 @@ class AuthorSchema(ma.SQLAlchemyAutoSchema):
################################################################################
# Helper class that defines a form for author, used to make html <form>, with field validation (via wtforms)
################################################################################
class AuthorForm(Form):
class AuthorForm(FlaskForm):
id = HiddenField()
firstnames = StringField('FirstName(s):', [validators.DataRequired()])
surname = StringField('Surname:', [validators.DataRequired()])
@@ -49,7 +50,8 @@ def author(id):
### DDP: should this be request.form or request.values?
alert="Success"
author_form = AuthorForm(request.form)
if request.method == 'POST' and author_form.validate():
print( author_form.validate_on_submit() )
if request.method == 'POST' and author_form.validate_on_submit():
id = request.form['id']
author = Author.query.get(id)
try:

View File

@@ -63,4 +63,4 @@ def condition(id):
condition = Condition.query.get(id)
condition_form = ConditionForm(request.values, obj=condition)
message=""
return render_template("condition.html", condition=condition, alert=alert, message=message, condition_form=condition_form)
return render_template("id_name_form.html", condition=condition, alert=alert, message=message, form=condition_form, page_title='Edit Condition')

View File

@@ -63,4 +63,4 @@ def covertype(id):
covertype = Covertype.query.get(id)
covertype_form = CovertypeForm(request.values, obj=covertype)
message=""
return render_template("covertype.html", covertype=covertype, alert=alert, message=message, covertype_form=covertype_form)
return render_template("id_name_form.html", covertype=covertype, alert=alert, message=message, form=covertype_form, page_title='Edit Covertype')

View File

@@ -61,4 +61,4 @@ def genre(id):
genre = Genre.query.get(id)
genre_form = GenreForm(request.values, obj=genre)
message=""
return render_template("genre.html", genre=genre, alert=alert, message=message, genre_form=genre_form)
return render_template("id_name_form.html", genre=genre, alert=alert, message=message, form=genre_form, page_title='Edit Genre')

View File

@@ -63,4 +63,4 @@ def owned(id):
owned = Owned.query.get(id)
owned_form = OwnedForm(request.values, obj=owned)
message=""
return render_template("owned.html", owned=owned, alert=alert, message=message, owned_form=owned_form)
return render_template("id_name_form.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Edit Owned Type' )

View File

@@ -1,5 +1,6 @@
from wtforms import SubmitField, StringField, HiddenField, validators, Form
from flask import request, render_template
from flask_wtf import FlaskForm
from __main__ import db, app, ma
################################################################################
@@ -21,7 +22,7 @@ class PublisherSchema(ma.SQLAlchemyAutoSchema):
################################################################################
# Helper class that defines a form for publisher, used to make html <form>, with field validation (via wtforms)
################################################################################
class PublisherForm(Form):
class PublisherForm(FlaskForm):
id = HiddenField()
name = StringField('Name:', [validators.DataRequired()])
submit = SubmitField('Save' )
@@ -45,7 +46,7 @@ def publisher(id):
### DDP: should this be request.form or request.values?
alert="Success"
publisher_form = PublisherForm(request.form)
if request.method == 'POST' and publisher_form.validate():
if request.method == 'POST' and publisher_form.validate_on_submit():
id = request.form['id']
publisher = Publisher.query.get(id)
try:
@@ -61,4 +62,4 @@ def publisher(id):
publisher = Publisher.query.get(id)
publisher_form = PublisherForm(request.values, obj=publisher)
message=""
return render_template("publisher.html", publisher=publisher, alert=alert, message=message, publisher_form=publisher_form)
return render_template("id_name_form.html", publisher=publisher, alert=alert, message=message, form=publisher_form, page_title='Edit Publisher')

View File

@@ -63,4 +63,4 @@ def rating(id):
rating = Rating.query.get(id)
rating_form = RatingForm(request.values, obj=rating)
message=""
return render_template("rating.html", rating=rating, alert=alert, message=message, rating_form=rating_form)
return render_template("id_name_form.html", rating=rating, alert=alert, message=message, form=rating_form, page_title='Edit Rating')

View File

@@ -1,26 +1,30 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Author</center></h3>
<div class="container">
<right>
<h3 class="col-lg-12"><center>Author</center></h3>
<div class="row">
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( author_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( author_form.firstnames, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
{{ wtf.form_field( author_form.surname, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( author_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( author_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
<form class="form form-inline col-lg-12" action="" method="POST">
{{ author_form.csrf_token }}
{{ author_form.id }}
<div class="form-row col-lg-12">
{{ author_form.firstnames.label( class="col-lg-2" ) }}
{{ author_form.firstnames( class="form-control col-lg-2" ) }}
</div class="form-row">
<div class="form-row col-lg-12">
{{ author_form.surname.label( class="col-lg-2" ) }}
{{ author_form.surname( class="form-control col-lg-2" ) }}
</div class="form-row">
<div class="row col-lg-12">
<br>
</div class="row">
<div class="form-row col-lg-12">
{{ author_form.delete( class="btn btn-outline-danger col-lg-2" )}}
{{ author_form.submit( class="btn btn-primary col-lg-2" )}}
</div class="form-row">
</form>
</div class="row">
</div class="container">

View File

@@ -54,7 +54,7 @@
<a class="dropdown-item" href="{{url_for('owneds')}}">Create new Owned Type</a>
<a class="dropdown-item" href="{{url_for('owneds')}}">Show Owned Types</a>
<a class="dropdown-item" href="{{url_for('ratings')}}">Create new Rating</a>
<a class="dropdown-item" href="{{url_for('ratings')}}">Show Owned Ratings</a>
<a class="dropdown-item" href="{{url_for('ratings')}}">Show Ratings</a>
</div>
</div>
</div>

View File

@@ -1,24 +0,0 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Condition</center></h3>
<div class="container">
<right>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( condition_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( condition_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( condition_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( condition_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
</form>
</div class="row">
</div class="container">
{% endblock main_content %}

View File

@@ -1,24 +0,0 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Covertype</center></h3>
<div class="container">
<right>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( covertype_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( covertype_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( covertype_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( covertype_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
</form>
</div class="row">
</div class="container">
{% endblock main_content %}

View File

@@ -1,24 +0,0 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Genre</center></h3>
<div class="container">
<right>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( genre_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( genre_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( genre_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( genre_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
</form>
</div class="row">
</div class="container">
{% endblock main_content %}

View File

@@ -1,24 +0,0 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Owned</center></h3>
<div class="container">
<right>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( owned_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( owned_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( owned_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( owned_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
</form>
</div class="row">
</div class="container">
{% endblock main_content %}

View File

@@ -1,24 +0,0 @@
{% extends "base.html" %} {% block main_content %}
<h3><center>Rating</center></h3>
<div class="container">
<right>
{% if message|length %}
<div class="row alert alert-{{alert}}">
{{message}}
</div>
{% endif %}
<div class="row">
<form class="form form-inline col-xl-12" action="" method="POST">
{{ wtf.form_field( rating_form.id, form_type='inline' ) }}
<div class="col-xl-12">
{{ wtf.form_field( rating_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
</div>
<div class="col-xl-12">
<br></br>
</div>
{{ wtf.form_field( rating_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
{{ wtf.form_field( rating_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
</form>
</div class="row">
</div class="container">
{% endblock main_content %}