api.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:iris 作者: linkedin 项目源码 文件源码
def on_get(self, req, resp, template_id):
            if template_id.isdigit():
                where = 'WHERE `template`.`id` = %s'
            else:
                where = 'WHERE `template`.`name` = %s AND `template_active`.`template_id` IS NOT NULL'
            query = single_template_query + where

            connection = db.engine.raw_connection()
            cursor = connection.cursor()
            cursor.execute(query, template_id)
            results = cursor.fetchall()

            if results:
                r = results[0]
                t = {
                    'id': r[0],
                    'name': r[1],
                    'active': r[2],
                    'creator': r[3],
                    'created': r[4]
                }
                content = {}
                for r in results:
                    content.setdefault(r[5], {})[r[6]] = {'subject': r[7], 'body': r[8]}
                t['content'] = content
                cursor = connection.cursor(db.dict_cursor)
                cursor.execute(single_template_query_plans, t['name'])
                t['plans'] = cursor.fetchall()
                connection.close()
                payload = ujson.dumps(t)
            else:
                raise HTTPNotFound()
            resp.status = HTTP_200
            resp.body = payload
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号