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 :)
This commit is contained in:
@@ -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/<id> -> 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')
|
||||
|
||||
@@ -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/<id> -> 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')
|
||||
|
||||
5
genre.py
5
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/<id> -> 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')
|
||||
|
||||
4
owned.py
4
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/<id> -> 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' )
|
||||
|
||||
@@ -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/<id> -> 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')
|
||||
|
||||
@@ -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/<id> -> 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')
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<a class="dropdown-item" href="{{url_for('covertypes')}}">Create new Covertype</a>
|
||||
<a class="dropdown-item" href="{{url_for('covertypes')}}">Show Covertypes</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 Ownership Types</a>
|
||||
<a class="dropdown-item" href="{{url_for('ratings')}}">Create new Rating</a>
|
||||
<a class="dropdown-item" href="{{url_for('ratings')}}">Show Ratings</a>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Conditions</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for condition in conditions %}
|
||||
<tr><td data-sort="{{condition.id}}"><a href="{{url_for('condition', id=condition.id )}}">{{condition.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock main_content %}
|
||||
@@ -1,15 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Covertypes</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for covertype in covertypes %}
|
||||
<tr><td data-sort="{{covertype.id}}"><a href="{{url_for('covertype', id=covertype.id )}}">{{covertype.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock main_content %}
|
||||
@@ -1,15 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Owned List</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for owned in owneds %}
|
||||
<tr><td data-sort="{{owned.id}}"><a href="{{url_for('owned', id=owned.id )}}">{{owned.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock main_content %}
|
||||
@@ -1,15 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Publishers</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for publisher in publishers %}
|
||||
<tr><td data-sort="{{publisher.name}}"><a href="{{url_for('publisher', id=publisher.id )}}">{{publisher.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock main_content %}
|
||||
@@ -1,15 +0,0 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Ratings</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for rating in ratings %}
|
||||
<tr><td data-sort="{{rating.id}}"><a href="{{url_for('rating', id=rating.id )}}">{{rating.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock main_content %}
|
||||
@@ -1,14 +1,14 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block main_content %}
|
||||
<h3>Genres</h3>
|
||||
<h3>{{page_title}}</h3>
|
||||
<table id="book_table" class="table table-striped table-sm" data-toolbar="#toolbar" data-search="true">
|
||||
<thead>
|
||||
<tr class="thead-light"><th>Name</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for genre in genres %}
|
||||
<tr><td><a href="{{url_for('genre', id=genre.id )}}">{{genre.name}}</a></td></tr>
|
||||
{% for obj in objects %}
|
||||
<tr><td data-sort="{{obj.id}}"><a href="{{url_for(url_base, id=obj.id )}}">{{obj.name}}</a></td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user