def get_references(self):
"""returns the references of this project
"""
sql = """select
rse.id,
rse.name,
rse.entity_type
from "Project_References" as pr
join "SimpleEntities" as rse on pr.link_id = rse.id
where pr.project_id = :id
union
select
rse.id,
rse.name,
rse.entity_type
from "Task_References" as tr
join "Tasks" as t on tr.task_id = t.id
join "SimpleEntities" as rse on tr.link_id = rse.id
where t.project_id = :id
"""
from stalker.db.session import DBSession
from sqlalchemy import text
conn = DBSession.connection()
result = conn.execute(text(sql), id=self.entity_id).fetchall()
from stalker_pyramid import entity_type_to_url
project_ref_data = [
{
'id': r[0],
'name': r[1],
'entity_type': r[2],
'$ref': '%s/%s' % (entity_type_to_url[r[2]], r[0])
} for r in result
]
from pyramid.response import Response
return Response(json_body=project_ref_data, status=200)
评论列表
文章目录