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
219bc211
Commit
219bc211
authored
Aug 24, 2016
by
Cédric Bonhomme
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/rodekruis/shelter-database
parents
62c31a19
169a8f1c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
src/web/views/shelterapiv02.py
src/web/views/shelterapiv02.py
+27
-4
No files found.
src/web/views/shelterapiv02.py
View file @
219bc211
...
...
@@ -17,15 +17,15 @@ __license__ = ""
#from bootstrap import db
from
bootstrap
import
db
,
app
from
sqlalchemy.sql
import
func
,
select
from
flask
import
Blueprint
,
jsonify
,
request
,
json
from
flask
import
Blueprint
,
jsonify
,
request
,
json
,
Response
from
collections
import
defaultdict
from
web.models
import
Shelter
,
Attribute
,
Property
,
Value
,
Association
,
ShelterPicture
,
Category
,
Tsvector
from
web.models
import
Shelter
,
Attribute
,
Property
,
Value
,
Association
,
ShelterPicture
,
Category
,
Tsvector
,
Translation
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
()
...
...
@@ -49,10 +49,33 @@ def getattributes(attribute_name, safetext=False):
attributes
=
Attribute
.
query
.
filter
(
Attribute
.
uniqueid
==
attribute_name
).
\
first
().
associated_values
result
[
attribute_name
]
=
";"
.
join
([
attribute
.
name
for
attribute
in
attributes
])
return
jsonify
(
result
)
@
apiv02_bp
.
route
(
'/translation'
,
methods
=
[
'GET'
])
def
available_translations
():
result
=
tree
()
subquery
=
db
.
session
.
query
(
Translation
.
language_code
).
group_by
(
Translation
.
language_code
).
subquery
()
available_languages
=
db
.
session
.
query
(
func
.
string_agg
(
subquery
.
c
.
language_code
,
';'
)).
first
()
#for language in available_languages
result
[
"languages"
]
=
available_languages
[
0
]
return
jsonify
(
result
)
@
apiv02_bp
.
route
(
'/translation/<language>'
,
methods
=
[
'GET'
])
def
translations
(
language
=
None
):
result
=
tree
()
query
=
Translation
.
query
.
filter
(
Translation
.
language_code
==
language
)
for
item
in
query
:
result
[
item
.
original
]
=
item
.
translated
return
Response
(
json
.
dumps
(
result
,
indent
=
3
),
mimetype
=
'application/json;charset=utf-8'
)
@
apiv02_bp
.
route
(
'/shelters'
,
methods
=
[
'GET'
])
@
apiv02_bp
.
route
(
'/shelters/<int:shelter_id>'
,
methods
=
[
'GET'
])
def
allshelters
(
shelter_id
=
None
):
...
...
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