invenio_records_ui/views.py
def record_view(pid_value=None, resolver=None, template=None,
                permission_factory=None, view_method=None, **kwargs):
    """Display record view.

    The two parameters ``resolver`` and ``template`` should not be included
    in the URL rule, but instead set by creating a partially evaluated function
    of the view.

    The template being rendered is passed two variables in the template
    context:

    - ``pid``
    - ``record``.

    Procedure followed:

    #. PID and record are resolved.

    #. Permission are checked.

    #. ``view_method`` is called.

    :param pid_value: Persistent identifier value.
    :param resolver: An instance of a persistent identifier resolver. A
        persistent identifier resolver takes care of resolving persistent
        identifiers into internal objects.
    :param template: Template to render.
    :param permission_factory: Permission factory called to check if user has
        enough power to execute the action.
    :param view_method: Function that is called.
    :returns: Tuple (pid object, record object).
    """
    try:
        pid, record = resolver.resolve(pid_value)
    except (PIDDoesNotExistError, PIDUnregistered):
        abort(404)
    except PIDMissingObjectError as e:
        current_app.logger.exception(
            "No object assigned to {0}.".format(e.pid),
            extra={'pid': e.pid})
        abort(500)
    except PIDRedirectedError as e:
        try:
            return redirect(url_for(
                '.{0}'.format(e.destination_pid.pid_type),
                pid_value=e.destination_pid.pid_value))
        except BuildError:
            current_app.logger.exception(
                "Invalid redirect - pid_type '{0}' endpoint missing.".format(
                    e.destination_pid.pid_type),
                extra={
                    'pid': e.pid,
                    'destination_pid': e.destination_pid,
                })
            abort(500)

    # Check permissions
    permission_factory = permission_factory or current_permission_factory
    if permission_factory:
        # Note, cannot be done in one line due to overloading of boolean
        # operations in permission object.
        if not permission_factory(record).can():
            from flask_login import current_user
            if not current_user.is_authenticated:
                return redirect(url_for(
                    current_app.config['RECORDS_UI_LOGIN_ENDPOINT'],
                    next=request.url))
            abort(403)

    return view_method(pid, record, template=template, **kwargs)
def record_view(pid_value=None, resolver=None, template=None,
                permission_factory=None, view_method=None, **kwargs):
    """Display record view.

    The two parameters ``resolver`` and ``template`` should not be included
    in the URL rule, but instead set by creating a partially evaluated function
    of the view.

    The template being rendered is passed two variables in the template
    context:

    - ``pid``
    - ``record``.

    Procedure followed:

    #. PID and record are resolved.

    #. Permission are checked.

    #. ``view_method`` is called.

    :param pid_value: Persistent identifier value.
    :param resolver: An instance of a persistent identifier resolver. A
        persistent identifier resolver takes care of resolving persistent
        identifiers into internal objects.
    :param template: Template to render.
    :param permission_factory: Permission factory called to check if user has
        enough power to execute the action.
    :param view_method: Function that is called.
    :returns: Tuple (pid object, record object).
    """
    try:
        pid, record = resolver.resolve(pid_value)
    except (PIDDoesNotExistError, PIDUnregistered):
        abort(404)
    except PIDMissingObjectError as e:
        current_app.logger.exception(
            "No object assigned to {0}.".format(e.pid),
            extra={'pid': e.pid})
        abort(500)
    except PIDRedirectedError as e:
        try:
            return redirect(url_for(
                '.{0}'.format(e.destination_pid.pid_type),
                pid_value=e.destination_pid.pid_value))
        except BuildError:
            current_app.logger.exception(
                "Invalid redirect - pid_type '{0}' endpoint missing.".format(
                    e.destination_pid.pid_type),
                extra={
                    'pid': e.pid,
                    'destination_pid': e.destination_pid,
                })
            abort(500)

    # Check permissions
    permission_factory = permission_factory or current_permission_factory
    if permission_factory:
        # Note, cannot be done in one line due to overloading of boolean
        # operations in permission object.
        if not permission_factory(record).can():
            from flask_login import current_user
            if not current_user.is_authenticated:
                return redirect(url_for(
                    current_app.config['RECORDS_UI_LOGIN_ENDPOINT'],
                    next=request.url))
            abort(403)

    return view_method(pid, record, template=template, **kwargs)
Display record view.

    The two parameters ``resolver`` and ``template`` should not be included
    in the URL rule, but instead set by creating a partially evaluated function
    of the view.

    The template being rendered is passed two variables in the template
    context:

    - ``pid``
    - ``record``.

    Procedure followed:

    #. PID and record are resolved.

    #. Permission are checked.

    #. ``view_method`` is called.

    :param pid_value: Persistent identifier value.
    :param resolver: An instance of a persistent identifier resolver. A
        persistent identifier resolver takes care of resolving persistent
        identifiers into internal objects.
    :param template: Template to render.
    :param permission_factory: Permission factory called to check if user has
        enough power to execute the action.
    :param view_method: Function that is called.
    :returns: Tuple (pid object, record object).