helpers.py 文件源码

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

项目:directory-ui-supplier 作者: uktrade 项目源码 文件源码
def get_results_from_search_response(response):
    parsed = response.json()
    formatted_results = []

    for result in parsed['hits']['hits']:
        formatted = format_company_details(result['_source'])
        if 'highlight' in result:
            highlighted = '...'.join(
                result['highlight'].get('description', '') or
                result['highlight'].get('summary', '')
            )
            # escape all html tags other than <em> and </em>
            highlighted_escaped = (
                escape(highlighted)
                .replace('&lt;em&gt;', '<em>')
                .replace('&lt;/em&gt;', '</em>')
            )
            formatted['highlight'] = mark_safe(highlighted_escaped)
        formatted_results.append(formatted)

    parsed['results'] = formatted_results
    return parsed
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号