コード例 #1
0
ファイル: views.py プロジェクト: jirikuncar/invenio-records
    def decorated(recid, *args, **kwargs):
        from invenio_collections.models import Collection

        from .api import get_record
        from .access import check_user_can_view_record
        from .models import Record as Bibrec
        # ensure recid to be integer
        recid = int(recid)
        g.bibrec = Bibrec.query.get(recid)

        g.record = record = get_record(recid)
        if record is None:
            abort(404)

        g.collection = collection = Collection.query.filter(
            Collection.name.in_(record['_collections'])).first()

        (auth_code, auth_msg) = check_user_can_view_record(
            current_user, record)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        # TODO check record status (exists, merged, deleted)

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        def _format_record(record, of='hd', user_info=current_user, *args,
                           **kwargs):
            from invenio_formatter import format_record
            return format_record(record, of, user_info=user_info, *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            # from invenio.modules.comments.api import get_mini_reviews
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=lambda *args, **kwargs: '',
                        # FIXME get_mini_reviews,
                        collection=collection,
                        format_record=_format_record
                        )

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
コード例 #2
0
ファイル: views.py プロジェクト: inspirehep/invenio-records
    def decorated(recid, *args, **kwargs):
        from invenio_collections.models import Collection

        from .api import get_record
        from .access import check_user_can_view_record
        from invenio_records.tasks.index import get_record_index
        from invenio_records.api import Record
        from invenio.base.globals import cfg
        from invenio_ext.es import es
        from elasticsearch import TransportError

        # ensure recid to be integer
        recid = int(recid)

        # get record from db and the one from es
        db_record = get_record(recid)
        if db_record is None:
            abort(404)

        index = get_record_index(db_record) or \
                   cfg['SEARCH_ELASTIC_DEFAULT_INDEX']

        try:
            es_record = es.get(index=index, doc_type='record', id=recid)
        except TransportError:
            abort(404)

        g.record = record = Record(data=es_record['_source'])

        g.collection = collection = Collection.query.filter(
            Collection.name.in_(record['_collections'])).first()

        (auth_code, auth_msg) = check_user_can_view_record(
            current_user, record)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        if Query(cfg['RECORDS_DELETED_FIELD_QUERY']).match(record):
            # Record is deleted. Check for referred master recid if merged or 404
            if record.get(cfg['RECORDS_MERGED_MASTER_RECID_KEY']):
                return redirect(url_for('.' + f.func_name, recid=record.get(cfg['RECORDS_MERGED_MASTER_RECID_KEY'])))
            abort(404)

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        def _format_record(record, of='hd', user_info=current_user, *args,
                           **kwargs):
            from invenio_formatter import format_record
            return format_record(record, of, user_info=user_info, *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            # from invenio.modules.comments.api import get_mini_reviews
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=lambda *args, **kwargs: '',
                        # FIXME get_mini_reviews,
                        collection=collection,
                        format_record=_format_record
                        )

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
コード例 #3
0
    def decorated(recid, *args, **kwargs):
        from invenio_collections.models import Collection

        from .api import get_record
        from .access import check_user_can_view_record
        from invenio_records.tasks.index import get_record_index
        from invenio_records.api import Record
        from invenio.base.globals import cfg
        from invenio_ext.es import es
        from elasticsearch import TransportError

        # ensure recid to be integer
        recid = int(recid)

        # get record from db and the one from es
        db_record = get_record(recid)
        if db_record is None:
            abort(404)

        index = get_record_index(db_record) or \
                   cfg['SEARCH_ELASTIC_DEFAULT_INDEX']

        try:
            es_record = es.get(index=index, doc_type='record', id=recid)
        except TransportError:
            abort(404)

        g.record = record = Record(data=es_record['_source'])

        g.collection = collection = Collection.query.filter(
            Collection.name.in_(record['_collections'])).first()

        (auth_code,
         auth_msg) = check_user_can_view_record(current_user, record)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        # TODO check record status (exists, merged, deleted)

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        def _format_record(record,
                           of='hd',
                           user_info=current_user,
                           *args,
                           **kwargs):
            from invenio_formatter import format_record
            return format_record(record,
                                 of,
                                 user_info=user_info,
                                 *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            # from invenio.modules.comments.api import get_mini_reviews
            return dict(
                recid=recid,
                record=record,
                tabs=tabs,
                title=title,
                get_mini_reviews=lambda *args, **kwargs: '',
                # FIXME get_mini_reviews,
                collection=collection,
                format_record=_format_record)

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
コード例 #4
0
ファイル: views.py プロジェクト: Panos512/invenio-records
    def decorated(recid, *args, **kwargs):
        from invenio_collections.models import Collection

        from .api import get_record
        from .access import check_user_can_view_record
        from .models import Record as Bibrec
        # ensure recid to be integer
        recid = int(recid)
        g.bibrec = Bibrec.query.get(recid)

        g.record = record = get_record(recid)
        if record is None:
            abort(404)

        g.collection = collection = Collection.query.filter(
            Collection.name.in_(record['_collections'])).first()

        (auth_code,
         auth_msg) = check_user_can_view_record(current_user, record)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        # TODO check record status (exists, merged, deleted)

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        def _format_record(record,
                           of='hd',
                           user_info=current_user,
                           *args,
                           **kwargs):
            from invenio_formatter import format_record
            return format_record(record,
                                 of,
                                 user_info=user_info,
                                 *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            # from invenio.modules.comments.api import get_mini_reviews
            return dict(
                recid=recid,
                record=record,
                tabs=tabs,
                title=title,
                get_mini_reviews=lambda *args, **kwargs: '',
                # FIXME get_mini_reviews,
                collection=collection,
                format_record=_format_record)

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)