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
acbaab77
Commit
acbaab77
authored
2 years ago
by
Arno Wunderlich
Browse files
Options
Downloads
Patches
Plain Diff
added items are now saved to db
parent
a22e174c
No related branches found
Branches containing commit
No related tags found
1 merge request
!10
Add item backend
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tjts5901/templates/addItem.html
+5
-5
5 additions, 5 deletions
src/tjts5901/templates/addItem.html
src/tjts5901/views.py
+52
-8
52 additions, 8 deletions
src/tjts5901/views.py
with
57 additions
and
13 deletions
src/tjts5901/templates/addItem.html
+
5
−
5
View file @
acbaab77
...
...
@@ -10,23 +10,23 @@
</header>
<main>
<form
class=
"container-fluid"
action=
"
#
"
method=
"
GE
T"
>
<form
class=
"container-fluid"
action=
"
{{ url_for('views.add_item') }}
"
method=
"
POS
T"
>
<div
class=
"container"
>
<div
class=
"mb-3"
>
<label
for=
"email"
class=
"form-label"
>
Email address
</label>
<input
type=
"email"
class=
"form-control"
id=
"email"
aria-describedby=
"emailHelp"
>
<input
type=
"email"
class=
"form-control"
id=
"email"
name=
"email"
aria-describedby=
"emailHelp"
>
</div>
<div
class=
"mb-3"
>
<label
for=
"nItem"
class=
"form-label"
>
Item's name
</label>
<input
type=
"text"
class=
"form-control"
id=
"nItem"
aria-describedby=
"emailHelp
"
>
<input
type=
"text"
class=
"form-control"
id=
"nItem"
name=
"nItem
"
>
</div>
<div
class=
"mb-3"
>
<label
for=
"description"
class=
"form-label"
>
Description
</label>
<textarea
class=
"form-control"
id=
"description"
maxlength=
"700"
></textarea>
<textarea
class=
"form-control"
id=
"description"
name=
"description"
maxlength=
"700"
></textarea>
</div>
<div
class=
"mb-3"
>
<label
for=
"sPrice"
class=
"form-label"
>
Starting price
</label>
<input
type=
"number"
class=
"form-control"
id=
"sPrice"
min=
"0"
max=
"100000000"
>
<input
type=
"number"
class=
"form-control"
id=
"sPrice"
name=
"sPrice"
min=
"0"
max=
"100000000"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
</div>
...
...
This diff is collapsed.
Click to expand it.
src/tjts5901/views.py
+
52
−
8
View file @
acbaab77
...
...
@@ -3,7 +3,10 @@ Basic views for Application
===========================
"""
from
flask
import
Blueprint
,
render_template
,
send_from_directory
import
random
from
datetime
import
datetime
,
timedelta
from
flask
import
Blueprint
,
render_template
,
send_from_directory
,
request
,
flash
,
url_for
,
redirect
from
.models
import
Item
,
User
# Main blueprint.
bp
=
Blueprint
(
'
views
'
,
__name__
)
...
...
@@ -29,10 +32,7 @@ def test_item_adding():
Test item is added
"""
from
.models
import
Item
,
User
# for test purpose create random number (unique mail address required)
import
random
ran_int
=
str
(
random
.
randint
(
0
,
10000
))
# Create a new user
...
...
@@ -51,12 +51,56 @@ def test_item_adding():
return
"
OK
"
@bp.route
(
"
/addItem
"
)
def
add
I
tem
()
->
str
:
@bp.route
(
"
/addItem
"
,
methods
=
(
'
GET
'
,
'
POST
'
)
)
def
add
_i
tem
():
"""
AddItem page.
"""
if
request
.
method
==
'
POST
'
:
nItem
=
request
.
form
.
get
(
'
nItem
'
)
print
(
'
nItem:
'
,
nItem
)
description
=
request
.
form
.
get
(
'
description
'
)
starting_price
=
int
(
request
.
form
.
get
(
'
sPrice
'
))
error
=
None
print
(
"
here: 66
"
)
if
not
nItem
:
error
=
'
Item name is required.
'
if
not
starting_price
or
starting_price
<
1
:
error
=
'
Starting price must be greater than 0.
'
if
error
is
None
:
# Placeholder for user as long as login function is not defined
ran_int
=
str
(
random
.
randint
(
0
,
10000
))
user
=
User
()
user
.
email
=
"
test
"
+
ran_int
+
"
@gmail.com
"
user
.
password
=
"
placeholder
"
user
.
save
()
try
:
item
=
Item
(
title
=
nItem
,
description
=
description
,
starting_bid
=
starting_price
,
seller
=
user
,
closes_at
=
datetime
.
utcnow
()
+
timedelta
(
days
=
1
)
)
item
.
save
()
print
(
"
item saved
"
)
except
Exception
as
exc
:
error
=
f
"
Error creating item:
{
exc
!s}
"
else
:
return
redirect
(
url_for
(
'
views.adding_successful
'
))
print
(
error
)
flash
(
error
)
item
=
render_template
(
"
addItem.html
"
)
return
item
@bp.route
(
"
/adding_successful
"
)
def
adding_successful
():
return
"
Item added successfully
"
Item
=
render_template
(
"
addItem.html
"
,
title
=
"
Adding items
"
)
return
Item
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