Commit 19a93946 authored by Cédric Bonhomme's avatar Cédric Bonhomme

Fixed conflicts.

parent 15df3aa0
#! /usr/bin/env python
#! /usr/bin/env python
#-*- coding: utf-8 -*-
# ***** BEGIN LICENSE BLOCK *****
......@@ -27,36 +27,22 @@ def tree():
return defaultdict(tree)
def queryfactory(model,join=False,filt=False,value=False):
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
#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])
<<<<<<< HEAD
else:
return obj.filter(attrib.in_(val))
=======
else:
return obj.filter(attrib.in_(val))
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
def filter_and(obj,attrib,val):
"""Construct filtering methods recursively (AND)"""
list(val)
if len(val) == 1:
return obj.filter(attrib == val[0])
<<<<<<< HEAD
else:
=======
else:
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
return filter_and(obj.filter(attrib == val[len(val)-1]),attrib, val[0:len(val)-1])
if join and not filt:
......@@ -79,17 +65,10 @@ def apimessage():
def getattributes(attribute_name, safetext=False):
"""Returns available values for a given attribute name, separated by semicolons"""
result= tree()
<<<<<<< HEAD
attributes = Attribute.query.filter(Attribute.uniqueid==attribute_name).\
first().associated_values
=======
attributes = Attribute.query.filter(Attribute.uniqueid==attribute_name).\
first().associated_values
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
result[attribute_name] = ";".join([attribute.name for attribute in attributes])
return jsonify(result)
......@@ -98,23 +77,15 @@ def getattributes(attribute_name, safetext=False):
def allshelters():
"""Returns all shelters and their properties"""
result = tree()
<<<<<<< HEAD
#shelter pictures folder path
picpath = 'data/shelters/pictures'
=======
#shelter pictures folder path
picpath = 'data/shelters/pictures'
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
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)
<<<<<<< HEAD
picquerybase = db.session.query(ShelterPicture.shelter_id, ShelterPicture.file_name.label("filename"), Category.name)\
.join(Category, Category.id == ShelterPicture.category_id)
......@@ -126,28 +97,11 @@ def allshelters():
if request.args.getlist('attribute'):
attribute = request.args.getlist('attribute')
=======
picquerybase = db.session.query(ShelterPicture.shelter_id, ShelterPicture.file_name.label("filename"), Category.name)\
.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')
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
subquery = db.session.query(Property.shelter_id)\
.join(Attribute, Attribute.id==Property.attribute_id)\
.filter(Attribute.uniqueid.in_(attribute))\
.group_by(Property.shelter_id)
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
shelter_properties = querybase.filter(subquery.subquery().c.shelter_id==Property.shelter_id)
shelter_pictures = picquerybase.filter(subquery.subquery().c.shelter_id==ShelterPicture.shelter_id)
......@@ -160,7 +114,6 @@ def allshelters():
.group_by(Property.shelter_id)
else:
subquery = subquery.filter(Property.values.any(Value.name.in_(value)))
<<<<<<< HEAD
shelter_properties = querybase.filter(subquery.subquery().c.shelter_id==Property.shelter_id)
shelter_pictures = picquerybase.filter(subquery.subquery().c.shelter_id==ShelterPicture.shelter_id)
......@@ -172,47 +125,22 @@ def allshelters():
for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.name] = shelter_property.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
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
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))
<<<<<<< HEAD
else:
for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.uniqueid] = shelter_property.value
=======
else:
for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.uniqueid] = shelter_property.value
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
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))
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
return jsonify(result)
......@@ -220,21 +148,13 @@ def allshelters():
def shelters(shelter_id):
"""Returns specific shelter with its properties"""
result = tree()
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
## 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)
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
## shelter property query
shelter_properties = Property.query.filter(Property.shelter_id==shelter_id)
for shelter_property in shelter_properties:
......@@ -252,21 +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))
<<<<<<< HEAD
for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.attribute.uniqueid] = shelter_property.get_values_as_string()
return jsonify(result)
=======
for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.attribute.uniqueid] = shelter_property.get_values_as_string()
return jsonify(result)
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
@api_bp.route('/shelters/search/<searchstring>', methods=['GET'])
def fulltext(searchstring):
"""Returns shelter id's which match the search criteria. Uses full text search'"""
......@@ -284,7 +195,3 @@ def fulltext(searchstring):
#print(shelter_property)
result[shelter_property.shelter_id]
return jsonify(result)
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
......@@ -61,11 +61,7 @@ def authentication_required(e):
@current_app.route('/', methods=['GET'])
def index():
return render_template('index.html')
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
@current_app.route('/map', methods=['GET'])
def map():
"""
......@@ -141,11 +137,7 @@ def shelters_for_map():
def dashboard():
# return render_template('dashboard0.html')
return render_template('dashboard.html')
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
@current_app.route('/shelters', methods=['GET'])
def shelters():
shelters = Shelter.query.filter(Shelter.is_published==True).all()
......@@ -163,22 +155,14 @@ def stats():
@current_app.route('/knowledgebase', methods=['GET'])
def knowledgebase():
return render_template('knowledgebase.html')
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
@current_app.route('/contribute', methods=['GET'])
def contribute():
"""
List of contributors.
"""
return render_template('contribute.html')
<<<<<<< HEAD
=======
>>>>>>> 56b170c62373521aae3518c6fece0335e0e06ec5
@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