Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PizzaPalace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
PizzaPalace
Commits
6b3b6ec2
Verified
Commit
6b3b6ec2
authored
Jul 13, 2023
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
Make some progress on order screen
parent
14e1da3a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/pizza_palace.py
+60
-7
60 additions, 7 deletions
client/pizza_palace.py
with
60 additions
and
7 deletions
client/pizza_palace.py
+
60
−
7
View file @
6b3b6ec2
...
...
@@ -17,6 +17,8 @@ pizzas = []
cart_id
=
""
cart_key
=
""
orderpage_items
=
[]
## Subroutines
def
get_endpoint
(
endpoint
):
return
connect_url
.
get
()
+
endpoint
...
...
@@ -45,7 +47,14 @@ def connect_fail():
tab_control
.
select
(
connect_frame
)
messagebox
.
showerror
(
"
Connection failed
"
,
"
Could not connect to server
"
)
# Connection success fail function
# Request session fail function
def
request_session_fail
():
logger
.
error
(
"
Request session failed
"
)
connect_status_label
.
configure
(
text
=
"
Request session failed
"
)
tab_control
.
select
(
connect_frame
)
messagebox
.
showerror
(
"
Request session failed
"
,
"
Could not request session
"
)
# Connection success function
# Used when the server is reachable and all is ok
# in the initial connection attempt
def
connect_success
():
...
...
@@ -65,8 +74,13 @@ def connect(*args):
try
:
res_json
=
json
.
loads
(
res
.
text
)
if
(
res_json
[
"
status
"
]
==
200
and
res_json
[
"
message
"
]
==
"
ok
"
):
# Request session
logger
.
debug
(
"
Got OK response from server
"
)
if
(
new_session
()):
connect_success
()
return
request_session_fail
()
return
else
:
logger
.
debug
(
"
Response from server did not contain OK
"
)
connect_fail
()
...
...
@@ -87,27 +101,66 @@ def connect(*args):
# Create new session
def
new_session
(
*
arg
):
global
cart_id
,
cart_key
res
=
requests
.
post
(
get_endpoint
(
"
/cart/
new
"
))
res
=
requests
.
post
(
get_endpoint
(
"
/cart/
open
"
))
if
(
res
.
status_code
==
200
):
res_json
=
res
.
json
()
if
(
res_json
!=
None
and
res_json
[
"
status
"
]
==
200
):
cart_id
,
cart_key
=
res_json
[
"
id
"
],
res_json
[
"
key
"
]
return
True
else
:
connect_fail
()
return
False
else
:
connect_fail
()
return
False
# Refresh order screen items
def
refresh_items
(
*
args
):
def
refresh_items
():
global
pizzas
res
=
requests
.
get
(
get_endpoint
(
"
/pizzas
"
))
if
(
res
.
status_code
==
200
and
res
.
json
()
!=
None
):
pizzas
=
res
.
json
()
return
True
else
:
connect_fail
()
return
False
def
order_item
(
item
,
people
,
stuffed_crust
):
pass
class
OrderItem
():
def
__init__
(
self
,
pizza_dict
,
col
):
self
.
id
=
pizza_dict
.
id
self
.
col
=
col
self
.
label1
=
ttk
.
Label
(
order_frame
,
text
=
pizza_dict
.
name
)
self
.
label1
.
grid
(
column
=
col
,
row
=
1
,
sticky
=
(
W
,
E
))
self
.
label2
=
ttk
.
Label
(
order_frame
,
text
=
"
£%.2f
"
%
pizza_dict
.
costpp
)
self
.
label2
.
grid
(
column
=
col
,
row
=
2
,
sticky
=
(
W
,
E
))
# TODO number of people
self
.
quantity
=
IntVar
(
value
=
1
)
# self.quant_entry = ttk.Spinbox(order_frame, from=1, to=99)
# TODO stuffed crust
self
.
stuffed_crust
=
BooleanVar
()
self
.
order_butt
=
ttk
.
Button
(
order_frame
,
text
=
"
Order
"
,
command
=
self
.
order
)
self
.
order_butt
.
grid
(
column
=
col
,
row
=
4
,
sticky
=
(
W
,
E
))
def
order
(
self
):
order_item
(
self
.
id
,
self
.
quantity
.
get
(),
self
.
stuffed_crust
.
get
())
def
refresh_order_items
(
*
args
):
global
order_frame
if
(
refresh_items
()):
# Remove all items
for
op_item
in
orderpage_items
:
for
op_childitem
in
op_item
:
op_childitem
.
destroy
()
del
op_childitem
del
op_item
col
=
1
for
pizza
in
pizzas
:
piz_label1
=
ttk
.
Label
(
order_frame
,
text
=
pizza
.
name
)
piz_label1
.
grid
(
column
=
col
,
row
=
1
,
sticky
=
(
W
,
E
))
piz_label2
=
ttk
.
Label
(
order_frame
,
text
=
"
£%.2f
"
%
pizza
.
costpp
)
piz_label2
.
grid
(
column
=
col
,
row
=
2
,
sticky
=
(
W
,
E
))
piz_orderbutton
=
ttk
.
Button
(
order_frame
,
text
=
"
Order
"
,
command
=
lambda
:
order_item
())
## Main program code
# Window setup
...
...
@@ -136,7 +189,7 @@ connect_frame.bind("<Return>", connect)
# Order tab
order_frame
=
create_tab
(
"
Order
"
)
# TODO order list
refresh_order_items
()
# Cart tab
cart_frame
=
create_tab
(
"
Cart
"
)
...
...
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