From 043eb5cc7386e97b7666e6e29d51ed6e3918f0b2 Mon Sep 17 00:00:00 2001 From: Arno Wunderlich <arno.a.wunderlich@student.jyu.fi> Date: Thu, 16 Feb 2023 13:19:27 +0000 Subject: [PATCH] view current bid instead of starting price --- src/tjts5901/templates/listBid.html | 2 +- src/tjts5901/templates/view.html | 4 ++-- src/tjts5901/views.py | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tjts5901/templates/listBid.html b/src/tjts5901/templates/listBid.html index bfb32214..38c1d1e2 100644 --- a/src/tjts5901/templates/listBid.html +++ b/src/tjts5901/templates/listBid.html @@ -20,7 +20,7 @@ <small>{{ item.created_at }}</small> </div> <p class="mb-1">{{ item.description }}</p> - <small>{{ item.starting_bid }}</small> + <small>{{ item.current_price}}</small> <a href="{{ url_for('views.page_bid', id=item.id) }}"><button class="btn btn-primary">Bid</button></a> </div> <div class="row justify-content-md-center"> diff --git a/src/tjts5901/templates/view.html b/src/tjts5901/templates/view.html index 820d6cd2..0e4ab599 100644 --- a/src/tjts5901/templates/view.html +++ b/src/tjts5901/templates/view.html @@ -18,9 +18,9 @@ <h5 class="mb-1">{{ item.title }}</h5> <p class="mb-1">{{ item.description }}</p> <p class="mb-1">Created : {{ item.created_at }}</p> - <p class="mb-1">Current bid : {{ item.starting_bid }}</p><br/> + <p class="mb-1">Current bid : {{ current_price }}</p><br/> <form method="POST" action="{{ url_for('views.bid', id=item.id)}}" class="row" enctype="multipart/form-data"> - <input class="col-md-9" id="bid" name ="bid" type="number" min="{{ item.starting_bid }}" placeholder="write your bid"> + <input class="col-md-9" id="bid" name ="bid" type="number" min="{{ min_bid }}" placeholder="write your bid"> <button for="bid" type="submit" class="btn btn-primary col-md-3">Validate</button> </form> </div> diff --git a/src/tjts5901/views.py b/src/tjts5901/views.py index 2350c42c..3a0cd6ee 100644 --- a/src/tjts5901/views.py +++ b/src/tjts5901/views.py @@ -168,6 +168,7 @@ def list_bid(): for item in items: item.image_base64 = base64.b64encode(item.image.read()).decode('utf-8') + item.current_price = get_item_price(item) - MIN_BID_INCREMENT html = render_template("listBid.html", items=items) return html @@ -207,7 +208,7 @@ def bid(id): ) bid.save() except Exception as exc: - flash(("Error placing bid: %(exc)s", exc=exc)) + flash(_("Error placing bid: %(exc)s", exc=exc)) else: flash(("Bid placed successfully!")) @@ -319,11 +320,16 @@ def page_bid(id): item = Item.objects.get_or_404(id=id) + # Set the current price for the bid according to current highest bid + winning_bid = get_winning_bid(item) + min_bid = get_item_price(item) + current_price = min_bid - MIN_BID_INCREMENT + item.image_base64 = base64.b64encode(item.image.read()).decode('utf-8') # Dark pattern to show enticing message to user #if item.closes_at < datetime.utcnow() + timedelta(hours=1): # flash("This item is closing soon! Act now! Now! Now!") - return render_template('view.html', item=item) + return render_template('view.html', item=item, current_price=current_price, min_bid=min_bid) -- GitLab