Esempio n. 1
0
def _operation(operation, identifier):
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc:
        if _register_click():
            api.link_gateway(doc['bibcode'], operation)
        if operation in ("trending", "similar"):
            sort = "score desc"
        elif operation == "references":
            sort = "first_author asc"
        else:
            sort = "date desc"
        target_url = _url_for('search',
                              q=f'{operation}(bibcode:{doc["bibcode"]})',
                              sort=sort)
        if request.cookies.get('core', 'never') == 'always':
            return redirect(target_url)
        else:
            key = "/".join(
                (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, operation))
            return _cached_render_template(
                key,
                'abstract-empty.html',
                environment=current_app.config['ENVIRONMENT'],
                base_url=app.config['SERVER_BASE_URL'],
                doc=doc)
    else:
        abort(404)
Esempio n. 2
0
def _abstract(identifier, section=None):
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc:
        if doc['bibcode'] != identifier:
            target_url = _url_for('abs', identifier=doc['bibcode'], section='abstract')
            return redirect(target_url, code=301)
        if _register_click():
            api.link_gateway(doc['bibcode'], "abstract")
        key = "/".join((app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'abstract'))
        return _cached_render_template(key, 'abstract.html', doc=doc)
    else:
        abort(404)
Esempio n. 3
0
def _metrics(identifier):
    """
    Metrics for a given identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc and doc['bibcode'] != identifier:
        target_url = _url_for('abs', identifier=doc['bibcode'], section='metrics')
        return redirect(target_url, code=301)
    if int(doc.get('metrics', {}).get('citation stats', {}).get('total number of citations', 0)) > 0 or int(doc.get('metrics', {}).get('basic stats', {}).get('total number of reads', 0)) > 0:
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "metrics")
        key = "/".join((app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'metrics'))
        return _cached_render_template(key, 'abstract-metrics.html', doc=doc)
    else:
        abort(404)
Esempio n. 4
0
def _graphics(identifier):
    """
    Graphics for a given identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc and doc['bibcode'] != identifier:
        target_url = _url_for('abs', identifier=doc['bibcode'], section='graphics')
        return redirect(target_url, code=301)
    if len(doc.get('graphics', {}).get('figures', [])) > 0:
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "graphics")
        key = "/".join((app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'graphics'))
        return _cached_render_template(key, 'abstract-graphics.html', doc=doc)
    else:
        abort(404)
Esempio n. 5
0
def _export(identifier):
    """
    Export bibtex given an identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc and doc['bibcode'] != identifier:
        target_url = _url_for('abs', identifier=doc['bibcode'], section='exportcitation')
        return redirect(target_url, code=301)
    if doc.get('export'):
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "exportcitation")
        key = "/".join((app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'export'))
        return _cached_render_template(key, 'abstract-export.html', doc=doc)
    else:
        abort(404)
Esempio n. 6
0
def _toc(identifier):
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc:
        if doc['bibcode'] != identifier:
            target_url = _url_for('abs', identifier=doc['bibcode'], section='toc')
            return redirect(target_url, code=301)
        if _register_click():
            api.link_gateway(doc['bibcode'], "toc")
        target_url = _url_for('search', q=f'bibcode:{doc["bibcode"][:13]}*')
        if request.cookies.get('core', 'never') == 'always':
            return redirect(target_url)
        else:
            key = "/".join((app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'toc'))
            return _cached_render_template(key, 'abstract-empty.html', doc=doc)
    else:
        abort(404)
Esempio n. 7
0
def _graphics(identifier):
    """
    Graphics for a given identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if len(doc.get('graphics', {}).get('figures', [])) > 0:
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "graphics")
        key = "/".join(
            (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'graphics'))
        return _cached_render_template(
            key,
            'abstract-graphics.html',
            environment=current_app.config['ENVIRONMENT'],
            base_url=app.config['SERVER_BASE_URL'],
            doc=doc)
    else:
        abort(404)
Esempio n. 8
0
def _export(identifier):
    """
    Export bibtex given an identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if doc.get('export'):
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "exportcitation")
        key = "/".join(
            (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'export'))
        return _cached_render_template(
            key,
            'abstract-export.html',
            environment=current_app.config['ENVIRONMENT'],
            base_url=app.config['SERVER_BASE_URL'],
            doc=doc)
    else:
        abort(404)
Esempio n. 9
0
def _toc(identifier):
    api = API()
    doc = api.abstract(identifier)
    if 'bibcode' in doc:
        if _register_click():
            api.link_gateway(doc['bibcode'], "toc")
        target_url = _url_for('search', q=f'bibcode:{doc["bibcode"][:13]}*')
        if request.cookies.get('core', 'never') == 'always':
            return redirect(target_url)
        else:
            key = "/".join(
                (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'toc'))
            return _cached_render_template(
                key,
                'abstract-empty.html',
                environment=current_app.config['ENVIRONMENT'],
                base_url=app.config['SERVER_BASE_URL'],
                doc=doc)
    else:
        abort(404)
Esempio n. 10
0
def _metrics(identifier):
    """
    Metrics for a given identifier
    """
    api = API()
    doc = api.abstract(identifier)
    if int(
            doc.get('metrics', {}).get('citation stats', {}).get(
                'total number of citations', 0)) > 0 or int(
                    doc.get('metrics', {}).get('basic stats', {}).get(
                        'total number of reads', 0)) > 0:
        if 'bibcode' in doc and _register_click():
            api.link_gateway(doc['bibcode'], "metrics")
        key = "/".join(
            (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'metrics'))
        return _cached_render_template(
            key,
            'abstract-metrics.html',
            environment=current_app.config['ENVIRONMENT'],
            base_url=app.config['SERVER_BASE_URL'],
            doc=doc)
    else:
        abort(404)