Skip to content
Snippets Groups Projects
Commit fa4465ce authored by arwunder's avatar arwunder
Browse files

Merge branch 'small-fixes-2002' into 'main'

Small fixes 2002

See merge request !63
parents 26cb9140 5ebaf276
No related branches found
No related tags found
1 merge request!63Small fixes 2002
Pipeline #16030 passed
......@@ -18,7 +18,7 @@
<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 : {{ current_price }}</p><br/>
<p class="mb-1">Current bid : {{ current_price|localcurrency }}</p><br/>
<form method="POST" action="{{ url_for('views.bid', id=item.id)}}" class="row" enctype="multipart/form-data">
<input class="col-md-6" 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>
......
......@@ -84,20 +84,14 @@ def get_item_price(item: Item) -> int:
def check_auction_ends():
"""
Check if all previously not processed auctions have ended now
Get all closed items, check if they belong to the current user and inform about
the ending of the auction.
Then process all bids on these items and check if they won
Get all closed items, process all bids on these items and check if they won
Then check if current_user needs to be informed
"""
items = Item.objects.filter(Q(closes_at=datetime.utcnow()) & Q(closed_processed=False)) \
items = Item.objects.filter(Q(closes_at__lte=datetime.utcnow()) & Q(closed_processed=False)) \
.order_by('-closes_at')
for item in items:
item.update(closed_processed = True)
message = None
if item.seller == current_user:
message = "The auction of your item \'{}\' has ended. ".format(item.title)
item.update(seller_informed_about_result = True)
# Get (potential) bids for the item and process them
bids = Bid.objects(item=item).order_by('-amount')
......@@ -111,19 +105,24 @@ def check_auction_ends():
bid.update(winning_bid = False)
bid.update(auction_end_processed = True)
# Inform seller if this is current user
if item.seller == current_user:
message += "Congrats! It was sold for {}.".format(bids[0].amount)
# Inform current user if no one bid on the item
else:
if item.seller == current_user:
message += "No one bid on your item. Try again!"
# Inform current user about results of his auctions
items_closed = Item.objects.filter(Q(closed_processed=True) & Q(seller_informed_about_result=False) \
& Q(seller=current_user))
message = None
for item in items_closed:
# Get (potential) bids for the item and process them
message = "The auction of your item \'{}\' has ended. ".format(item.title)
bids = Bid.objects(item=item).order_by('-amount')
if len(bids) >= 1:
message += "Congrats! It was sold for {}.".format(bids[0].amount)
else:
message += "No one bid on your item. Try again!"
item.update(seller_informed_about_result = True)
#Display message if not None
if message is not None:
flash((message))
def check_bids_ended():
"""
......@@ -137,7 +136,7 @@ def check_bids_ended():
if bid.winning_bid == True:
flash(("Congrats! You won the auction of '{}' with your bid over {}.".format(bid.item.title, bid.amount)))
else:
flash(("Pity! You were not successfull with the auction of '{}' with your bid over {}.".format(bid.item.title, bid.amount)))
flash(("Pity! You were not successfull with the auction of '{}' with your bid over {}.".format(bid.item.title, bid.amount)))
bid.update(bidder_informed = True)
......@@ -400,6 +399,7 @@ def page_bid(id):
item = Item.objects.get_or_404(id=id)
min_bid = get_item_price(item) + MIN_BID_INCREMENT
current_price = get_item_price(item)
local_currency = get_preferred_currency()
local_min_bid = convert_currency(min_bid, local_currency)
......@@ -409,5 +409,5 @@ def page_bid(id):
return render_template('view.html',
item=item, min_bid=min_bid,
local_min_bid=local_min_bid,
current_price=current_price,
local_currency=local_currency)
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