Commit 18b7a4f2 authored by Cédric Bonhomme's avatar Cédric Bonhomme

Fixed conflicts.

parents 19a93946 3eae8b3a
......@@ -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>');
......
......@@ -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);
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
// 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
......
#! /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)
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment