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