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 %}
...@@ -12,7 +12,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -12,7 +12,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-lg-7 col-md-6"> <div class="col-lg-7 col-md-6">
<!-- Countdown display--> <!-- Countdown display-->
<div class="test"> <div class="test">
<!-- Format: <!-- Format:
Auction ends at: <Date> Auction ends at: <Date>
...@@ -20,8 +20,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -20,8 +20,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<h4> Auction ends at: {{ auction_end }} </h4> <h4> Auction ends at: {{ auction_end }} </h4>
</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,12 +61,12 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -63,12 +61,12 @@ 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"
data-whatever="@mdo">Place Bid</button> data-whatever="@mdo">Place Bid</button>
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" <div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true"> aria-hidden="true">
...@@ -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>
...@@ -101,7 +99,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -101,7 +99,7 @@ a{% extends 'boodlesite\templates\base.html' %}
</div> </div>
<!-- latest bids / history --> <!-- latest bids / history -->
<h1>Latest Bids</h1> <h1>Latest Bids</h1>
<ul class="cards"> <ul class="cards">
...@@ -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_amount(self): def clean(self):
form_amount = self.cleaned_data.get("amount") super().clean()
prev_amt = AuctionBid.objects.latest("amount") form_amount = self.cleaned_data.get('amount')
prev_amt_cleaned = prev_amt.amount auction = self.cleaned_data.get('auctionid')
if prev_amt_cleaned > form_amount: auction_item = Item.objects.get(auction=auction)
raise forms.ValidationError("Please Put Higher Bid")
return form_amount auction_bids = AuctionBid.objects.filter(auctionid=auction)
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: if auction_bids:
highest_bid = auction_bids[0] highest_bid = auction_bids[0].amount
form = PlaceBidForm() 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():
amount = form.cleaned_data['amount'] try:
if amount > highest_bid.amount: amount = form.cleaned_data['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