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
18b7a4f2
Unverified
Commit
18b7a4f2
authored
Sep 07, 2016
by
Cédric Bonhomme
Browse files
Fixed conflicts.
parents
19a93946
3eae8b3a
Changes
14
Hide whitespace changes
Inline
Side-by-side
src/web/static/js/d2utmpx5icup
0 → 100644
View file @
18b7a4f2
src/web/static/js/dashboard.js
View file @
18b7a4f2
...
...
@@ -541,8 +541,17 @@ generateShelterList = function (data) {
$
(
'
#shelterList
'
).
empty
();
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
// get url from api data if pictures exist
var
url
=
''
;
if
(
typeof
(
data
[
i
].
shelterpicture
)
!==
'
undefined
'
&&
Object
.
keys
(
data
[
i
].
shelterpicture
).
length
>
0
){
for
(
var
prop
in
data
[
i
].
shelterpicture
)
{
url
=
data
[
i
].
shelterpicture
[
prop
][
0
];
break
;
}
}
var
shelter
=
$
(
'
<div class="shelter"/>
'
).
appendTo
(
'
#shelterList
'
);
shelter
.
append
(
'
<div class="image" style="background-image: url(
'
+
''
+
'
)"></div>
'
+
shelter
.
append
(
'
<div class="image" style="background-image: url(
\'
/
'
+
url
+
'
\
'
)"></div>
'
+
'
<h4 class="title"><a href="/shelter/
'
+
data
[
i
].
db_id
+
'
">
'
+
data
[
i
].
nameofshelter
+
'
</a></h4>
'
+
'
<div class="country">
'
+
data
[
i
].
country
+
'
</div>
'
+
'
<div class="description"><p>
'
+
''
+
'
</p></div>
'
);
...
...
src/web/static/pictures/shelters/12/CRC A_Foundation_Strip.jpg
0 → 100644
View file @
18b7a4f2
1.64 MB
src/web/static/pictures/shelters/12/CRC A_Foundation_Strip2.jpg
0 → 100644
View file @
18b7a4f2
1.73 MB
src/web/static/pictures/shelters/12/CRC A_Framed walls_Assembling (2).jpg
0 → 100644
View file @
18b7a4f2
1.77 MB
src/web/static/pictures/shelters/12/CRC A_Framed walls_Assembling.jpg
0 → 100644
View file @
18b7a4f2
1.97 MB
src/web/static/pictures/shelters/12/CRC A_Framed walls_Preassembled.jpg
0 → 100644
View file @
18b7a4f2
2.13 MB
src/web/static/pictures/shelters/12/CRC A_Identification_Facade.jpg
0 → 100644
View file @
18b7a4f2
1.02 MB
src/web/static/pictures/shelters/12/CRC A_Identification_Satellite.jpg
0 → 100644
View file @
18b7a4f2
177 KB
src/web/static/pictures/shelters/12/CRC A_Roof_Trusses (2).jpg
0 → 100644
View file @
18b7a4f2
1.41 MB
src/web/static/pictures/shelters/12/CRC A_Roof_Trusses.jpg
0 → 100644
View file @
18b7a4f2
588 KB
src/web/templates/shelter.html
View file @
18b7a4f2
...
...
@@ -24,14 +24,18 @@
<div
class=
"dot"
></div>
</div>
</section>
<section
class=
"details"
>
<div
class=
"content"
>
<table
id=
"identification"
>
<tr>
<td>
No data available in this category
</td>
</tr>
</table>
</div>
<section>
<div
class=
"details"
>
<h3>
Identification
</h3>
<div
id=
"location-map"
style=
"width:100%; height:400px;"
></div>
<div
class=
"content"
>
<table
id=
"identification"
>
<tr>
<td>
No data available in this category
</td>
</tr>
</table>
</div>
</div>
</section>
<section
class=
"details details-1"
>
<div
class=
"content"
>
...
...
@@ -43,11 +47,6 @@
</table>
</div>
</section>
<section>
<div
class=
"details"
>
<div
id=
"location-map"
style=
"width:100%; height:400px;"
></div>
</div>
</section>
<section
class=
"details details-2"
>
<div
class=
"content"
>
<h3>
Disaster
&
Response
</h3>
...
...
@@ -140,12 +139,17 @@
if
(
typeof
data
[
shelter_id
][
'
Foundation
'
]
!==
'
undefined
'
)
{
var
foundation
=
data
[
shelter_id
][
'
Foundation
'
][
'
Attributes
'
];
$
(
"
#foundation
"
).
empty
();
tabulate
(
"
#foundation
"
,
foundation
,
d3
.
keys
(
general
));
tabulate
(
"
#foundation
"
,
foundation
,
d3
.
keys
(
foundation
));
}
if
(
typeof
data
[
shelter_id
][
'
Identification
'
]
!==
'
undefined
'
)
{
// Set shelter name
$
(
'
#shelter-name
'
).
text
(
data
[
shelter_id
][
'
Identification
'
][
'
Attributes
'
][
'
Name of shelter
'
]);
// add attributes
var
identification
=
data
[
shelter_id
][
'
Identification
'
][
'
Attributes
'
];
$
(
"
#identification
"
).
empty
();
tabulate
(
"
#identification
"
,
identification
,
d3
.
keys
(
identification
));
// Get coordinates for this shelter
var
lat
=
data
[
shelter_id
][
'
Identification
'
][
'
Attributes
'
][
'
GPS Latitude
'
];
...
...
@@ -172,7 +176,7 @@
function
addCoverPicture
(
elementId
,
section
){
if
(
typeof
section
[
'
Cover
'
]
!==
'
undefined
'
&&
section
[
'
Cover
'
].
length
>
0
)
{
$
(
elementId
).
css
(
"
background-image
"
,
"
url('
"
+
section
[
'
Cover
'
][
0
]
+
"
')
"
);
$
(
elementId
).
css
(
"
background-image
"
,
"
url('
/
"
+
section
[
'
Cover
'
][
0
]
+
"
')
"
);
}
}
...
...
@@ -180,11 +184,7 @@
if
(
typeof
section
[
'
Pictures
'
]
!==
'
undefined
'
)
{
//merge arrays
<<<<<<<
HEAD
var
d
=
section
[
'
Cover
'
].
concat
(
section
[
'
Pictures
'
]);
=======
var
d
=
$
.
merge
(
section
.
Cover
,
section
.
Pictures
);
>>>>>>>
56
b170c62373521aae3518c6fece0335e0e06ec5
// add panes
d3
.
select
(
elementId
+
"
Panes
"
)
...
...
@@ -193,7 +193,7 @@
.
enter
()
.
append
(
"
div
"
)
.
attr
(
"
class
"
,
"
pane
"
)
.
attr
(
"
style
"
,
function
(
d
){
return
"
background-image: url('
"
+
d
+
"
')
"
;});
.
attr
(
"
style
"
,
function
(
d
){
return
"
background-image: url('
/
"
+
d
+
"
')
"
;});
// add dots
// TODO increment show id
...
...
src/web/views/shelterapi.py
View file @
18b7a4f2
#! /usr/bin/env python
#! /usr/bin/env python
#-*- coding: utf-8 -*-
# ***** BEGIN LICENSE BLOCK *****
...
...
@@ -21,28 +21,30 @@ from flask import Blueprint, jsonify, request
from
collections
import
defaultdict
from
web.models
import
Shelter
,
Attribute
,
Property
,
Value
,
Association
,
ShelterPicture
,
Category
,
Tsvector
import
conf
,
os
.
path
api_bp
=
Blueprint
(
'api for shelter'
,
__name__
,
url_prefix
=
'/api/v0.1'
)
def
tree
():
return
defaultdict
(
tree
)
def
queryfactory
(
model
,
join
=
False
,
filt
=
False
,
value
=
False
):
#helper functions to construct queries
def
filter_or
(
obj
,
attrib
,
val
):
"""Construct filtering method (OR)"""
list
(
val
)
if
len
(
val
)
==
1
:
return
obj
.
filter
(
attrib
==
val
[
0
])
else
:
else
:
return
obj
.
filter
(
attrib
.
in_
(
val
))
def
filter_and
(
obj
,
attrib
,
val
):
"""Construct filtering methods recursively (AND)"""
list
(
val
)
if
len
(
val
)
==
1
:
return
obj
.
filter
(
attrib
==
val
[
0
])
else
:
else
:
return
filter_and
(
obj
.
filter
(
attrib
==
val
[
len
(
val
)
-
1
]),
attrib
,
val
[
0
:
len
(
val
)
-
1
])
if
join
and
not
filt
:
...
...
@@ -65,10 +67,10 @@ def apimessage():
def
getattributes
(
attribute_name
,
safetext
=
False
):
"""Returns available values for a given attribute name, separated by semicolons"""
result
=
tree
()
attributes
=
Attribute
.
query
.
filter
(
Attribute
.
uniqueid
==
attribute_name
).
\
first
().
associated_values
result
[
attribute_name
]
=
";"
.
join
([
attribute
.
name
for
attribute
in
attributes
])
return
jsonify
(
result
)
...
...
@@ -77,31 +79,31 @@ def getattributes(attribute_name, safetext=False):
def
allshelters
():
"""Returns all shelters and their properties"""
result
=
tree
()
#shelter pictures folder path
picpath
=
'data/shelters/pictures'
picpath
=
os
.
path
.
relpath
(
conf
.
SHELTERS_PICTURES_PATH
)
querybase
=
db
.
session
.
query
(
Property
.
shelter_id
,
Attribute
.
name
,
Attribute
.
uniqueid
,
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
,
Attribute
.
uniqueid
)
picquerybase
=
db
.
session
.
query
(
ShelterPicture
.
shelter_id
,
ShelterPicture
.
file_name
.
label
(
"filename"
),
Category
.
name
)
\
.
join
(
Category
,
Category
.
id
==
ShelterPicture
.
category_id
)
.
join
(
Category
,
Category
.
id
==
ShelterPicture
.
category_id
)
##queries if no request arguments
shelter_properties
=
querybase
shelter_pictures
=
picquerybase
if
request
.
args
.
getlist
(
'attribute'
):
attribute
=
request
.
args
.
getlist
(
'attribute'
)
attribute
=
request
.
args
.
getlist
(
'attribute'
)
subquery
=
db
.
session
.
query
(
Property
.
shelter_id
)
\
.
join
(
Attribute
,
Attribute
.
id
==
Property
.
attribute_id
)
\
.
filter
(
Attribute
.
uniqueid
.
in_
(
attribute
))
\
.
group_by
(
Property
.
shelter_id
)
shelter_properties
=
querybase
.
filter
(
subquery
.
subquery
().
c
.
shelter_id
==
Property
.
shelter_id
)
shelter_pictures
=
picquerybase
.
filter
(
subquery
.
subquery
().
c
.
shelter_id
==
ShelterPicture
.
shelter_id
)
...
...
@@ -114,33 +116,33 @@ def allshelters():
.
group_by
(
Property
.
shelter_id
)
else
:
subquery
=
subquery
.
filter
(
Property
.
values
.
any
(
Value
.
name
.
in_
(
value
)))
shelter_properties
=
querybase
.
filter
(
subquery
.
subquery
().
c
.
shelter_id
==
Property
.
shelter_id
)
shelter_pictures
=
picquerybase
.
filter
(
subquery
.
subquery
().
c
.
shelter_id
==
ShelterPicture
.
shelter_id
)
#print(shelter_properties)
#print(shelter_pictures)
if
request
.
args
.
get
(
'format'
)
==
'prettytext'
:
for
shelter_property
in
shelter_properties
:
result
[
shelter_property
.
shelter_id
][
shelter_property
.
name
]
=
shelter_property
.
value
for
picture
in
shelter_pictures
:
if
not
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
result
[
picture
.
shelter_id
][
"ID"
]
,
picture
.
filename
)]
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
)]
else
:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
result
[
picture
.
shelter_id
][
"ID"
]
,
picture
.
filename
))
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
))
else
:
for
shelter_property
in
shelter_properties
:
result
[
shelter_property
.
shelter_id
][
shelter_property
.
uniqueid
]
=
shelter_property
.
value
for
picture
in
shelter_pictures
:
if
not
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
result
[
picture
.
shelter_id
][
"id"
]
,
picture
.
filename
)]
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
)]
else
:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
result
[
picture
.
shelter_id
][
"id"
]
,
picture
.
filename
))
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
))
return
jsonify
(
result
)
...
...
@@ -148,19 +150,25 @@ def allshelters():
def
shelters
(
shelter_id
):
"""Returns specific shelter with its properties"""
result
=
tree
()
#shelter pictures folder path
picpath
=
os
.
path
.
relpath
(
conf
.
SHELTERS_PICTURES_PATH
)
## shelter picture query
shelter_pictures
=
db
.
session
.
query
(
ShelterPicture
.
shelter_id
,
func
.
string_agg
(
ShelterPicture
.
file_name
,
';'
).
label
(
"filename"
),
Category
.
name
)
\
.
join
(
Category
,
Category
.
id
==
ShelterPicture
.
category_id
)
\
.
group_by
(
ShelterPicture
.
shelter_id
,
Category
.
name
)
\
.
filter
(
ShelterPicture
.
shelter_id
==
shelter_id
)
## shelter property query
shelter_properties
=
Property
.
query
.
filter
(
Property
.
shelter_id
==
shelter_id
)
for
shelter_property
in
shelter_properties
:
result
[
shelter_property
.
shelter_id
][
shelter_property
.
attribute
.
uniqueid
]
=
shelter_property
.
get_values_as_string
()
for
picture
in
shelter_pictures
:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
picture
.
filename
if
not
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
]
=
[
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
)]
else
:
result
[
picture
.
shelter_id
][
"shelterpicture"
][
picture
.
name
].
append
(
"{}/{}/{}"
.
format
(
picpath
,
picture
.
shelter_id
,
picture
.
filename
))
return
jsonify
(
result
)
@
api_bp
.
route
(
'/shelters/<attribute_name>'
,
methods
=
[
'GET'
])
...
...
@@ -172,12 +180,12 @@ def attributes(attribute_name, attribute_value=''):
shelter_properties
=
Property
.
query
.
filter
(
Property
.
attribute
.
has
(
uniqueid
=
attribute_name
))
else
:
shelter_properties
=
Property
.
query
.
filter
(
Property
.
attribute
.
has
(
uniqueid
=
attribute_name
),
Property
.
values
.
any
(
name
=
attribute_value
))
for
shelter_property
in
shelter_properties
:
result
[
shelter_property
.
shelter_id
][
shelter_property
.
attribute
.
uniqueid
]
=
shelter_property
.
get_values_as_string
()
return
jsonify
(
result
)
@
api_bp
.
route
(
'/shelters/search/<searchstring>'
,
methods
=
[
'GET'
])
def
fulltext
(
searchstring
):
"""Returns shelter id's which match the search criteria. Uses full text search'"""
...
...
@@ -195,3 +203,4 @@ def fulltext(searchstring):
#print(shelter_property)
result
[
shelter_property
.
shelter_id
]
return
jsonify
(
result
)
src/web/views/shelterapiv02.py
View file @
18b7a4f2
...
...
@@ -14,13 +14,13 @@ __revision__ = ""
__copyright__
=
""
__license__
=
""
#from bootstrap import db
from
bootstrap
import
db
,
app
from
sqlalchemy.sql
import
func
,
select
from
flask
import
Blueprint
,
jsonify
,
request
,
json
,
Response
from
collections
import
defaultdict
from
web.models
import
Shelter
,
Attribute
,
Property
,
Value
,
Association
,
ShelterPicture
,
Category
,
Tsvector
,
Translation
import
conf
,
os
.
path
apiv02_bp
=
Blueprint
(
'development api v0.2'
,
__name__
,
url_prefix
=
'/api/v0.2'
)
...
...
@@ -148,7 +148,9 @@ def allshelters(shelter_id=None):
result
=
tree
()
#shelter pictures folder path
picpath
=
'/public/pictures/shelters'
picpath
=
os
.
path
.
relpath
(
conf
.
SHELTERS_PICTURES_PATH
)
Supercategory
=
db
.
aliased
(
Category
)
...
...
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