Commit 169a8f1c authored by Aron Gergely's avatar Aron Gergely
Browse files

Added '/translation' resource to API

parent befc7c6c
...@@ -17,15 +17,15 @@ __license__ = "" ...@@ -17,15 +17,15 @@ __license__ = ""
#from bootstrap import db #from bootstrap import db
from bootstrap import db, app from bootstrap import db, app
from sqlalchemy.sql import func, select from sqlalchemy.sql import func, select
from flask import Blueprint, jsonify, request, json from flask import Blueprint, jsonify, request, json, Response
from collections import defaultdict from collections import defaultdict
from web.models import Shelter, Attribute, Property, Value, Association, ShelterPicture, Category, Tsvector from web.models import Shelter, Attribute, Property, Value, Association, ShelterPicture, Category, Tsvector, Translation
apiv02_bp = Blueprint('development api v0.2', __name__, url_prefix='/api/v0.2') apiv02_bp = Blueprint('development api v0.2', __name__, url_prefix='/api/v0.2')
def tree(): def tree():
return defaultdict(tree) return defaultdict(tree)
@apiv02_bp.route('/', methods=['GET']) @apiv02_bp.route('/', methods=['GET'])
def apimessage(): def apimessage():
message = tree() message = tree()
...@@ -49,10 +49,33 @@ def getattributes(attribute_name, safetext=False): ...@@ -49,10 +49,33 @@ def getattributes(attribute_name, safetext=False):
attributes = Attribute.query.filter(Attribute.uniqueid==attribute_name).\ attributes = Attribute.query.filter(Attribute.uniqueid==attribute_name).\
first().associated_values first().associated_values
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)
@apiv02_bp.route('/translation', methods=['GET'])
def available_translations():
result = tree()
subquery = db.session.query(Translation.language_code).group_by(Translation.language_code).subquery()
available_languages = db.session.query(func.string_agg(subquery.c.language_code, ';')).first()
#for language in available_languages
result["languages"]= available_languages[0]
return jsonify(result)
@apiv02_bp.route('/translation/<language>', methods=['GET'])
def translations(language=None):
result = tree()
query = Translation.query.filter(Translation.language_code==language)
for item in query:
result[item.original]=item.translated
return Response(json.dumps(result, indent=3), mimetype='application/json;charset=utf-8')
@apiv02_bp.route('/shelters', methods=['GET']) @apiv02_bp.route('/shelters', methods=['GET'])
@apiv02_bp.route('/shelters/<int:shelter_id>', methods=['GET']) @apiv02_bp.route('/shelters/<int:shelter_id>', methods=['GET'])
def allshelters(shelter_id=None): def allshelters(shelter_id=None):
......
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