diff --git a/store/routes.py b/store/routes.py index a8f3b35df73c1b3d084ffb3afac10adc1d7d27ab..87e95fc60e60aeee726638d2b946bfb22f84b031 100644 --- a/store/routes.py +++ b/store/routes.py @@ -96,26 +96,25 @@ def items(): @app.route("/item_sets") def item_sets(): items = get_item_sets() - return render_template("item_sets.html", title="Item Sets", items=items) + return render_template("items.html", title="Item Sets", items=items) -@app.route("/item_set_page/<int:item_id>") +@app.route("/item_page/item_<int:item_id>") +def item_page(item_id): + item = get_item_by_id(item_id) + if not item: + return "Item not found", 404 + + return render_template("item_page.html", item=item) + + +@app.route("/item_set_page/item_set_<int:item_id>") def item_set_page(item_id): item = get_item_set_by_id(item_id) if not item: return "Item set not found", 404 - item_price = item.price - item_description = item.description - print(item.items) - contained_items = item.items - return render_template( - "item_set_page.html", - item_price=item_price, - item_description=item_description, - item_id=item_id, - contained_items=contained_items, - ) + return render_template("item_page.html", item=item) @app.route("/register", methods=["POST", "GET"]) @@ -597,21 +596,6 @@ def remove_item_basket(): # Calling this remove_item shadows the utility functi return redirect(url_for("basket")) -@app.route("/item_page/<int:item_id>") -def item_page(item_id): - item = get_item_by_id(item_id) - if not item: - return "Item not found", 404 - item_price = item.price - item_description = item.description - return render_template( - "item_page.html", - item_price=item_price, - item_description=item_description, - item_id=item_id, - ) - - @app.route("/addAdress", methods=["GET", "POST"]) @login_required def addAdress(): diff --git a/store/templates/item_page.html b/store/templates/item_page.html index 3f4434c44257d019a7b5c24a018913cdd65df523..0eb54cac981bf2f2406daaa404e6b39eb3e33f00 100644 --- a/store/templates/item_page.html +++ b/store/templates/item_page.html @@ -5,14 +5,37 @@ <div> <img src='..\static\image_placeholder.png' alt="Image Placeholder" width="200" height="170"> <br /> - Item price: £{{item_price}} + Item price: £{{item.price}} <br /> - Item description: {{item_description}} + Item description: {{item.description}} <br /> - <form method="POST" action="{{url_for ('add_to_basket') }}"> - <input type="hidden" name="item_id" value="{{ item_id }}"> + <form method="POST" action="{{ url_for('add_to_basket_set') if item.items else url_for('add_to_basket') }}"> + <input type="hidden" name="item_id" value="{{ item.id }}"> <input class="button" type="submit" value="Add to basket"> </form> </div> - +<div> + {% if item.items %} + <h1>Items contained in set: </h1> + <table> + <thead> + <tr> + <th>Item description</th> + <th>Item price</th> + <th></th> + </tr> + </thead> + <tbody> + {% for item in item.items %} + <tr> + <td>{{ item['description'] }}</td> + <td>£{{ item['price'] }}</td> + </tr> + {% endfor %} + </tbody> + </table> + {% else %} + <p>Item set is empty.</p> + {% endif %} +</div> {% endblock %} \ No newline at end of file diff --git a/store/templates/item_set_page.html b/store/templates/item_set_page.html deleted file mode 100644 index d2b0b0136412c49e5838ce3d769bfe1306b28aee..0000000000000000000000000000000000000000 --- a/store/templates/item_set_page.html +++ /dev/null @@ -1,56 +0,0 @@ -{%extends 'base.html' %} - -{% block content %} -{% block title %} Item Set Page | Antiques Online {% endblock %} -<style> - table { - margin-left: auto; - margin-right: auto; - font: inherit; - } - - h1 { - font-size: 25px; - font: inherit; - font-weight: bold; - } -</style> -<div> - <img src='..\static\image_placeholder.png' alt="Image Placeholder" width="200" height="170"> - <br> - Item price: £{{item_price}} - <br> - Item description: {{item_description}} - <br> - <form method="POST" action="{{url_for ('add_to_basket_set') }}"> - <input type="hidden" name="item_id" value="{{ item_id }}"> - <input class="button" type="submit" value="Add to basket"> - </form> - <br> -</div> -<div> - {% if contained_items %} - <h1>Items contained in set: </h1> - <table> - <thead> - <tr> - <th>Item description</th> - <th>Item price</th> - <th></th> - </tr> - </thead> - <tbody> - {% for item in contained_items %} - <tr> - <td>{{ item['description'] }}</td> - <td>£{{ item['price'] }}</td> - </tr> - {% endfor %} - </tbody> - </table> - {% else %} - <p>Item set is empty.</p> - {% endif %} -</div> - -{% endblock %} \ No newline at end of file diff --git a/store/templates/item_sets.html b/store/templates/item_sets.html deleted file mode 100644 index 27bae077dd6b90b93e0b67dac8fd13e4ec478f16..0000000000000000000000000000000000000000 --- a/store/templates/item_sets.html +++ /dev/null @@ -1,55 +0,0 @@ -{%extends 'base.html' %} - -{% block title %} Item Sets | Antiques Online {% endblock %} - -{% block content %} - -<style> - .grid { - display: grid; - grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); - grid-gap: 10px; - grid-auto-rows: minmax(100px, auto); - } - - .grid-item { - grid-row: span 1; - grid-column: span 1; - padding: 10px; - } - - .grid-item img { - max-width: 100%; - height: auto; - } - - .grid-item h2 { - margin: 10px 0; - font-size: 18px; - - } - - .grid-item p { - margin: 5px 0; - font-size: 14px; - } -</style> - -<div class="grid"> - {% if items %} - {% for item in items %} - <div class="grid-item"> - - <img src="static\image_placeholder.png" alt="{{ item.description }}"> - <h2>{{ item.description }}</h2> - <p>£{{ item.price }}</p> - <a href="{{url_for('item_set_page', item_id = item.id)}}">View - Details</a> - - </div> - {% endfor %} - {% else %} - <p>No items available</p> - {% endif %} -</div> -{% endblock %} \ No newline at end of file diff --git a/store/templates/items.html b/store/templates/items.html index a60fb2bdd143dd2d6a741ba5c62d86928414a079..de28bb762c783667d79e2bdae86ff8c27c53b24f 100644 --- a/store/templates/items.html +++ b/store/templates/items.html @@ -12,7 +12,9 @@ style="width: 200px; height: 200px;"> <!-- Set image size to ensure content is always fitting. --> <h2>{{ item.description }}</h2> <p>£{{ item.price }}</p> - <a href="{{url_for('item_page', item_id = item.id)}}">View Details</a> + <a + href="{{url_for('item_set_page', item_id = item.id) if item.items else url_for('item_page', item_id = item.id)}}">View + Details</a> </div> </div> {% endfor %}