<s> from flask import Blueprint , request <EOL> from apikit import jsonify <EOL> from apikit import get_limit , get_offset <EOL> from aleph import authz <EOL> from aleph . core import url_for <EOL> from aleph . model import Alert <EOL> from aleph . views . cache import enable_cache <EOL> from aleph . views . util import get_document <EOL> from aleph . search import documents_query , execute_documents_query <EOL> from aleph . search import records_query , execute_records_query <EOL> from aleph . search . util import next_params <EOL> blueprint = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> @ blueprint . route ( '<STR_LIT>' ) <EOL> def query ( ) : <EOL> creds = authz . collections ( authz . READ ) , authz . sources ( authz . READ ) <EOL> enable_cache ( vary_user = True , vary = creds ) <EOL> query = documents_query ( request . args ) <EOL> query [ '<STR_LIT:size>' ] = get_limit ( default = <NUM_LIT:100> ) <EOL> query [ '<STR_LIT>' ] = get_offset ( ) <EOL> result = execute_documents_query ( request . args , query ) <EOL> result [ '<STR_LIT>' ] = None <EOL> if authz . logged_in ( ) : <EOL> result [ '<STR_LIT>' ] = Alert . exists ( request . args , request . auth_role ) <EOL> params = next_params ( request . args , result ) <EOL> if params is not None : <EOL> result [ '<STR_LIT>' ] = url_for ( '<STR_LIT>' , ** params ) <EOL> return jsonify ( result ) <EOL> @ blueprint . route ( '<STR_LIT>' ) <EOL> def records ( document_id ) : <EOL> document = get_document ( document_id ) <EOL> enable_cache ( vary_user = True ) <EOL> query = records_query ( document . id , request . args ) <EOL> if query is None : <EOL> return jsonify ( { <EOL> '<STR_LIT:status>' : '<STR_LIT>' , <EOL> '<STR_LIT:message>' : '<STR_LIT>' <EOL> } ) <EOL> query [ '<STR_LIT:size>' ] = get_limit ( default = <NUM_LIT:30> ) <EOL> query [ '<STR_LIT>' ] = get_offset ( ) <EOL> result = execute_records_query ( query ) <EOL> params = next_params ( request . args , result ) <EOL> if params is not None : <EOL> result [ '<STR_LIT>' ] = url_for ( '<STR_LIT>' , document_id = document_id , <EOL> ** params ) <EOL> return jsonify ( result ) </s>
