views.py 文件源码

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

项目:morpheus 作者: tutorcruncher 项目源码 文件源码
def call(self, request):
        es_query = {
            'bool': {
                'filter': [
                    {'match_all': {}}
                    if self.session.company == '__all__' else
                    {'term': {'company': self.session.company}},
                ] + [
                    {'term': {'_id': request.match_info['id']}}
                ]
            }
        }
        method = request.match_info['method']
        r = await self.app['es'].get(
            f'messages/{method}/_search?filter_path=hits', query=es_query
        )
        data = await r.json()
        if data['hits']['total'] != 1:
            raise HTTPNotFound(text='message not found')
        source = data['hits']['hits'][0]['_source']
        body = source['body']
        if method.startswith('sms'):
            # need to render the sms so it makes sense to users
            return {
                'from': source['from_name'],
                'to': source['to_last_name'] or source['to_address'],
                'status': source['status'],
                'message': body,
                'extra': source.get('extra') or {},
            }
        else:
            return {'raw': body}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号