Skip to content

Commit

Permalink
Added a view for "no category assigned"
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekaterina-Vititneva committed Sep 13, 2024
1 parent c9f569d commit fc423c5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
15 changes: 10 additions & 5 deletions project_2/commerce/auctions/templates/auctions/categories.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
<h2>Categories</h2>
<ul>
{% for category in categories %}
<li>
<a href="{% url 'category_listings' category.category %}">
{{ category.category }}
</a>
</li>
{% if category.category %} <!-- Check if category is not empty -->
<li>
<a href="{% url 'category_listings' category.category %}">
{{ category.category }}
</a>
</li>
{% endif %}
{% endfor %}
<li>
<a href="{% url 'no_category_listings' %}">No category assigned</a> <!-- Link to no category listings -->
</li>
</ul>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2>{{ category }}</h2>

<div class="listings-grid">
{% for listing in listings %}
<a class="listing-card-link link-offset-2 link-underline link-underline-opacity-0" href="{% url 'listing' listing.title %}">
<div class="card" style="width: 18rem;">
{% if listing.imageURL %}
<img src="{{ listing.imageURL }}" alt="listing image" height="200" class="listing-image">
{% else %}
<div class="placeholder-rectangle"></div>
{% endif %}
<div class="card-body">
<h5 class="card-title">{{ listing.title }}</h5>
<h6 class="card-subtitle mb-2 text-body">Price: {{ listing.bid }}€</h6>
<p class="card-text">{{ listing.description }}</p>
</div>
<div class="card-footer text-body-secondary">
<div>Created time: {{ listing.created_at }}</div>
</div>
</div>
</a>
{% empty %}
<p>No listings available without a category.</p> <!-- Message for no listings -->
{% endfor %}
</div>
{% endblock %}
1 change: 1 addition & 0 deletions project_2/commerce/auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
path("listing/<str:title>", views.listing, name="listing"),
path("categories", views.categories, name="categories"),
path("categories/<str:category>", 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"),
]
10 changes: 8 additions & 2 deletions project_2/commerce/auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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"
})

0 comments on commit fc423c5

Please sign in to comment.