views.py 文件源码

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

项目:open-wob-api 作者: openstate 项目源码 文件源码
def get_object_source(source_id, object_id, doc_type=u'items'):
    index_name = '%s_%s' % (current_app.config['DEFAULT_INDEX_PREFIX'],
                            source_id)

    try:
        obj = current_app.es.get(index=index_name, id=object_id,
                                 doc_type=doc_type,
                                 _source_include=['source_data'])
    except NotFoundError, e:
        if e.error.startswith('IndexMissingException'):
            message = 'Source \'%s\' does not exist' % source_id
        else:
            message = 'Document not found.'

        raise OcdApiError(message, 404)

    resp = current_app.make_response(obj['_source']['source_data']['data'])
    resp.mimetype = obj['_source']['source_data']['content_type']

    # Log a 'get_object_source' event if usage logging is enabled
    if current_app.config['USAGE_LOGGING_ENABLED']:
        tasks.log_event.delay(
            user_agent=request.user_agent.string,
            referer=request.headers.get('Referer', None),
            user_ip=request.remote_addr,
            created_at=datetime.utcnow(),
            event_type='get_object_source',
            source_id=source_id,
            doc_type=doc_type,
            object_id=object_id
        )

    return resp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号