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
976825e0
Commit
976825e0
authored
Nov 15, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement stall views as View and FormView classes
parent
03656886
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
59 deletions
+64
-59
stall_views.py
canteeneo/stall_views.py
+64
-59
No files found.
canteeneo/stall_views.py
View file @
976825e0
from
canteeneo
import
app
,
db
from
canteeneo
import
app
,
db
from
canteeneo.models
import
Stall
,
Location
from
canteeneo.models
import
Stall
,
Location
from
canteeneo.forms
import
StallRegisterForm
from
canteeneo.forms
import
StallRegisterForm
from
canteeneo.views
import
flash_form_errors
,
stall_validate
from
canteeneo.views
import
flash_form_errors
,
stall_validate
,
FormView
from
flask
import
render_template
,
redirect
,
url_for
,
request
from
flask
import
render_template
,
redirect
,
url_for
,
request
from
flask.views
import
View
from
flask_login
import
login_required
,
current_user
from
flask_login
import
login_required
,
current_user
@
app
.
route
(
'/stalls'
)
class
StallListView
(
View
):
@
login_required
decorators
=
[
login_required
]
def
stalls
(
):
def
dispatch_request
(
self
):
return
render_template
(
'stalls.html'
,
owner
=
current_user
,
stalls
=
current_user
.
stalls
.
all
())
return
render_template
(
'stalls.html'
,
owner
=
current_user
,
stalls
=
current_user
.
stalls
.
all
())
@
app
.
route
(
'/stalls/<int:stall_id>'
)
app
.
add_url_rule
(
'/stalls'
,
view_func
=
StallListView
.
as_view
(
'stalls'
),
methods
=
[
'GET'
])
@
login_required
@
stall_validate
class
StallView
(
View
):
def
view_stall
(
stall_id
):
decorators
=
[
login_required
,
stall_validate
]
def
dispatch_request
(
self
,
stall_id
):
stall
=
Stall
.
query
.
get
(
stall_id
)
stall
=
Stall
.
query
.
get
(
stall_id
)
dishes
=
stall
.
dishes
.
all
()
dishes
=
stall
.
dishes
.
all
()
return
render_template
(
'viewstall.html'
,
stall
=
stall
,
dishes
=
dishes
,
upload_folder
=
app
.
config
[
'UPLOAD_FOLDER'
])
return
render_template
(
'viewstall.html'
,
stall
=
stall
,
dishes
=
dishes
,
upload_folder
=
app
.
config
[
'UPLOAD_FOLDER'
])
@
app
.
route
(
'/stalls/new'
,
methods
=
[
'GET'
,
'POST'
])
app
.
add_url_rule
(
'/stalls/<int:stall_id>'
,
view_func
=
StallView
.
as_view
(
'view_stall'
),
methods
=
[
'GET'
])
@
login_required
def
new_stall
():
class
NewStallView
(
FormView
):
form
=
StallRegisterForm
()
decorators
=
[
login_required
]
form
.
location
.
choices
=
[(
loc
.
id
,
loc
.
name
)
for
loc
in
Location
.
query
.
all
()]
def
render_post
(
self
):
if
request
.
method
==
'POST'
:
form
=
self
.
get_form
()
if
form
.
validate
():
stall
=
Stall
(
form
.
name
.
data
,
form
.
description
.
data
,
current_user
.
id
,
form
.
location
.
data
)
stall
=
Stall
(
form
.
name
.
data
,
form
.
description
.
data
,
current_user
.
id
,
form
.
location
.
data
)
db
.
session
.
add
(
stall
)
db
.
session
.
add
(
stall
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall
.
id
))
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall
.
id
))
else
:
def
render_get
(
self
):
flash_form_errors
(
form
)
return
render_template
(
'newstall.html'
,
form
=
self
.
get_form
())
return
redirect
(
url_for
(
'new_stall'
))
def
get_form
(
self
):
form
=
StallRegisterForm
()
form
.
location
.
choices
=
[(
loc
.
id
,
loc
.
name
)
for
loc
in
Location
.
query
.
all
()]
return
form
return
render_template
(
'newstall.html'
,
form
=
form
)
app
.
add_url_rule
(
'/stalls/new'
,
view_func
=
NewStallView
.
as_view
(
'new_stall'
)
)
@
app
.
route
(
'/stalls/<int:stall_id>/edit'
,
methods
=
[
'GET'
,
'POST'
])
class
EditStallView
(
FormView
):
@
login_required
decorators
=
[
login_required
,
stall_validate
]
@
stall_validate
def
dispatch_request
(
self
,
stall_id
):
def
edit_stall
(
stall_id
):
self
.
stall
=
Stall
.
query
.
get
(
stall_id
)
stall
=
Stall
.
query
.
get
(
stall_id
)
return
FormView
.
dispatch_request
(
self
,
stall_id
)
def
render_post
(
self
,
stall_id
):
form
=
self
.
get_form
()
self
.
stall
.
name
=
form
.
name
.
data
self
.
stall
.
description
=
form
.
description
.
data
self
.
stall
.
location_id
=
form
.
location
.
data
db
.
session
.
connect
()
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall_id
))
def
render_get
(
self
,
stall_id
):
form
=
self
.
get_form
()
form
.
name
.
data
=
self
.
stall
.
name
form
.
description
.
data
=
self
.
stall
.
description
form
.
location
.
data
=
self
.
stall
.
location_id
return
render_template
(
'editstall.html'
,
form
=
form
,
stall
=
stall
)
def
get_form
(
self
):
form
=
StallRegisterForm
()
form
=
StallRegisterForm
()
form
.
location
.
choices
=
[(
loc
.
id
,
loc
.
name
)
for
loc
in
Location
.
query
.
all
()]
form
.
location
.
choices
=
[(
loc
.
id
,
loc
.
name
)
for
loc
in
Location
.
query
.
all
()]
form
.
editing
=
True
form
.
editing
=
True
return
form
if
request
.
method
==
'POST'
:
app
.
add_url_rule
(
'/stalls/<int:stall_id>/edit'
,
view_func
=
EditStallView
.
as_view
(
'edit_stall'
))
if
form
.
validate
():
stall
.
name
=
form
.
name
.
data
stall
.
description
=
form
.
description
.
data
stall
.
location_id
=
form
.
location
.
data
db
.
session
.
commit
()
return
redirect
(
url_for
(
'view_stall'
,
stall_id
=
stall_id
))
else
:
flash_form_errors
(
form
)
return
redirect
(
url_for
(
'edit_stall'
,
values
=
[(
'stall_id'
,
stall_id
)]))
else
:
form
.
name
.
data
=
stall
.
name
form
.
description
.
data
=
stall
.
description
form
.
location
.
data
=
stall
.
location_id
return
render_template
(
'editstall.html'
,
form
=
form
,
stall
=
stall
)
class
DeleteStallView
(
View
):
decorators
=
[
login_required
,
stall_validate
]
@
app
.
route
(
'/stalls/<int:stall_id>/delete'
,
methods
=
[
'POST'
])
def
dispatch_request
(
self
,
stall_id
):
@
login_required
@
stall_validate
def
delete_stall
(
stall_id
):
stall
=
Stall
.
query
.
get
(
stall_id
)
stall
=
Stall
.
query
.
get
(
stall_id
)
db
.
session
.
delete
(
stall
)
db
.
session
.
delete
(
stall
)
db
.
session
.
commit
()
db
.
session
.
commit
()
return
redirect
(
url_for
(
'view_stall'
))
return
redirect
(
url_for
(
'view_stall'
),
stall_id
=
stall_id
)
\ No newline at end of file
app
.
add_url_rule
(
'/stalls/<int:stall_id>/delete'
,
view_func
=
DeleteStallView
.
as_view
(
'delete_stall'
),
methods
=
[
'POST'
])
\ No newline at end of file
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