diff --git a/author.py b/author.py index 732d8c3..b748029 100644 --- a/author.py +++ b/author.py @@ -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
, 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: diff --git a/condition.py b/condition.py index eaac9a6..b2bedca 100644 --- a/condition.py +++ b/condition.py @@ -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') diff --git a/covertype.py b/covertype.py index 871cb8b..9bb8ed5 100644 --- a/covertype.py +++ b/covertype.py @@ -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') diff --git a/genre.py b/genre.py index 7f59796..b16a325 100644 --- a/genre.py +++ b/genre.py @@ -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') diff --git a/owned.py b/owned.py index 870080d..809bb61 100644 --- a/owned.py +++ b/owned.py @@ -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' ) diff --git a/publisher.py b/publisher.py index b33e824..85452ab 100644 --- a/publisher.py +++ b/publisher.py @@ -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 , 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') diff --git a/rating.py b/rating.py index 4170197..5f161a3 100644 --- a/rating.py +++ b/rating.py @@ -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') diff --git a/templates/author.html b/templates/author.html index 94485e7..6c98873 100644 --- a/templates/author.html +++ b/templates/author.html @@ -1,26 +1,30 @@ {% extends "base.html" %} {% block main_content %} -

Author

- +

Author

+
{% if message|length %}
{{message}}
{% endif %} -
- - {{ wtf.form_field( author_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( author_form.firstnames, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
- {{ wtf.form_field( author_form.surname, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} + + {{ author_form.csrf_token }} + {{ author_form.id }} +
+ {{ author_form.firstnames.label( class="col-lg-2" ) }} + {{ author_form.firstnames( class="form-control col-lg-2" ) }} +
+
+ {{ author_form.surname.label( class="col-lg-2" ) }} + {{ author_form.surname( class="form-control col-lg-2" ) }} +
+
+
+
+
+ {{ author_form.delete( class="btn btn-outline-danger col-lg-2" )}} + {{ author_form.submit( class="btn btn-primary col-lg-2" )}} +
diff --git a/templates/base.html b/templates/base.html index 6b441b1..8e0e3c4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -54,7 +54,7 @@ Create new Owned Type Show Owned Types Create new Rating - Show Owned Ratings + Show Ratings
diff --git a/templates/condition.html b/templates/condition.html deleted file mode 100644 index 9fdc56a..0000000 --- a/templates/condition.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} {% block main_content %} -

Condition

-
- - {% if message|length %} -
- {{message}} -
- {% endif %} -
-
- {{ wtf.form_field( condition_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( condition_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} -
-
-
-{% endblock main_content %} diff --git a/templates/covertype.html b/templates/covertype.html deleted file mode 100644 index 16e0b8d..0000000 --- a/templates/covertype.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} {% block main_content %} -

Covertype

-
- - {% if message|length %} -
- {{message}} -
- {% endif %} -
-
- {{ wtf.form_field( covertype_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( covertype_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} -
-
-
-{% endblock main_content %} diff --git a/templates/genre.html b/templates/genre.html deleted file mode 100644 index 6345ffc..0000000 --- a/templates/genre.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} {% block main_content %} -

Genre

-
- - {% if message|length %} -
- {{message}} -
- {% endif %} -
-
- {{ wtf.form_field( genre_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( genre_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} -
-
-
-{% endblock main_content %} diff --git a/templates/publisher.html b/templates/id_name_form.html similarity index 100% rename from templates/publisher.html rename to templates/id_name_form.html diff --git a/templates/owned.html b/templates/owned.html deleted file mode 100644 index 86f0544..0000000 --- a/templates/owned.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} {% block main_content %} -

Owned

-
- - {% if message|length %} -
- {{message}} -
- {% endif %} -
-
- {{ wtf.form_field( owned_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( owned_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} -
-
-
-{% endblock main_content %} diff --git a/templates/rating.html b/templates/rating.html deleted file mode 100644 index 06fb106..0000000 --- a/templates/rating.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} {% block main_content %} -

Rating

-
- - {% if message|length %} -
- {{message}} -
- {% endif %} -
-
- {{ wtf.form_field( rating_form.id, form_type='inline' ) }} -
- {{ wtf.form_field( rating_form.name, form_type='horizontal', horizontal_columns=('xl', 2, 10), style="width:100%" ) }} -
-
-

-
- {{ 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" )}} -
-
-
-{% endblock main_content %}