Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
frozen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSE6
frozen
Commits
19f8c59f
Commit
19f8c59f
authored
2 years ago
by
Arno Wunderlich
Browse files
Options
Downloads
Patches
Plain Diff
bidding backend frontend integration
parent
697dcaf7
No related branches found
No related tags found
1 merge request
!41
Bidding frontend backend integration fixes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tjts5901/templates/view.html
+1
-1
1 addition, 1 deletion
src/tjts5901/templates/view.html
src/tjts5901/views.py
+8
-26
8 additions, 26 deletions
src/tjts5901/views.py
with
9 additions
and
27 deletions
src/tjts5901/templates/view.html
+
1
−
1
View file @
19f8c59f
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
<p
class=
"mb-1"
>
Created : {{ item.created_at }}
</p>
<p
class=
"mb-1"
>
Created : {{ item.created_at }}
</p>
<p
class=
"mb-1"
>
Current bid : {{ item.starting_bid }}
</p><br/>
<p
class=
"mb-1"
>
Current bid : {{ item.starting_bid }}
</p><br/>
<form
method=
"POST"
action=
"{{ url_for('views.bid', id=item.id)}}"
class=
"row"
enctype=
"multipart/form-data"
>
<form
method=
"POST"
action=
"{{ url_for('views.bid', id=item.id)}}"
class=
"row"
enctype=
"multipart/form-data"
>
<input
class=
"col-md-9"
id=
"bid"
type=
"number"
min=
"{{ item.starting_bid }}"
placeholder=
"write your bid"
>
<input
class=
"col-md-9"
id=
"bid"
name =
"bid"
type=
"number"
min=
"{{ item.starting_bid }}"
placeholder=
"write your bid"
>
<button
for=
"bid"
type=
"submit"
class=
"btn btn-primary col-md-3"
>
Validate
</button>
<button
for=
"bid"
type=
"submit"
class=
"btn btn-primary col-md-3"
>
Validate
</button>
</form>
</form>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
src/tjts5901/views.py
+
8
−
26
View file @
19f8c59f
...
@@ -172,42 +172,24 @@ def list_bid():
...
@@ -172,42 +172,24 @@ def list_bid():
html
=
render_template
(
"
listBid.html
"
,
items
=
items
)
html
=
render_template
(
"
listBid.html
"
,
items
=
items
)
return
html
return
html
@bp.route
(
'
/item/<id>
'
)
def
view
(
id
):
"""
Item view page.
Displays the item details, and a form to place a bid.
"""
item
=
Item
.
objects
.
get_or_404
(
id
=
id
)
# Set the minumum price for the bid form from the current winning bid
@bp.route
(
"
item/<id>/bid
"
,
methods
=
(
'
POST
'
,))
winning_bid
=
get_winning_bid
(
item
)
min_bid
=
get_item_price
(
item
)
if
item
.
closes_at
<
datetime
.
utcnow
()
and
winning_bid
.
bidder
==
current_user
:
flash
((
"
Congratulations! You won the auction!
"
))
elif
item
.
closes_at
<
datetime
.
utcnow
()
+
timedelta
(
hours
=
1
):
# Dark pattern to show enticing message to user
flash
((
"
This item is closing soon! Act now! Now! Now!
"
))
return
render_template
(
"
item.html
"
,
item
=
item
)
@bp.route
(
"
item/<id>/bid
"
)
@login_required
@login_required
def
bid
(
id
):
def
bid
(
id
):
"""
"""
method that saves bid on object
method that saves bid on object
If the bid is valid, create a new bid and redirect to the item view page.
Otherwise, display an error message and redirect back to the item view page.
"""
"""
# frontend not implemented yet, therefore not active
# frontend not implemented yet, therefore not active
item
=
Item
.
objects
.
get_or_404
(
id
=
id
)
item
=
Item
.
objects
.
get_or_404
(
id
=
id
)
min_amount
=
item
.
starting_bid
min_amount
=
item
.
starting_bid
amount
=
request
.
form
[
'
amount
'
]
amount
=
int
(
request
.
form
.
get
(
'
bid
'
))
if
amount
<
min_amount
:
if
amount
<
=
min_amount
:
flash
((
"
Bid must be at least %(min_amount)s
"
,
min_amount
))
flash
((
"
Bid must be at least %(min_amount)s
"
,
min_amount
))
return
redirect
(
url_for
(
'
views.list_bid
'
))
return
redirect
(
url_for
(
'
views.list_bid
'
))
...
@@ -225,7 +207,7 @@ def bid(id):
...
@@ -225,7 +207,7 @@ def bid(id):
)
)
bid
.
save
()
bid
.
save
()
except
Exception
as
exc
:
except
Exception
as
exc
:
flash
(
_
(
"
Error placing bid: %(exc)s
"
,
exc
=
exc
))
flash
((
"
Error placing bid: %(exc)s
"
,
exc
=
exc
))
else
:
else
:
flash
((
"
Bid placed successfully!
"
))
flash
((
"
Bid placed successfully!
"
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment