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:
@@ -1,4 +1,5 @@
|
|||||||
from wtforms import SubmitField, StringField, HiddenField, validators, Form
|
from wtforms import SubmitField, StringField, HiddenField, validators, Form
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
from flask import request, render_template
|
from flask import request, render_template
|
||||||
from __main__ import db, app, ma
|
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)
|
# 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()
|
id = HiddenField()
|
||||||
firstnames = StringField('FirstName(s):', [validators.DataRequired()])
|
firstnames = StringField('FirstName(s):', [validators.DataRequired()])
|
||||||
surname = StringField('Surname:', [validators.DataRequired()])
|
surname = StringField('Surname:', [validators.DataRequired()])
|
||||||
@@ -49,7 +50,8 @@ def author(id):
|
|||||||
### DDP: should this be request.form or request.values?
|
### DDP: should this be request.form or request.values?
|
||||||
alert="Success"
|
alert="Success"
|
||||||
author_form = AuthorForm(request.form)
|
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']
|
id = request.form['id']
|
||||||
author = Author.query.get(id)
|
author = Author.query.get(id)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -63,4 +63,4 @@ def condition(id):
|
|||||||
condition = Condition.query.get(id)
|
condition = Condition.query.get(id)
|
||||||
condition_form = ConditionForm(request.values, obj=condition)
|
condition_form = ConditionForm(request.values, obj=condition)
|
||||||
message=""
|
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')
|
||||||
|
|||||||
@@ -63,4 +63,4 @@ def covertype(id):
|
|||||||
covertype = Covertype.query.get(id)
|
covertype = Covertype.query.get(id)
|
||||||
covertype_form = CovertypeForm(request.values, obj=covertype)
|
covertype_form = CovertypeForm(request.values, obj=covertype)
|
||||||
message=""
|
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')
|
||||||
|
|||||||
2
genre.py
2
genre.py
@@ -61,4 +61,4 @@ def genre(id):
|
|||||||
genre = Genre.query.get(id)
|
genre = Genre.query.get(id)
|
||||||
genre_form = GenreForm(request.values, obj=genre)
|
genre_form = GenreForm(request.values, obj=genre)
|
||||||
message=""
|
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')
|
||||||
|
|||||||
2
owned.py
2
owned.py
@@ -63,4 +63,4 @@ def owned(id):
|
|||||||
owned = Owned.query.get(id)
|
owned = Owned.query.get(id)
|
||||||
owned_form = OwnedForm(request.values, obj=owned)
|
owned_form = OwnedForm(request.values, obj=owned)
|
||||||
message=""
|
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' )
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from wtforms import SubmitField, StringField, HiddenField, validators, Form
|
from wtforms import SubmitField, StringField, HiddenField, validators, Form
|
||||||
from flask import request, render_template
|
from flask import request, render_template
|
||||||
|
from flask_wtf import FlaskForm
|
||||||
from __main__ import db, app, ma
|
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)
|
# 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()
|
id = HiddenField()
|
||||||
name = StringField('Name:', [validators.DataRequired()])
|
name = StringField('Name:', [validators.DataRequired()])
|
||||||
submit = SubmitField('Save' )
|
submit = SubmitField('Save' )
|
||||||
@@ -45,7 +46,7 @@ def publisher(id):
|
|||||||
### DDP: should this be request.form or request.values?
|
### DDP: should this be request.form or request.values?
|
||||||
alert="Success"
|
alert="Success"
|
||||||
publisher_form = PublisherForm(request.form)
|
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']
|
id = request.form['id']
|
||||||
publisher = Publisher.query.get(id)
|
publisher = Publisher.query.get(id)
|
||||||
try:
|
try:
|
||||||
@@ -61,4 +62,4 @@ def publisher(id):
|
|||||||
publisher = Publisher.query.get(id)
|
publisher = Publisher.query.get(id)
|
||||||
publisher_form = PublisherForm(request.values, obj=publisher)
|
publisher_form = PublisherForm(request.values, obj=publisher)
|
||||||
message=""
|
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')
|
||||||
|
|||||||
@@ -63,4 +63,4 @@ def rating(id):
|
|||||||
rating = Rating.query.get(id)
|
rating = Rating.query.get(id)
|
||||||
rating_form = RatingForm(request.values, obj=rating)
|
rating_form = RatingForm(request.values, obj=rating)
|
||||||
message=""
|
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')
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
{% extends "base.html" %} {% block main_content %}
|
{% extends "base.html" %} {% block main_content %}
|
||||||
<h3><center>Author</center></h3>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<right>
|
<h3 class="col-lg-12"><center>Author</center></h3>
|
||||||
|
<div class="row">
|
||||||
{% if message|length %}
|
{% if message|length %}
|
||||||
<div class="row alert alert-{{alert}}">
|
<div class="row alert alert-{{alert}}">
|
||||||
{{message}}
|
{{message}}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row">
|
<form class="form form-inline col-lg-12" action="" method="POST">
|
||||||
<form class="form form-inline col-xl-12" action="" method="POST">
|
{{ author_form.csrf_token }}
|
||||||
{{ wtf.form_field( author_form.id, form_type='inline' ) }}
|
{{ author_form.id }}
|
||||||
<div class="col-xl-12">
|
<div class="form-row col-lg-12">
|
||||||
{{ wtf.form_field( author_form.firstnames, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
|
{{ author_form.firstnames.label( class="col-lg-2" ) }}
|
||||||
</div>
|
{{ author_form.firstnames( class="form-control col-lg-2" ) }}
|
||||||
<div class="col-xl-12">
|
</div class="form-row">
|
||||||
{{ wtf.form_field( author_form.surname, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }}
|
<div class="form-row col-lg-12">
|
||||||
</div>
|
{{ author_form.surname.label( class="col-lg-2" ) }}
|
||||||
<div class="col-xl-12">
|
{{ author_form.surname( class="form-control col-lg-2" ) }}
|
||||||
<br></br>
|
</div class="form-row">
|
||||||
</div>
|
<div class="row col-lg-12">
|
||||||
{{ wtf.form_field( author_form.submit, horizontal_columns=('xl', 2, 2), class="btn btn-primary offset-xl-1 col-xl-2" )}}
|
<br>
|
||||||
{{ wtf.form_field( author_form.delete, horizontal_columns=('xl', 2, 2), class="btn btn-danger offset-xl-1 col-xl-2" )}}
|
</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>
|
</form>
|
||||||
</div class="row">
|
</div class="row">
|
||||||
</div class="container">
|
</div class="container">
|
||||||
|
|||||||
@@ -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')}}">Create new Owned Type</a>
|
||||||
<a class="dropdown-item" href="{{url_for('owneds')}}">Show Owned Types</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')}}">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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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 %}
|
|
||||||
@@ -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 %}
|
|
||||||
@@ -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 %}
|
|
||||||
@@ -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 %}
|
|
||||||
@@ -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 %}
|
|
||||||
Reference in New Issue
Block a user