Commit d0cef508 authored by Krystyna Milian's avatar Krystyna Milian
parents 5fd683db 2b11291f
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -14,6 +14,9 @@ __revision__ = "" ...@@ -14,6 +14,9 @@ __revision__ = ""
__copyright__ = "" __copyright__ = ""
__license__ = "" __license__ = ""
#from bootstrap import db
from bootstrap import db
from sqlalchemy.sql import func
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
from collections import defaultdict from collections import defaultdict
from web.models import Shelter, Attribute, Property, Value, Association from web.models import Shelter, Attribute, Property, Value, Association
...@@ -83,7 +86,12 @@ def allshelters(): ...@@ -83,7 +86,12 @@ def allshelters():
subquery = queryfactory(Property,Attribute,Attribute.uniqueid,attr).subquery() subquery = queryfactory(Property,Attribute,Attribute.uniqueid,attr).subquery()
shelter_properties = Property.query.filter(Property.shelter_id==subquery.c.shelter_id).all() shelter_properties = Property.query.filter(Property.shelter_id==subquery.c.shelter_id).all()
else: else:
shelter_properties = Property.query.all() shelter_properties = db.session.query(Property.shelter_id,Attribute.name,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)
print(shelter_properties)
## value parameter listening ## value parameter listening
if request.args.getlist('attribute') and request.args.getlist('value'): if request.args.getlist('attribute') and request.args.getlist('value'):
...@@ -91,15 +99,14 @@ def allshelters(): ...@@ -91,15 +99,14 @@ def allshelters():
subquery = Property.query.filter(Property.attribute.has(Attribute.uniqueid.in_(attr)), Property.values.any(Value.name.in_(valu))).subquery() subquery = Property.query.filter(Property.attribute.has(Attribute.uniqueid.in_(attr)), Property.values.any(Value.name.in_(valu))).subquery()
shelter_properties = Property.query.filter(Property.shelter_id==subquery.c.shelter_id).all() shelter_properties = Property.query.filter(Property.shelter_id==subquery.c.shelter_id).all()
## format parameter listening and populate defaultict ## format parameter listening and populate defaultict
if request.args.get('format') == 'prettytext': if request.args.get('format') == 'prettytext':
for shelter_property in shelter_properties: for shelter_property in shelter_properties:
result[shelter_property.shelter_id][shelter_property.attribute.name] = shelter_property.get_values_as_string() result[shelter_property.shelter_id][shelter_property.attribute.name] = shelter_property.get_values_as_string()
else: else:
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.name] = shelter_property.value
return jsonify(result) return jsonify(result)
......
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