Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CS123-Canteeneo
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Willard Torres
CS123-Canteeneo
Commits
0e07d5c1
Commit
0e07d5c1
authored
Nov 10, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement rest of dish_views as classes
parent
48e5fd07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
41 deletions
+38
-41
dish_views.py
canteeneo/dish_views.py
+38
-41
No files found.
canteeneo/dish_views.py
View file @
0e07d5c1
...
...
@@ -6,6 +6,7 @@ from canteeneo.forms import DishRegisterForm
from
canteeneo.views
import
flash_form_errors
,
stall_validate
,
dish_validate
,
FormView
from
flask
import
render_template
,
redirect
,
url_for
,
request
from
flask.views
import
View
from
flask_login
import
login_required
from
werkzeug.utils
import
secure_filename
...
...
@@ -26,47 +27,43 @@ class NewDishView(FormView):
def
get_form
(
self
):
return
DishRegisterForm
()
app
.
add_url_rule
(
'/stalls/<int:stall_id>/dishes/new'
,
view_func
=
NewDishView
.
as_view
(
'new_dish'
))
class
DishView
(
View
):
decorators
=
[
login_required
,
dish_validate
]
def
dispatch_request
(
self
,
stall_id
,
dish_id
):
return
render_template
(
'viewdish.html'
,
stall
=
Stall
.
query
.
get
(
stall_id
),
dish
=
Dish
.
query
.
get
(
dish_id
))
@
app
.
route
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>'
,
methods
=
[
"GET"
])
@
login_required
@
dish_validate
def
dish
(
stall_id
,
dish_id
):
return
render_template
(
'viewdish.html'
,
stall
=
Stall
.
query
.
get
(
stall_id
),
dish
=
Dish
.
query
.
get
(
dish_id
))
@
app
.
route
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>/edit'
,
methods
=
[
'GET'
,
'POST'
])
@
login_required
@
dish_validate
def
edit_dish
(
stall_id
,
dish_id
):
stall
=
Stall
.
query
.
get
(
stall_id
)
dish
=
Dish
.
query
.
get
(
dish_id
)
form
=
DishRegisterForm
()
if
request
.
method
==
'POST'
:
if
form
.
validate
(
editing
=
True
):
dish
.
name
=
form
.
name
.
data
dish
.
description
=
form
.
description
.
data
dish
.
price
=
form
.
price
.
data
if
form
.
image
.
data
.
filename
is
not
u''
:
dish
.
image_path
=
secure_filename
(
form
.
image
.
data
.
filename
)
form
.
image
.
data
.
save
(
os
.
path
.
join
(
app
.
config
[
'UPLOAD_FOLDER'
],
dish
.
image_path
))
db
.
session
.
commit
()
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall_id
))
else
:
flash_form_errors
(
form
)
return
redirect
(
url_for
(
'edit_dish'
,
stall_id
=
stall_id
,
dish_id
=
dish_id
))
else
:
form
.
name
.
data
=
dish
.
name
form
.
description
.
data
=
dish
.
description
form
.
price
.
data
=
dish
.
price
return
render_template
(
'editdish.html'
,
form
=
form
,
stall
=
stall
,
dish
=
dish
)
class
EditDishView
(
FormView
):
decorators
=
[
login_required
,
dish_validate
]
def
dispatch_request
(
self
,
stall_id
,
dish_id
):
self
.
stall
=
Stall
.
query
.
get
(
stall_id
)
self
.
dish
=
Dish
.
query
.
get
(
dish_id
)
return
FormView
.
dispatch_request
(
self
,
stall_id
,
dish_id
)
def
render_post
(
self
,
stall_id
,
dish_id
):
self
.
dish
.
name
=
form
.
name
.
data
self
.
dish
.
description
=
form
.
description
.
data
self
.
dish
.
price
=
form
.
price
.
data
if
form
.
image
.
data
.
filename
is
not
u''
:
self
.
dish
.
image_path
=
secure_filename
(
form
.
image
.
data
.
filename
)
form
.
image
.
data
.
save
(
os
.
path
.
join
(
app
.
config
[
'UPLOAD_FOLDER'
],
self
.
dish
.
image_path
))
db
.
session
.
commit
()
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall
.
id
))
def
render_get
(
self
,
stall_id
,
dish_id
):
form
.
name
.
data
=
self
.
dish
.
name
form
.
description
.
data
=
self
.
dish
.
description
form
.
price
.
data
=
self
.
dish
.
price
return
render_template
(
'editdish.html'
,
form
=
form
,
stall
=
self
.
stall
,
dish
=
self
.
dish
)
def
get_form
(
self
):
return
DishRegisterForm
()
@
app
.
route
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>/delete'
,
methods
=
[
'POST'
])
@
login_required
@
dish_validate
def
delete_dish
(
stall_id
,
dish_id
):
dish
=
Dish
.
query
.
get
(
dish_id
)
db
.
session
.
delete
(
dish
)
db
.
session
.
commit
(
)
class
DeleteDishView
(
View
):
decorators
=
[
login_required
,
dish_validate
]
def
dispatch_request
(
self
,
stall_id
,
dish_id
):
dish
=
Dish
.
query
.
get
(
dish_id
)
db
.
session
.
delete
(
dish
)
db
.
session
.
commit
(
)
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall_id
)
)
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall_id
))
\ No newline at end of file
app
.
add_url_rule
(
'/stalls/<int:stall_id>/dishes/new'
,
view_func
=
NewDishView
.
as_view
(
'new_dish'
))
app
.
add_url_rule
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>'
,
view_func
=
DishView
.
as_view
(
'view_dish'
),
methods
=
[
'GET'
])
app
.
add_url_rule
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>/edit'
,
view_func
=
EditDishView
.
as_view
(
'edit_dish'
))
app
.
add_url_rule
(
'/stalls/<int:stall_id>/dishes/<int:dish_id>/delete'
,
view_func
=
DeleteDishView
.
as_view
(
'delete_dish'
),
methods
=
[
'POST'
])
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