From fc423c55d2e163e82da7397e02f1769ac6fb2482 Mon Sep 17 00:00:00 2001 From: Ekaterina Vititneva Date: Fri, 13 Sep 2024 22:11:07 +0200 Subject: [PATCH] Added a view for "no category assigned" --- .../templates/auctions/categories.html | 15 ++++++---- .../auctions/no_category_listings.html | 29 +++++++++++++++++++ project_2/commerce/auctions/urls.py | 1 + project_2/commerce/auctions/views.py | 10 +++++-- 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 project_2/commerce/auctions/templates/auctions/no_category_listings.html diff --git a/project_2/commerce/auctions/templates/auctions/categories.html b/project_2/commerce/auctions/templates/auctions/categories.html index 58e61c9..b4d1c62 100644 --- a/project_2/commerce/auctions/templates/auctions/categories.html +++ b/project_2/commerce/auctions/templates/auctions/categories.html @@ -8,11 +8,16 @@

Categories

{% endblock %} diff --git a/project_2/commerce/auctions/templates/auctions/no_category_listings.html b/project_2/commerce/auctions/templates/auctions/no_category_listings.html new file mode 100644 index 0000000..7ca793c --- /dev/null +++ b/project_2/commerce/auctions/templates/auctions/no_category_listings.html @@ -0,0 +1,29 @@ +{% extends "auctions/layout.html" %} + +{% block body %} +

{{ category }}

+ +
+ {% for listing in listings %} + +
+ {% if listing.imageURL %} + listing image + {% else %} +
+ {% endif %} +
+
{{ listing.title }}
+
Price: {{ listing.bid }}€
+

{{ listing.description }}

+
+ +
+
+ {% empty %} +

No listings available without a category.

+ {% endfor %} +
+{% endblock %} diff --git a/project_2/commerce/auctions/urls.py b/project_2/commerce/auctions/urls.py index 18c1673..64e63c0 100644 --- a/project_2/commerce/auctions/urls.py +++ b/project_2/commerce/auctions/urls.py @@ -11,5 +11,6 @@ path("listing/", views.listing, name="listing"), path("categories", views.categories, name="categories"), path("categories/", views.category_listings, name="category_listings"), + path("categories/no-category", views.no_category_listings, name="no_category_listings"), # New URL pattern path("watchlist", views.watchlist, name="watchlist"), ] diff --git a/project_2/commerce/auctions/views.py b/project_2/commerce/auctions/views.py index 6843bfc..b89ad99 100644 --- a/project_2/commerce/auctions/views.py +++ b/project_2/commerce/auctions/views.py @@ -69,7 +69,6 @@ def register(request): else: return render(request, "auctions/register.html") -@login_required def create_listing(request): if request.method == "POST": form = ListingForm(request.POST) @@ -198,4 +197,11 @@ def add_comment(request, title): else: messages.error(request, "There was a problem with your comment. Please try again.") - return redirect('listing', title=listing.title) \ No newline at end of file + return redirect('listing', title=listing.title) + +def no_category_listings(request): + listings = Listing.objects.filter(category='') # Fetch listings with no category + return render(request, "auctions/no_category_listings.html", { + "listings": listings, + "category": "No Category Assigned" + }) \ No newline at end of file