Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CHARISM
Shelter Database
Commits
d9497249
Commit
d9497249
authored
Sep 05, 2016
by
Aron Gergely
Browse files
API '/shelters' resource always returns category names
parent
2f02e7a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/web/views/shelterapiv02.py
View file @
d9497249
...
...
@@ -27,12 +27,12 @@ apiv02_bp = Blueprint('development api v0.2', __name__, url_prefix='/api/v0.2')
def
tree
():
return
defaultdict
(
tree
)
@
apiv02_bp
.
route
(
'/'
,
methods
=
[
'GET'
])
def
apimessage
():
message
=
tree
()
message
[
"API version"
]
=
0.2
message
[
"Message"
]
=
"This is the development API"
defaultjson
()
return
jsonify
(
message
)
@
apiv02_bp
.
route
(
'/documentation'
,
methods
=
[
'GET'
])
...
...
@@ -163,6 +163,7 @@ def allshelters(shelter_id=None):
picquerybase
=
db
.
session
.
query
(
ShelterPicture
.
shelter_id
,
ShelterPicture
.
file_name
.
label
(
"filename"
),
ShelterPicture
.
is_main_picture
,
Category
.
name
)
\
.
join
(
Category
,
Category
.
id
==
ShelterPicture
.
category_id
)
catquery
=
db
.
session
.
query
(
Category
.
name
).
filter
(
Category
.
section_id
!=
None
)
##queries if no request arguments
shelter_properties
=
querybase
shelter_pictures
=
picquerybase
...
...
@@ -203,21 +204,25 @@ def allshelters(shelter_id=None):
#print(shelter_properties)
#print(shelter_pictures)
print
(
catquery
)
if
request
.
args
.
get
(
'format'
)
==
'prettytext'
:
for
shelter_property
in
shelter_properties
:
if
not
result
[
shelter_property
.
shelter_id
]:
for
category
in
catquery
:
if
category
.
name
==
"Identification"
:
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Cover"
]
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Attributes"
]
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Pictures"
]
result
[
shelter_property
.
shelter_id
][
shelter_property
.
supercategory_name
][
"Attributes"
][
shelter_property
.
name
]
=
shelter_property
.
value
for
picture
in
shelter_pictures
:
if
picture
.
is_main_picture
==
True
:
result
[
picture
.
shelter_id
][
"Identification"
][
"Cover"
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
)]
elif
not
result
[
picture
.
shelter_id
][
picture
.
name
][
"Pictures"
]:
result
[
picture
.
shelter_id
][
picture
.
name
][
"Pictures"
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
)]
else
:
result
[
picture
.
shelter_id
][
picture
.
name
][
"Pictures"
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
))
else
:
for
shelter_property
in
shelter_properties
:
if
not
result
[
shelter_property
.
shelter_id
]:
for
category
in
catquery
:
if
category
.
name
==
"Identification"
:
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Cover"
]
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Attributes"
]
result
[
shelter_property
.
shelter_id
][
category
.
name
][
"Pictures"
]
result
[
shelter_property
.
shelter_id
][
shelter_property
.
supercategory_name
][
"Attributes"
][
shelter_property
.
uniqueid
]
=
shelter_property
.
value
for
picture
in
shelter_pictures
:
...
...
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