Unverified Commit e3c373a0 authored by Cédric Bonhomme's avatar Cédric Bonhomme

Fixed conflict.

parents b7509953 19a93946
<<<<<<< HEAD
<<<<<<< HEAD
Shelter Database project news
0.3 (2016-08-02)
* merge the rodekruis repository (https://github.com/rodekruis/shelter-database)
in the LIST repository;
......@@ -11,15 +10,3 @@ Shelter Database project news
0.1 (2016-04-10)
* first stable prototype with base functionalities.
=======
Shelter Database project news
0.1 (2015-03-30)
- initial release.
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
Shelter Database project news
0.1 (2015-03-30)
- initial release.
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
......@@ -4,12 +4,34 @@ API
===
Examples of requests to the Web Service
--------------------------------------
.. code-block:: shell
# Get the list of root categories
$ GET http://127.0.0.1:5000/api/category?q={"filters":[{"name":"parent_id","op":"is_null"}]}
# Get the list of child categories
$ GET http://127.0.0.1:5000/api/category?q={"filters":[{"name":"parent_id","op":"is_not_null"}]}
# Get information about the child category "Walls & Frame"
$ GET http://127.0.0.1:5000/api/category?q={"filters":[{"name":"parent_id","op":"is_not_null"},{"name":"name","op":"eq","val":"Walls %26 frame"}]}
# Get information about an attribute
$ GET http://127.0.0.1:5000/api/attribute?q={"filters":[{"name":"name","op":"eq","val":"Landform"}]}
$ GET http://127.0.0.1:5000/api/attribute?q={"filters":[{"name":"name","op":"eq","val":"Main hazards in country"}]}
# Get the translations of a string
$ GET http://127.0.0.1:5000/api/translation?q={"filters":[{"name":"original","op":"eq","val":"Name of shelter"}]}
=======
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
Web Services
============
Example of requests to the Web Service
<<<<<<< HEAD
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
--------------------------------------
.. code-block:: shell
......@@ -28,6 +50,7 @@ Example of requests to the Web Service
# Get the translations of a string
$ GET http://127.0.0.1:5000/api/translation?q={"filters":[{"name":"original","op":"eq","val":"Name of shelter"}]}
<<<<<<< HEAD
<<<<<<< HEAD
=======
Web Services
============
......@@ -53,3 +76,8 @@ Example of requests to the Web Service
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
......@@ -16,7 +16,35 @@ Request parameters:
Examples
--------
.. code-block:: shell
http://0.0.0.0:5000/api/v0.1
# Welcome message and version info
http://0.0.0.0:5000/api/v0.1/shelters
# Get all shelters and their attributes
http://0.0.0.0:5000/api/v0.1/shelters/3
# Get a specific shelter via shelter ID
http://0.0.0.0:5000/api/v0.1/shelters?attribute=Vegetation
# Get all shelters which have an atttribute value for "Vegetation"
http://0.0.0.0:5000/api/v0.1/shelters?attribute=vegetation&format=prettytext
# Get all shelters which have an atttribute value for "Vegetation", with nicely formatted attribute names
http://0.0.0.0:5000/api/v0.1/attributes/Climate zone
# Get all available values of an attribute
http://0.0.0.0:5000/api/v0.1/shelters/Kitchen type
#get all shelters which have a specific attribute
http://0.0.0.0:5000/api/v0.1/shelters/Kitchen type/open fire
#get all shelters which have a specific attribute value
=======
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
Web Services
============
......@@ -34,7 +62,10 @@ request parameters:
Examples:
<<<<<<< HEAD
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
.. code-block:: shell
......@@ -62,6 +93,7 @@ Examples:
http://0.0.0.0:5000/api/v0.1/shelters/Kitchen type/open fire
#get all shelters which have a specific attribute value
<<<<<<< HEAD
<<<<<<< HEAD
=======
Web Services
============
......@@ -109,3 +141,8 @@ Examples:
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
This diff is collapsed.
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
.. Shelter Database documentation master file, created by
sphinx-quickstart on Sun Jun 19 21:53:46 2016.
You can adapt this file completely to your liking, but it should at least
......@@ -46,47 +50,51 @@ Web Services
<<<<<<< HEAD
api_v0.1
=======
.. Shelter Database documentation master file, created by
sphinx-quickstart on Sun Jun 19 21:53:46 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Presentation
============
The goal of this application is to list the shelters deployed around the world.
The official instance is available `here <https://shelter-database.org>`_.
Deployment
==========
.. toctree::
:maxdepth: 3
deployment
pdf-generation
test-server
Database
========
.. toctree::
:maxdepth: 2
database-schema
database-migrations
Web Services
============
.. toctree::
:maxdepth: 2
api
.. Shelter Database documentation master file, created by
sphinx-quickstart on Sun Jun 19 21:53:46 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Presentation
============
The goal of this application is to list the shelters deployed around the world.
The official instance is available `here <https://shelter-database.org>`_.
Deployment
==========
.. toctree::
:maxdepth: 3
deployment
pdf-generation
test-server
Database
========
.. toctree::
:maxdepth: 2
database-schema
database-migrations
Web Services
============
.. toctree::
:maxdepth: 2
api
>>>>>>> 011351c71fefe44d232b84497307f51ee6d5b501
=======
<<<<<<< HEAD
>>>>>>> b6b3759e10b96db233dac9cadc04365ff404dd97
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
>>>>>>> 19a939463af74c6008ef819369c07cfda36d9d34
......@@ -180,7 +180,11 @@
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")
......
#! /usr/bin/env python
#! /usr/bin/env python
#-*- coding: utf-8 -*-
# ***** BEGIN LICENSE BLOCK *****
......@@ -27,22 +27,22 @@ 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 +65,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 +77,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'
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 +114,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)]
else:
result[picture.shelter_id]["shelterpicture"][picture.name].append("{}/{}/{}".format(picpath, result[picture.shelter_id]["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)]
else:
result[picture.shelter_id]["shelterpicture"][picture.name].append("{}/{}/{}".format(picpath, result[picture.shelter_id]["id"], picture.filename))
return jsonify(result)
......@@ -148,13 +148,13 @@ def allshelters():
def shelters(shelter_id):
"""Returns specific shelter with its properties"""
result = tree()
## 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:
......@@ -172,12 +172,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,4 +195,3 @@ def fulltext(searchstring):
#print(shelter_property)
result[shelter_property.shelter_id]
return jsonify(result)
......@@ -61,7 +61,7 @@ def authentication_required(e):
@current_app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@current_app.route('/map', methods=['GET'])
def map():
"""
......@@ -137,7 +137,7 @@ def shelters_for_map():
def dashboard():
# return render_template('dashboard0.html')
return render_template('dashboard.html')
@current_app.route('/shelters', methods=['GET'])
def shelters():
shelters = Shelter.query.filter(Shelter.is_published==True).all()
......@@ -155,14 +155,14 @@ def stats():
@current_app.route('/knowledgebase', methods=['GET'])
def knowledgebase():
return render_template('knowledgebase.html')
@current_app.route('/contribute', methods=['GET'])
def contribute():
"""
List of contributors.
"""
return render_template('contribute.html')
@current_app.route('/contributors', methods=['GET'])
def contributors():
"""
......
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