Example #1
0
def export_get(bibcode, style, format=-1):
    """

    :param bibcode:
    :param style:
    :param format:
    :return:
    """
    if format == -1:
        current_app.logger.debug(
            'received request with bibcode={bibcode} to export in {style} style'
            .format(bibcode=bibcode, style=style))
    else:
        current_app.logger.debug(
            'received request with bibcode={bibcode} to export in {style} style with output format {format}'
            .format(bibcode=bibcode, style=style, format=format))

    sort = 'date desc, bibcode desc'

    # if in the test mode, return test solr data
    if current_app.config['EXPORT_SERVICE_TEST_BIBCODE_GET'] == bibcode:
        return solrdata.data_2

    return get_solr_data(bibcodes=[bibcode],
                         fields=default_solr_fields(),
                         sort=sort,
                         encode_style=adsFormatter().native_encoding(format))
Example #2
0
def csl_format_export():
    try:
        payload = request.get_json(force=True)  # post data in json
    except:
        payload = dict(request.form)  # post data in form encoding

    if not payload:
        return return_response({'error': 'no information received'}, 400)
    if 'bibcode' not in payload:
        return return_response(
            {
                'error':
                'no bibcode found in payload (parameter name is `bibcode`)'
            }, 400)
    if 'style' not in payload:
        return return_response(
            {'error': 'no style found in payload (parameter name is `style`)'},
            400)
    if 'format' not in payload:
        return return_response(
            {
                'error':
                'no output format found in payload (parameter name is `format`)'
            }, 400)

    bibcodes = payload['bibcode']
    csl_style = payload['style']
    export_format = payload['format']

    if (len(bibcodes) == 0) or (len(csl_style) == 0) or (export_format
                                                         == None):
        return return_response(
            {'error': 'not all the needed information received'}, 400)

    if (not adsCSLStyle().verify(csl_style)):
        return return_response(
            {
                'error':
                'unrecognizable style (supprted formats are: ' +
                adsCSLStyle().get() + ')'
            }, 400)
    if (not adsFormatter().verify(export_format)):
        return return_response(
            {
                'error':
                'unrecognizable format (supprted formats are: unicode=1, html=2, latex=3)'
            }, 400)

    current_app.logger.debug(
        'received request with bibcodes={bibcodes} to export in {csl_style} style with output format {export_format}'
        .format(bibcodes=''.join(bibcodes),
                csl_style=csl_style,
                export_format=export_format))

    solr_data = get_solr_data(bibcodes=bibcodes, fields=default_solr_fields())
    return return_csl_format_export(solr_data, csl_style, export_format)
Example #3
0
def export_post(request, style, format=-1):
    """

    :param request:
    :param style:
    :param format:
    :return:
    """
    try:
        payload = request.get_json(force=True)  # post data in json
    except:
        payload = dict(request.form)  # post data in form encoding

    if not payload:
        return {'error': 'no information received'}, 400
    if 'bibcode' not in payload:
        return {
            'error':
            'no bibcode found in payload (parameter name is `bibcode`)'
        }, 400
    if 'sort' in payload:
        sort = read_value_list_or_not(payload, 'sort')
    else:
        sort = 'date desc, bibcode desc'

    bibcodes = payload['bibcode']

    if format == -1:
        current_app.logger.info(
            'received request with bibcodes={bibcodes} to export in {style} style using sort order={sort}'
            .format(bibcodes=','.join(bibcodes), style=style, sort=sort))
    else:
        current_app.logger.info(
            'received request with bibcodes={bibcodes} to export in {style} style with output format {format} using sort order={sort}'
            .format(bibcodes=','.join(bibcodes),
                    style=style,
                    format=format,
                    sort=sort))

    # if in the test mode, return test solr data
    if current_app.config['EXPORT_SERVICE_TEST_BIBCODE_GET'] == bibcodes:
        return solrdata.data, 200

    return get_solr_data(
        bibcodes=bibcodes,
        fields=default_solr_fields(),
        sort=sort,
        encode_style=adsFormatter().native_encoding(format)), 200