Skip to content

Commit

Permalink
fix: fix close auction view
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasFASouza committed Feb 3, 2023
1 parent 3ab8f81 commit 857643e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
31 changes: 19 additions & 12 deletions auctions/templates/auctions/listing.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ <h2>Place bid</h2>
{{ bid_form }}
<input type="submit" name="bid">
</form>
{% endif %}

<h2>Comments</h2>
<form action="{% url 'listing' listing.id %}" method="post">
{% csrf_token %}
{{ comment_form }}
<input type="submit" name="comment">
</form>
<ul>
{% for comment in comments %}
<li>{{ comment }}</li>
{% endfor %}
</ul>
<h2>Comments</h2>
<form action="{% url 'listing' listing.id %}" method="post">
{% csrf_token %}
{{ comment_form }}
<input type="submit" name="comment">
</form>
<ul>
{% for comment in comments %}
<li>{{ comment }}</li>
{% endfor %}
</ul>
{% else %}
<h2>Comments</h2>
<ul>
{% for comment in comments %}
<li>{{ comment }}</li>
{% endfor %}
</ul>
{% endif %}

<h2>Bidings</h2>
<ul>
Expand Down
11 changes: 7 additions & 4 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ def add_listing(request):


@login_required
def close_auction(listing_id):
def close_auction(request, listing_id):
auction = Listing.objects.get(id=listing_id)
auction.active = False
auction.save()
user = request.user

return HttpResponseRedirect(reverse("index"))
if user.is_authenticated and auction.seller == user:
auction.active = False
auction.save()

return HttpResponseRedirect(reverse("listing", kwargs={'listing_id': listing_id}))

0 comments on commit 857643e

Please sign in to comment.