Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Boodle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martina Therese R. Reyes
Boodle
Commits
5207bc71
Commit
5207bc71
authored
Mar 29, 2022
by
Felizia Tiburcio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix form validation for Place Bid
parent
251a4d81
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
25 deletions
+38
-25
auction.html
boodlesite/templates/auction.html
+8
-9
forms.py
main/forms.py
+19
-8
views.py
main/views.py
+11
-8
No files found.
boodlesite/templates/auction.html
View file @
5207bc71
a
{% extends 'boodlesite\templates\base.html' %}
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}Auction{% endblock %}
...
...
@@ -12,7 +12,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"col-lg-7 col-md-6"
>
<!-- Countdown display-->
<!-- Countdown display-->
<div
class=
"test"
>
<!-- Format:
Auction ends at: <Date>
...
...
@@ -20,8 +20,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<h4>
Auction ends at: {{ auction_end }}
</h4>
</div>
<!--product display -->
product display div
<!--product display -->
<div
id=
"carouselExampleControls"
class=
"carousel slide"
data-ride=
"carousel"
>
<div
class=
"carousel-inner"
>
...
...
@@ -55,7 +54,6 @@ a{% extends 'boodlesite\templates\base.html' %}
</div>
<div
class=
"col-lg-5 col-md-6"
>
product info div
<div
class=
"product-info"
style=
"border: 2px dotted black;"
>
...
...
@@ -63,11 +61,12 @@ a{% extends 'boodlesite\templates\base.html' %}
<h4>
Product Specifications
</h4>
<p>
{{ item_specs }}
</p>
<p>
Starting at: {{item_floor_price}}
</p>
</div>
<button
type=
"button"
class=
"btn btn-primary"
data-toggle=
"modal"
data-target=
"#placeBidModal"
data-whatever=
"@mdo"
>
Place Bid
</button>
<div
class=
"modal fade"
id=
"placeBidModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"exampleModalLabel"
aria-hidden=
"true"
>
...
...
@@ -83,7 +82,7 @@ a{% extends 'boodlesite\templates\base.html' %}
<div
class=
"modal-body"
>
<form
action=
""
method=
"POST"
>
<div
class=
"form-group"
>
<h3>
Current Highest Bid: PHP {{highest_bid
.amount
}}
</h3>
<h3>
Current Highest Bid: PHP {{highest_bid}}
</h3>
{% csrf_token %}
{{ form }}
</div>
...
...
@@ -100,7 +99,7 @@ a{% extends 'boodlesite\templates\base.html' %}
</div>
<!-- latest bids / history -->
<!-- latest bids / history -->
<h1>
Latest Bids
</h1>
<ul
class=
"cards"
>
...
...
@@ -114,7 +113,7 @@ a{% extends 'boodlesite\templates\base.html' %}
</li>
{% endfor %}
{% else %}
<h3>
no bids placed
yet.
</h3>
<h3>
No bids have been placed for this item
yet.
</h3>
{% endif %}
</ul>
...
...
main/forms.py
View file @
5207bc71
...
...
@@ -3,17 +3,28 @@ from django.forms import (ModelForm,
TextInput
,
Textarea
,
widgets
)
from
.models
import
*
from
django.core.exceptions
import
ValidationError
class
PlaceBidForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
AuctionBid
fields
=
[
'amount'
]
fields
=
[
'amount'
,
'auctionid'
]
widgets
=
{
'auctionid'
:
forms
.
HiddenInput
()}
def
clean
_amount
(
self
):
form_amount
=
self
.
cleaned_data
.
get
(
"amount"
)
prev_amt
=
AuctionBid
.
objects
.
latest
(
"amount"
)
prev_amt_cleaned
=
prev_amt
.
amount
def
clean
(
self
):
super
()
.
clean
(
)
form_amount
=
self
.
cleaned_data
.
get
(
'amount'
)
auction
=
self
.
cleaned_data
.
get
(
'auctionid'
)
if
prev_amt_cleaned
>
form_amount
:
raise
forms
.
ValidationError
(
"Please Put Higher Bid"
)
auction_item
=
Item
.
objects
.
get
(
auction
=
auction
)
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
main/views.py
View file @
5207bc71
...
...
@@ -40,20 +40,23 @@ def auction(request, pk):
# Auction bids
auction_bids
=
AuctionBid
.
objects
.
filter
(
auctionid
=
pk
)
.
order_by
(
'-bidtime'
)
if
not
auction_bids
:
highest_bid
=
auction_item
.
floorprice
else
:
highest_bid
=
auction_bids
[
0
]
highest_bid
=
auction_item
.
floorprice
if
auction_bids
:
highest_bid
=
auction_bids
[
0
]
.
amount
form
=
PlaceBidForm
()
form
=
PlaceBidForm
(
initial
=
{
'auctionid'
:
auction
}
)
if
request
.
method
==
'POST'
:
form
=
PlaceBidForm
(
request
.
POST
)
form
=
PlaceBidForm
(
request
.
POST
,
initial
=
{
'auctionid'
:
auction
}
)
if
form
.
is_valid
():
amount
=
form
.
cleaned_data
[
'amount'
]
if
amount
>
highest_bid
.
amount
:
try
:
amount
=
form
.
cleaned_data
[
'amount'
]
new_bid
=
AuctionBid
(
amount
=
amount
,
bidtime
=
datetime
.
now
(),
auctionid
=
auction
)
new_bid
.
save
()
return
redirect
(
f
"/auction/{pk}"
)
except
:
pass
context
=
{
'item_name'
:
auction_item
.
itemname
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment