From 296ef4c1f73fc29606f650d082c5b06a4c598003 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Wed, 18 Nov 2020 12:30:23 +1100 Subject: [PATCH] renamed id_name_form to edit_id_name, then made show_id_name and used it for all appropriate classes. Shaved about 150 LOC / removed 5 x duplication of code :) --- condition.py | 4 ++-- covertype.py | 4 ++-- genre.py | 5 +++-- owned.py | 4 ++-- publisher.py | 4 ++-- rating.py | 4 ++-- templates/base.html | 2 +- templates/conditions.html | 15 --------------- templates/covertypes.html | 15 --------------- .../{id_name_form.html => edit_id_name.html} | 0 templates/owneds.html | 15 --------------- templates/publishers.html | 15 --------------- templates/ratings.html | 15 --------------- templates/{genres.html => show_id_name.html} | 6 +++--- 14 files changed, 17 insertions(+), 91 deletions(-) delete mode 100644 templates/conditions.html delete mode 100644 templates/covertypes.html rename templates/{id_name_form.html => edit_id_name.html} (100%) delete mode 100644 templates/owneds.html delete mode 100644 templates/publishers.html delete mode 100644 templates/ratings.html rename templates/{genres.html => show_id_name.html} (65%) diff --git a/condition.py b/condition.py index c3e3929..5db57e3 100644 --- a/condition.py +++ b/condition.py @@ -37,7 +37,7 @@ class ConditionForm(FlaskForm): @app.route("/conditions", methods=["GET"]) def conditions(): conditions = Condition.query.order_by('id').all() - return render_template("conditions.html", conditions=conditions) + return render_template("show_id_name.html", objects=conditions, page_title='Show All Conditions', url_base='condition') ################################################################################ # /condition/ -> GET/POST(save or delete) -> shows/edits/delets a single @@ -64,4 +64,4 @@ def condition(id): condition = Condition.query.get(id) condition_form = ConditionForm(request.values, obj=condition) message="" - return render_template("id_name_form.html", condition=condition, alert=alert, message=message, form=condition_form, page_title='Edit Condition') + return render_template("edit_id_name.html", condition=condition, alert=alert, message=message, form=condition_form, page_title='Edit Condition') diff --git a/covertype.py b/covertype.py index 84ed184..2829028 100644 --- a/covertype.py +++ b/covertype.py @@ -37,7 +37,7 @@ class CovertypeForm(FlaskForm): @app.route("/covertypes", methods=["GET"]) def covertypes(): covertypes = Covertype.query.order_by('id').all() - return render_template("covertypes.html", covertypes=covertypes) + return render_template( "show_id_name.html", objects=covertypes, page_title='Show All Covertypes', url_base='covertype') ################################################################################ # /covertype/ -> GET/POST(save or delete) -> shows/edits/delets a single @@ -64,4 +64,4 @@ def covertype(id): covertype = Covertype.query.get(id) covertype_form = CovertypeForm(request.values, obj=covertype) message="" - return render_template("id_name_form.html", covertype=covertype, alert=alert, message=message, form=covertype_form, page_title='Edit Covertype') + return render_template("edit_id_name.html", covertype=covertype, alert=alert, message=message, form=covertype_form, page_title='Edit Covertype') diff --git a/genre.py b/genre.py index f3ab9b6..0f0a6d0 100644 --- a/genre.py +++ b/genre.py @@ -36,7 +36,8 @@ class GenreForm(FlaskForm): @app.route("/genres", methods=["GET"]) def genres(): genres = Genre.query.all() - return render_template("genres.html", genres=genres) + return render_template("show_id_name.html", objects=genres, page_title='Show All Genres', url_base='genre') + ################################################################################ # /genre/ -> GET/POST(save or delete) -> shows/edits/delets a single genre @@ -62,4 +63,4 @@ def genre(id): genre = Genre.query.get(id) genre_form = GenreForm(request.values, obj=genre) message="" - return render_template("id_name_form.html", genre=genre, alert=alert, message=message, form=genre_form, page_title='Edit Genre') + return render_template("edit_id_name.html", genre=genre, alert=alert, message=message, form=genre_form, page_title='Edit Genre') diff --git a/owned.py b/owned.py index ebc902b..bace3c3 100644 --- a/owned.py +++ b/owned.py @@ -37,7 +37,7 @@ class OwnedForm(FlaskForm): @app.route("/owneds", methods=["GET"]) def owneds(): owneds = Owned.query.order_by('id').all() - return render_template("owneds.html", owneds=owneds) + return render_template("show_id_name.html", objects=owneds, page_title='Show All Ownership types', url_base='owned') ################################################################################ # /owned/ -> GET/POST(save or delete) -> shows/edits/delets a single @@ -64,4 +64,4 @@ def owned(id): owned = Owned.query.get(id) owned_form = OwnedForm(request.values, obj=owned) message="" - return render_template("id_name_form.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Edit Owned Type' ) + return render_template("edit_id_name.html", owned=owned, alert=alert, message=message, form=owned_form, page_title='Edit Owned Type' ) diff --git a/publisher.py b/publisher.py index 816a3bc..01cb53d 100644 --- a/publisher.py +++ b/publisher.py @@ -36,7 +36,7 @@ class PublisherForm(FlaskForm): @app.route("/publishers", methods=["GET"]) def publishers(): publishers = Publisher.query.all() - return render_template("publishers.html", publishers=publishers) + return render_template("show_id_name.html", objects=publishers, page_title='Show All Publishers', url_base='publisher') ################################################################################ # /publisher/ -> GET/POST(save or delete) -> shows/edits/delets a single publisher @@ -62,4 +62,4 @@ def publisher(id): publisher = Publisher.query.get(id) publisher_form = PublisherForm(request.values, obj=publisher) message="" - return render_template("id_name_form.html", publisher=publisher, alert=alert, message=message, form=publisher_form, page_title='Edit Publisher') + return render_template("edit_id_name.html", publisher=publisher, alert=alert, message=message, form=publisher_form, page_title='Edit Publisher') diff --git a/rating.py b/rating.py index 5f161a3..37940b7 100644 --- a/rating.py +++ b/rating.py @@ -36,7 +36,7 @@ class RatingForm(Form): @app.route("/ratings", methods=["GET"]) def ratings(): ratings = Rating.query.order_by('id').all() - return render_template("ratings.html", ratings=ratings) + return render_template("show_id_name.html", objects=ratings, page_title='Show All Ratings', url_base='rating') ################################################################################ # /rating/ -> GET/POST(save or delete) -> shows/edits/delets a single @@ -63,4 +63,4 @@ def rating(id): rating = Rating.query.get(id) rating_form = RatingForm(request.values, obj=rating) message="" - return render_template("id_name_form.html", rating=rating, alert=alert, message=message, form=rating_form, page_title='Edit Rating') + return render_template("edit_id_name.html", rating=rating, alert=alert, message=message, form=rating_form, page_title='Edit Rating') diff --git a/templates/base.html b/templates/base.html index 8e0e3c4..bacc707 100644 --- a/templates/base.html +++ b/templates/base.html @@ -52,7 +52,7 @@ Create new Covertype Show Covertypes Create new Owned Type - Show Owned Types + Show Ownership Types Create new Rating Show Ratings diff --git a/templates/conditions.html b/templates/conditions.html deleted file mode 100644 index d295e8b..0000000 --- a/templates/conditions.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block main_content %} -

Conditions

- - - - - - {% for condition in conditions %} - - {% endfor %} - -
Name
{{condition.name}}
-{% endblock main_content %} diff --git a/templates/covertypes.html b/templates/covertypes.html deleted file mode 100644 index 527287f..0000000 --- a/templates/covertypes.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block main_content %} -

Covertypes

- - - - - - {% for covertype in covertypes %} - - {% endfor %} - -
Name
{{covertype.name}}
-{% endblock main_content %} diff --git a/templates/id_name_form.html b/templates/edit_id_name.html similarity index 100% rename from templates/id_name_form.html rename to templates/edit_id_name.html diff --git a/templates/owneds.html b/templates/owneds.html deleted file mode 100644 index 4e61e30..0000000 --- a/templates/owneds.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block main_content %} -

Owned List

- - - - - - {% for owned in owneds %} - - {% endfor %} - -
Name
{{owned.name}}
-{% endblock main_content %} diff --git a/templates/publishers.html b/templates/publishers.html deleted file mode 100644 index 2c890af..0000000 --- a/templates/publishers.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block main_content %} -

Publishers

- - - - - - {% for publisher in publishers %} - - {% endfor %} - -
Name
{{publisher.name}}
-{% endblock main_content %} diff --git a/templates/ratings.html b/templates/ratings.html deleted file mode 100644 index 871a7c2..0000000 --- a/templates/ratings.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "base.html" %} - -{% block main_content %} -

Ratings

- - - - - - {% for rating in ratings %} - - {% endfor %} - -
Name
{{rating.name}}
-{% endblock main_content %} diff --git a/templates/genres.html b/templates/show_id_name.html similarity index 65% rename from templates/genres.html rename to templates/show_id_name.html index 2ae1808..24acad2 100644 --- a/templates/genres.html +++ b/templates/show_id_name.html @@ -1,14 +1,14 @@ {% extends "base.html" %} {% block main_content %} -

Genres

+

{{page_title}}

- {% for genre in genres %} - + {% for obj in objects %} + {% endfor %}
Name
{{genre.name}}
{{obj.name}}