Skip to content
Snippets Groups Projects
Commit 19f8c59f authored by Arno Wunderlich's avatar Arno Wunderlich
Browse files

bidding backend frontend integration

parent 697dcaf7
No related branches found
No related tags found
1 merge request!41Bidding frontend backend integration fixes
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<p class="mb-1">Created : {{ item.created_at }}</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 : {{ item.starting_bid }}</p><br/>
<form method="POST" action="{{ url_for('views.bid', id=item.id)}}" class="row" enctype="multipart/form-data"> <form method="POST" action="{{ url_for('views.bid', id=item.id)}}" class="row" enctype="multipart/form-data">
<input class="col-md-9" id="bid" type="number" min="{{ item.starting_bid }}" placeholder="write your bid"> <input class="col-md-9" id="bid" name ="bid" type="number" min="{{ item.starting_bid }}" placeholder="write your bid">
<button for="bid" type="submit" class="btn btn-primary col-md-3">Validate</button> <button for="bid" type="submit" class="btn btn-primary col-md-3">Validate</button>
</form> </form>
</div> </div>
......
...@@ -172,42 +172,24 @@ def list_bid(): ...@@ -172,42 +172,24 @@ def list_bid():
html = render_template("listBid.html", items=items) html = render_template("listBid.html", items=items)
return html return html
@bp.route('/item/<id>')
def view(id):
"""
Item view page.
Displays the item details, and a form to place a bid.
"""
item = Item.objects.get_or_404(id=id)
# Set the minumum price for the bid form from the current winning bid @bp.route("item/<id>/bid", methods=('POST',))
winning_bid = get_winning_bid(item)
min_bid = get_item_price(item)
if item.closes_at < datetime.utcnow() and winning_bid.bidder == current_user:
flash(("Congratulations! You won the auction!"))
elif item.closes_at < datetime.utcnow() + timedelta(hours=1):
# Dark pattern to show enticing message to user
flash(("This item is closing soon! Act now! Now! Now!"))
return render_template("item.html", item=item)
@bp.route("item/<id>/bid")
@login_required @login_required
def bid(id): def bid(id):
""" """
method that saves bid on object method that saves bid on object
If the bid is valid, create a new bid and redirect to the item view page.
Otherwise, display an error message and redirect back to the item view page.
""" """
# frontend not implemented yet, therefore not active # frontend not implemented yet, therefore not active
item = Item.objects.get_or_404(id=id) item = Item.objects.get_or_404(id=id)
min_amount = item.starting_bid min_amount = item.starting_bid
amount = request.form['amount'] amount = int(request.form.get('bid'))
if amount < min_amount: if amount <= min_amount:
flash(("Bid must be at least %(min_amount)s", min_amount)) flash(("Bid must be at least %(min_amount)s", min_amount))
return redirect(url_for('views.list_bid')) return redirect(url_for('views.list_bid'))
...@@ -225,7 +207,7 @@ def bid(id): ...@@ -225,7 +207,7 @@ def bid(id):
) )
bid.save() bid.save()
except Exception as exc: except Exception as exc:
flash(_("Error placing bid: %(exc)s", exc=exc)) flash(("Error placing bid: %(exc)s", exc=exc))
else: else:
flash(("Bid placed successfully!")) flash(("Bid placed successfully!"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment