Skip to content

Commit bcebe38

Browse files
author
=
committed
fix #323
1 parent bdec3f3 commit bcebe38

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

auctions/models.py

+26
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,32 @@ def find_user(self, name="", email="", exclude_pk=None):
760760
return name_search
761761
return None
762762

763+
@property
764+
def estimate_end(self):
765+
try:
766+
if self.is_online:
767+
return None
768+
expected_sell_percent = 95
769+
lots_to_use_for_estimate = 10
770+
percent_complete = self.total_unsold_lots / self.total_lots
771+
if percent_complete > expected_sell_percent:
772+
return None
773+
lots = self.lots_qs.exclude(date_end__isnull=True).order_by("-date_end")[:lots_to_use_for_estimate]
774+
if lots.count() < lots_to_use_for_estimate:
775+
return None
776+
first_lot = lots[0]
777+
last_lot = lots[lots_to_use_for_estimate - 1]
778+
time_diff = first_lot.date_end - last_lot.date_end
779+
elapsed_seconds = time_diff.total_seconds()
780+
rate = elapsed_seconds / lots_to_use_for_estimate
781+
mintues_to_end = int(self.total_unsold_lots * rate / 60)
782+
if mintues_to_end < 15:
783+
return None
784+
return mintues_to_end
785+
except Exception as e:
786+
logger.error(e)
787+
return None
788+
763789
@property
764790
def location_qs(self):
765791
"""All locations associated with this auction"""

auctions/templates/auctions/dynamic_set_lot_winner.html

+17
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@
9999
} else {
100100
$("#sell_to_online_high_bidder").addClass('d-none');
101101
}
102+
if (response.auction_minutes_to_end) {
103+
var result = response.unsold_lot_count + " unsold lots. Based on the rate of the last 10 lots sold, this auction will end in "
104+
var hours = Math.floor(response.auction_minutes_to_end / 60);
105+
var remainingMinutes = response.auction_minutes_to_end % 60;
106+
if (hours > 0) {
107+
result += hours + " hour" + (hours > 1 ? "s" : "") + (remainingMinutes > 0 ? " and " + remainingMinutes + " minute" + (remainingMinutes > 1 ? "s" : "") : "");
108+
} else {
109+
result += remainingMinutes + " minute" + (remainingMinutes > 1 ? "s" : "");
110+
}
111+
$("#auction_minutes_to_end").removeClass('d-none');
112+
$("#auction_minutes_to_end").text(result);
113+
} else {
114+
$("#auction_minutes_to_end").addClass('d-none');
115+
}
102116

103117
}
104118

@@ -243,4 +257,7 @@
243257
</form>
244258
</div>
245259
<div id="result"></div>
260+
<div class="d-flex justify-content-center">
261+
<small><span class="text-muted" id="auction_minutes_to_end"></span></small>
262+
</div>
246263
{% endblock %}

auctions/views.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def post(self, request, *args, **kwargs):
13261326
class AuctionTOSValidation(AuctionViewMixin, APIPostView):
13271327
"""For real time validation on the auctiontos admin create form
13281328
See views.AuctionTOSAdmin for the corresponding js and view
1329-
qqq"""
1329+
"""
13301330

13311331
def post(self, request, *args, **kwargs):
13321332
pk = request.POST.get("pk", None)
@@ -2534,6 +2534,7 @@ def post(self, request, *args, **kwargs):
25342534
"last_sold_lot_number": None,
25352535
"success_message": None,
25362536
"online_high_bidder_message": None,
2537+
"auction_minutes_to_end": None,
25372538
}
25382539
lot, lot_error = self.validate_lot(lot, action)
25392540
if lot and not lot_error and action == "to_online_high_bidder":
@@ -2603,6 +2604,9 @@ def post(self, request, *args, **kwargs):
26032604
result["lot"] = lot_error or lot
26042605
result["price"] = price_error or price
26052606
result["winner"] = winner_error or winner
2607+
if not lot_error and not price_error and not winner_error:
2608+
result["auction_minutes_to_end"] = self.auction.estimate_end
2609+
result["unsold_lot_count"] = self.auction.total_unsold_lots
26062610
return JsonResponse(result)
26072611

26082612

@@ -4080,7 +4084,7 @@ def get_context_data(self, **kwargs):
40804084
else:
40814085
extra_script += "var pk=null;"
40824086
extra_script += f"""var validation_url = '{reverse("auctiontos_validation", kwargs={"slug": self.auction.slug})}';
4083-
var csrf_token = '{get_token(self.request)}';'qqq'"""
4087+
var csrf_token = '{get_token(self.request)}';"""
40844088
extra_script += """
40854089
40864090
function setFieldInvalid(fieldId, message, is_invalid) {

0 commit comments

Comments
 (0)