def report(context, request):
doc_types = request.params.getall('type')
if len(doc_types) != 1:
msg = 'Report view requires specifying a single type.'
raise HTTPBadRequest(explanation=msg)
# schemas for all types
types = request.registry[TYPES]
# Get the subtypes of the requested type
try:
sub_types = types[doc_types[0]].subtypes
except KeyError:
# Raise an error for an invalid type
msg = "Invalid type: " + doc_types[0]
raise HTTPBadRequest(explanation=msg)
# Raise an error if the requested type has subtypes.
if len(sub_types) > 1:
msg = 'Report view requires a type with no child types.'
raise HTTPBadRequest(explanation=msg)
# Ignore large limits, which make `search` return a Response
# -- UNLESS we're being embedded by the download_report view
from_, size = get_pagination(request)
if ('limit' in request.GET and request.__parent__ is None
and (size is None or size > 1000)):
del request.GET['limit']
# Reuse search view
res = search(context, request)
# change @id, @type, and views
res['views'][0] = {
'href': res['@id'],
'title': 'View results as list',
'icon': 'list-alt',
}
search_base = normalize_query(request)
res['@id'] = '/report/' + search_base
# TODO add this back one day
# res['download_tsv'] = request.route_path('report_download') + search_base
res['title'] = 'Report'
res['@type'] = ['Report']
return res
评论列表
文章目录