Skip to content

Commit

Permalink
feat: add close option button
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasFASouza committed Feb 1, 2023
1 parent 27e7b40 commit f071514
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
4 changes: 1 addition & 3 deletions auctions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class Meta:
class NewBid(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.item = kwargs.pop('item')

if kwargs['buyer']:
self.buyer = kwargs.pop('buyer')
self.buyer = kwargs.pop('buyer')

super(NewBid, self).__init__(*args, **kwargs)

Expand Down
18 changes: 18 additions & 0 deletions auctions/migrations/0004_listing_isactive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-02-01 20:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('auctions', '0003_alter_biding_options'),
]

operations = [
migrations.AddField(
model_name='listing',
name='isActive',
field=models.BooleanField(default=True),
),
]
1 change: 1 addition & 0 deletions auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Listing(models.Model):
category = models.CharField(choices=CATEGORIES_CHOICES, max_length=24, blank=True)
seller = models.ForeignKey(User, on_delete=models.CASCADE, related_name="listings")
price = models.DecimalField(max_digits=6, decimal_places=2, blank=True)
isActive = models.BooleanField(default=True)

def __str__(self):
return f"{self.title}: {self.description}"
Expand Down
4 changes: 4 additions & 0 deletions auctions/static/auctions/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
body {
padding: 10px;
}

.listing {
background-color: red;
}
14 changes: 9 additions & 5 deletions auctions/templates/auctions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ <h2>Active Listings</h2>

<ul>
{% for listing in listings %}
<li>
<img src="{{ listing.photo_url }}" width="128">
<a href="{% url 'listing' listing.id %}">{{ listing.title }}:</a>
{{ listing.description }}, by {{ listing.seller }} - $ {{ listing.price }}
</li>
{% if listing.isActive %}
<li>
<img src="{{ listing.photo_url }}" width="128">
<div>
<a href="{% url 'listing' listing.id %}">{{ listing.title }}:</a>
{{ listing.description }}, by {{ listing.seller }} - $ {{ listing.price }}
</div>
</li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
3 changes: 1 addition & 2 deletions auctions/templates/auctions/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<link href="{% static 'auctions/styles.css' %}" rel="stylesheet">
</head>
<body>
<h1>Auctions</h1>
<div>
{% if user.is_authenticated %}
Signed in as <strong>{{ user.username }}</strong>.
Expand All @@ -25,7 +24,7 @@ <h1>Auctions</h1>
<a class="nav-link" href="{% url 'logout' %}">Log Out</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add' %}">Add new listing</a>
<a class="nav-link" href="{% url 'add' %}">Create listing</a>
</li>
{% else %}
<li class="nav-item">
Expand Down
4 changes: 4 additions & 0 deletions auctions/templates/auctions/listing.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends "auctions/layout.html" %}

{% block body %}
{% if user.is_authenticated and listing.seller == user %}
<a>Close auction</a>
{% endif %}

<h2>{{ listing.title }}</h2>
<img src="{{ listing.photo_url }}" width="256">
<ul>
Expand Down
2 changes: 1 addition & 1 deletion auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def listing(request, listing_id):
return render(request, "auctions/listing.html", {
"listing": auction,
"bidings": bidings,
"form": forms.NewBid(item=auction)
"form": forms.NewBid(item=auction, buyer=request.user),
})


Expand Down

0 comments on commit f071514

Please sign in to comment.