Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Shelter Database
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
CHARISM
Shelter Database
Commits
2b11291f
Commit
2b11291f
authored
Jul 31, 2016
by
Aron Gergely
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved sqlalchemy querying for API "/shelters" resource
parent
20c456b5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
src/web/views/shelterapi.py
src/web/views/shelterapi.py
+11
-4
No files found.
src/web/views/shelterapi.py
View file @
2b11291f
...
...
@@ -14,6 +14,9 @@ __revision__ = ""
__copyright__
=
""
__license__
=
""
#from bootstrap import db
from
bootstrap
import
db
from
sqlalchemy.sql
import
func
from
flask
import
Blueprint
,
jsonify
,
request
from
collections
import
defaultdict
from
web.models
import
Shelter
,
Attribute
,
Property
,
Value
,
Association
...
...
@@ -83,7 +86,12 @@ def allshelters():
subquery
=
queryfactory
(
Property
,
Attribute
,
Attribute
.
uniqueid
,
attr
).
subquery
()
shelter_properties
=
Property
.
query
.
filter
(
Property
.
shelter_id
==
subquery
.
c
.
shelter_id
).
all
()
else
:
shelter_properties
=
Property
.
query
.
all
()
shelter_properties
=
db
.
session
.
query
(
Property
.
shelter_id
,
Attribute
.
name
,
func
.
string_agg
(
Value
.
name
,
"';'"
).
label
(
"value"
))
\
.
join
(
Attribute
)
\
.
join
(
Association
,
Property
.
id
==
Association
.
property_id
)
\
.
join
(
Value
,
Association
.
value_id
==
Value
.
id
)
\
.
group_by
(
Property
.
shelter_id
,
Attribute
.
name
)
print
(
shelter_properties
)
## value parameter listening
if
request
.
args
.
getlist
(
'attribute'
)
and
request
.
args
.
getlist
(
'value'
):
...
...
@@ -98,8 +106,7 @@ def allshelters():
result
[
shelter_property
.
shelter_id
][
shelter_property
.
attribute
.
name
]
=
shelter_property
.
get_values_as_string
()
else
:
for
shelter_property
in
shelter_properties
:
result
[
shelter_property
.
shelter_id
][
shelter_property
.
attribute
.
uniqueid
]
=
shelter_property
.
get_values_as_string
()
result
[
shelter_property
.
shelter_id
][
shelter_property
.
name
]
=
shelter_property
.
value
return
jsonify
(
result
)
...
...
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