예제 #1
0
def _operation(operation, identifier):
    doc = api.Abstract(identifier)
    if 'bibcode' in doc:
        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'],
                auth=session['auth'],
                doc=doc)
    else:
        abort(404)
예제 #2
0
def _abstract(identifier, section=None):
    doc = api.Abstract(identifier)
    if 'bibcode' in doc:
        if doc['bibcode'] != identifier:
            if current_app.config['ENVIRONMENT'] == "localhost":
                target_url = url_for('abs',
                                     identifier=doc['bibcode'],
                                     section='abstract',
                                     _external=True,
                                     _scheme='https')
            else:
                target_url = url_for('abs',
                                     identifier=doc['bibcode'],
                                     section='abstract')
            return redirect(target_url, code=301)
        api.link_gateway(doc['bibcode'], "abstract")
        key = "/".join(
            (app.config['REDIS_RENDER_KEY_PREFIX'], identifier, 'abstract'))
        return _cached_render_template(
            key,
            'abstract.html',
            environment=current_app.config['ENVIRONMENT'],
            base_url=app.config['SERVER_BASE_URL'],
            auth=session['auth'],
            doc=doc)
    else:
        abort(404)
예제 #3
0
def _metrics(identifier):
    """
    Metrics for a given identifier
    """
    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:
            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'], auth=session['auth'], doc=doc)
    else:
        abort(404)
예제 #4
0
def _graphics(identifier):
    """
    Graphics for a given identifier
    """
    doc = api.Abstract(identifier)
    if len(doc.get('graphics', {}).get('figures', [])) > 0:
        if 'bibcode' in doc:
            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'], auth=session['auth'], doc=doc)
    else:
        abort(404)
예제 #5
0
def _export(identifier):
    """
    Export bibtex given an identifier
    """
    doc = api.Abstract(identifier)
    if doc.get('export'):
        if 'bibcode' in doc:
            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'], auth=session['auth'], doc=doc)
    else:
        abort(404)
예제 #6
0
def _toc(identifier):
    doc = api.Abstract(identifier)
    if 'bibcode' in doc:
        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'], auth=session['auth'], doc=doc)
    else:
        abort(404)