Commit d93e5739 authored by Martina Therese R. Reyes's avatar Martina Therese R. Reyes

Merge branch 'felizia' of...

Merge branch 'felizia' of ssh://gitlab.discs.ateneo.edu:15316/matereyes00/boodle into mate_devbranch
parents 607efddb 5207bc71
a{% extends 'boodlesite\templates\base.html' %} {% extends 'boodlesite\templates\base.html' %}
{% load static %} {% load static %}
{% block title %}Auction{% endblock %} {% block title %}Auction{% endblock %}
...@@ -21,7 +21,6 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -21,7 +21,6 @@ a{% extends 'boodlesite\templates\base.html' %}
</div> </div>
<!--product display --> <!--product display -->
product display div
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner"> <div class="carousel-inner">
...@@ -55,7 +54,6 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -55,7 +54,6 @@ a{% extends 'boodlesite\templates\base.html' %}
</div> </div>
<div class="col-lg-5 col-md-6"> <div class="col-lg-5 col-md-6">
product info div
<div class="product-info" style="border: 2px dotted black;"> <div class="product-info" style="border: 2px dotted black;">
...@@ -63,7 +61,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -63,7 +61,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<h4>Product Specifications</h4> <h4>Product Specifications</h4>
<p>{{ item_specs }}</p> <p>{{ item_specs }}</p>
<p> Starting at: PHP{{ item_floor_price }} </p> <p>Starting at: {{item_floor_price}}</p>
</div> </div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal" <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal"
...@@ -84,7 +82,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -84,7 +82,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<div class="modal-body"> <div class="modal-body">
<form action="" method="POST"> <form action="" method="POST">
<div class="form-group"> <div class="form-group">
<h3>Current Highest Bid: PHP {{highest_bid.amount}}</h3> <h3>Current Highest Bid: PHP {{highest_bid}}</h3>
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
</div> </div>
...@@ -115,7 +113,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -115,7 +113,7 @@ a{% extends 'boodlesite\templates\base.html' %}
</li> </li>
{% endfor %} {% endfor %}
{% else %} {% else %}
<h3> no bids placed yet.</h3> <h3> No bids have been placed for this item yet.</h3>
{% endif %} {% endif %}
</ul> </ul>
......
...@@ -3,17 +3,28 @@ from django.forms import (ModelForm, ...@@ -3,17 +3,28 @@ from django.forms import (ModelForm,
TextInput, Textarea, widgets) TextInput, Textarea, widgets)
from .models import * from .models import *
from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm): class PlaceBidForm(forms.ModelForm):
class Meta: class Meta:
model = AuctionBid model = AuctionBid
fields = ['amount'] fields = ['amount','auctionid']
widgets = {'auctionid': forms.HiddenInput()}
def clean(self):
super().clean()
form_amount = self.cleaned_data.get('amount')
auction = self.cleaned_data.get('auctionid')
def clean_amount(self): auction_item = Item.objects.get(auction=auction)
form_amount = self.cleaned_data.get("amount")
prev_amt = AuctionBid.objects.latest("amount")
prev_amt_cleaned = prev_amt.amount
if prev_amt_cleaned > form_amount: auction_bids = AuctionBid.objects.filter(auctionid=auction)
raise forms.ValidationError("Please Put Higher Bid")
return form_amount if not auction_bids:
highest_bid = auction_item.floorprice
if form_amount < highest_bid:
raise ValidationError('Please enter an amount greater than or equal to the floorprice.')
else:
highest_bid = auction_bids.latest('bidtime').amount
if form_amount <= highest_bid:
raise ValidationError('Please enter an amount higher than the current highest bid.')
\ No newline at end of file
...@@ -40,20 +40,23 @@ def auction(request, pk): ...@@ -40,20 +40,23 @@ def auction(request, pk):
# Auction bids # Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime') auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
if not auction_bids:
highest_bid = auction_item.floorprice highest_bid = auction_item.floorprice
else:
highest_bid = auction_bids[0]
form = PlaceBidForm() if auction_bids:
highest_bid = auction_bids[0].amount
form = PlaceBidForm(initial={'auctionid':auction})
if request.method == 'POST': if request.method == 'POST':
form = PlaceBidForm(request.POST) form = PlaceBidForm(request.POST,initial={'auctionid':auction})
if form.is_valid(): if form.is_valid():
try:
amount = form.cleaned_data['amount'] amount = form.cleaned_data['amount']
if amount > highest_bid.amount:
new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction) new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction)
new_bid.save() new_bid.save()
return redirect(f"/auction/{pk}") return redirect(f"/auction/{pk}")
except:
pass
context = { context = {
'item_name':auction_item.itemname, 'item_name':auction_item.itemname,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment