Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GrabGrub
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
Matthew Dominic M. Dizon
GrabGrub
Commits
e4801b6b
Commit
e4801b6b
authored
May 27, 2021
by
Matthew Dizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
messages with CRUD functionality for customer
parent
645ee339
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
7 deletions
+30
-7
add_food.html
GrabGrub/Kiosk/templates/Kiosk/add_food.html
+0
-2
view_customer_details.html
GrabGrub/Kiosk/templates/Kiosk/view_customer_details.html
+3
-0
view_customers.html
GrabGrub/Kiosk/templates/Kiosk/view_customers.html
+4
-0
views.py
GrabGrub/Kiosk/views.py
+23
-5
No files found.
GrabGrub/Kiosk/templates/Kiosk/add_food.html
View file @
e4801b6b
...
...
@@ -28,8 +28,6 @@
<input
type=
"datetime-local"
class=
"form-control"
id=
"date"
name=
"date"
required
>
</div>
<input
type=
"hidden"
name=
"message"
value=
"Food created successfully"
>
<a
href=
"{% url 'add_food' %}"
><button
type=
"submit"
class=
"mt-3 btn btn-primary"
>
Add Food
</button></a>
</form>
...
...
GrabGrub/Kiosk/templates/Kiosk/view_customer_details.html
View file @
e4801b6b
...
...
@@ -16,4 +16,7 @@
<a
href=
"{% url 'update_customer' customer.pk %}"
><button
type=
"submit"
class=
"btn btn-primary"
>
Update Customer
</button></a>
<a
href=
"{% url 'delete_customer' customer.pk %}"
><button
class=
"btn btn-danger my-4"
>
Delete Customer
</button></a>
<a
href=
"{% url 'view_customers' %}"
><button
class=
"btn btn-secondary"
>
Back
</button></a>
{% if message %}
<p
class=
"mt-3 alert alert-success"
style=
"width: 75%"
>
{{message}}
</p>
{% endif %}
{% endblock %}
\ No newline at end of file
GrabGrub/Kiosk/templates/Kiosk/view_customers.html
View file @
e4801b6b
...
...
@@ -9,6 +9,10 @@
</div>
</section>
{% if message %}
<p
class=
"mt-3 alert alert-success"
>
{{message}}
</p>
{% endif %}
<div
class=
"col-12"
>
<table
class=
"table table-striped"
>
<thead>
...
...
GrabGrub/Kiosk/views.py
View file @
e4801b6b
...
...
@@ -151,6 +151,7 @@ def update_food(request, pk):
try
:
Food
.
objects
.
filter
(
pk
=
pk
)
.
update
(
name
=
name
,
description
=
description
,
price
=
price
,
created_at
=
created_at
)
message
=
"Food updated successfully"
return
redirect
(
f
'/view_food_details/{pk}?message={message}'
,
pk
=
pk
)
except
Exception
as
e
:
...
...
@@ -195,25 +196,42 @@ def add_food(request):
### Views for Customer Model
def
view_customers
(
request
):
customers
=
Customer
.
objects
.
all
()
if
request
.
GET
.
get
(
'message'
)
==
None
:
context
=
{
"customers"
:
customers
}
else
:
context
=
{
"customers"
:
customers
,
'message'
:
request
.
GET
.
get
(
'message'
)}
return
render
(
request
,
'Kiosk/view_customers.html'
,
context
)
def
view_customer_details
(
request
,
pk
):
customer
=
get_object_or_404
(
Customer
,
pk
=
pk
)
if
request
.
GET
.
get
(
'message'
)
==
None
:
context
=
{
"customer"
:
customer
}
else
:
context
=
{
"customer"
:
customer
,
'message'
:
request
.
GET
.
get
(
'message'
)}
return
render
(
request
,
'Kiosk/view_customer_details.html'
,
context
)
def
delete_customer
(
request
,
pk
):
Customer
.
objects
.
filter
(
pk
=
pk
)
.
delete
()
return
redirect
(
'view_customers'
)
message
=
"Customer deleted successfully"
return
redirect
(
f
'/customers?message={message}'
)
def
update_customer
(
request
,
pk
):
if
(
request
.
method
==
"POST"
):
customer_name
=
request
.
POST
.
get
(
'customer_name'
)
address
=
request
.
POST
.
get
(
'address'
)
city
=
request
.
POST
.
get
(
'city'
)
try
:
Customer
.
objects
.
filter
(
pk
=
pk
)
.
update
(
name
=
customer_name
,
address
=
address
,
city
=
city
)
return
redirect
(
'view_customer_details'
,
pk
=
pk
)
message
=
"Customer updated successfully"
return
redirect
(
f
'/view_customer_details/{pk}?message={message}'
,
pk
=
pk
)
except
Exception
as
e
:
message
=
f
"Customer with name '{customer_name}' already exists"
customer
=
get_object_or_404
(
Customer
,
pk
=
pk
)
context
=
{
"customer"
:
customer
,
"message"
:
message
}
return
render
(
request
,
'Kiosk/update_customer.html'
,
context
)
else
:
customer
=
get_object_or_404
(
Customer
,
pk
=
pk
)
context
=
{
"customer"
:
customer
}
...
...
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