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
8401a6ed
Commit
8401a6ed
authored
Oct 23, 2016
by
Willard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move API specific functions to api.py, fixe imports
parent
f0fc44d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
41 deletions
+45
-41
__init__.py
canteeneo/__init__.py
+2
-1
api.py
canteeneo/api.py
+43
-0
views.py
canteeneo/views.py
+0
-40
No files found.
canteeneo/__init__.py
View file @
8401a6ed
...
...
@@ -18,4 +18,5 @@ db = SQLAlchemy(app)
migrate
=
Migrate
(
app
,
db
)
import
models
import
controllers
\ No newline at end of file
import
views
import
api
\ No newline at end of file
canteeneo/api.py
0 → 100644
View file @
8401a6ed
from
canteeneo
import
app
from
flask
import
jsonify
,
request
from
models
import
Dish
,
Stall
,
Location
from
datetime
import
datetime
@
app
.
route
(
'/api/all'
)
def
all
():
data
=
{
'update_time'
:
str
(
datetime
.
now
()),
'dishes'
:
[],
'stalls'
:
[],
'locations'
:
[]}
for
dish
in
Dish
.
query
.
all
():
data
[
'dishes'
]
.
append
({
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_id'
:
dish
.
stall_id
,
'image_path'
:
dish
.
image_path
})
for
stall
in
Stall
.
query
.
all
():
data
[
'stalls'
]
.
append
({
'id'
:
stall
.
id
,
'name'
:
stall
.
name
})
for
loc
in
Location
.
query
.
all
():
data
[
'locations'
]
.
append
({
'id'
:
loc
.
id
,
'name'
:
loc
.
name
})
return
jsonify
(
**
data
)
@
app
.
route
(
'/api/search/dish'
)
def
search
():
query
=
request
.
args
.
get
(
'name'
)
result
=
Dish
.
query
.
filter
(
Dish
.
name
.
like
(
"
%
"
+
query
+
"
%
"
))
.
all
()
data
=
[]
for
dish
in
result
:
data
.
append
({
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_name'
:
dish
.
stall
.
name
,
'image_path'
:
dish
.
image_path
})
return
jsonify
(
data
)
\ No newline at end of file
canteeneo/views.py
View file @
8401a6ed
...
...
@@ -202,46 +202,6 @@ def unauthorized():
flash
(
'You have to be logged in to view this page!'
)
return
redirect
(
url_for
(
'login'
))
@
app
.
route
(
'/api/all'
)
def
all
():
data
=
{
'update_time'
:
str
(
datetime
.
now
()),
'dishes'
:
[],
'stalls'
:
[],
'locations'
:
[]}
for
dish
in
Dish
.
query
.
all
():
data
[
'dishes'
]
.
append
({
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_id'
:
dish
.
stall_id
,
'image_path'
:
dish
.
image_path
})
for
stall
in
Stall
.
query
.
all
():
data
[
'stalls'
]
.
append
({
'id'
:
stall
.
id
,
'name'
:
stall
.
name
})
for
loc
in
Location
.
query
.
all
():
data
[
'locations'
]
.
append
({
'id'
:
loc
.
id
,
'name'
:
loc
.
name
})
return
jsonify
(
**
data
)
@
app
.
route
(
'/api/search/dish'
)
def
search
():
query
=
request
.
args
.
get
(
'name'
)
result
=
Dish
.
query
.
filter
(
Dish
.
name
.
like
(
"
%
"
+
query
+
"
%
"
))
.
all
()
data
=
[]
for
dish
in
result
:
data
.
append
({
'id'
:
dish
.
id
,
'name'
:
dish
.
name
,
'price'
:
dish
.
price
,
'stall_name'
:
dish
.
stall
.
name
,
'image_path'
:
dish
.
image_path
})
return
jsonify
(
data
)
def
flash_form_errors
(
form
):
for
field
,
errors
in
form
.
errors
.
items
():
for
error
in
errors
:
...
...
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