API Docs

Flask extension

Flask extension for Invenio-Records-UI.

class invenio_records_ui.ext.InvenioRecordsUI(app=None)[source]

Invenio-Records-UI extension.

The extension takes care of setting default configuration and registering a blueprint with URL routes for the endpoints.

Extension initialization.

Parameters:app – The Flask application. (Default: None)
init_app(app)[source]

Flask application initialization.

Parameters:app – The Flask application.
init_config(app)[source]

Initialize configuration on application.

Parameters:app – The Flask application.
class invenio_records_ui.ext._RecordUIState(app)[source]

Record UI state.

Initialize state.

Parameters:app – The Flask application.
export_formats(pid_type)[source]

List of export formats.

permission_factory

Load default permission factory.

Views

Factory for creating a blueprint for Invenio-Records-UI.

invenio_records_ui.views.create_blueprint(endpoints)[source]

Create Invenio-Records-UI blueprint.

The factory installs one URL route per endpoint defined, and adds an error handler for rendering tombstones.

Parameters:endpoints – Dictionary of endpoints to be installed. See usage documentation for further details.
Returns:The initialized blueprint.
invenio_records_ui.views.create_blueprint_from_app(app)[source]

Create Invenio-Records-UI blueprint from a Flask application.

Note

This function assumes that the application has loaded all extensions that want to register REST endpoints via the RECORDS_UI_ENDPOINTS configuration variable.

Params app:A Flask application.
Returns:Configured blueprint.
invenio_records_ui.views.create_url_rule(endpoint, route=None, pid_type=None, template=None, permission_factory_imp=None, view_imp=None, record_class=None, methods=None)[source]

Create Werkzeug URL rule for a specific endpoint.

The method takes care of creating a persistent identifier resolver for the given persistent identifier type.

Parameters:
  • endpoint – Name of endpoint.
  • route – URL route (must include <pid_value> pattern). Required.
  • pid_type – Persistent identifier type for endpoint. Required.
  • template – Template to render. (Default: invenio_records_ui/detail.html)
  • permission_factory_imp – Import path to factory that creates a permission object for a given record.
  • view_imp – Import path to view function. (Default: None)
  • record_class – Name of the record API class.
  • methods – Method allowed for the endpoint.
Returns:

A dictionary that can be passed as keywords arguments to Blueprint.add_url_rule.

invenio_records_ui.views.default_view_method(pid, record, template=None, **kwargs)[source]

Display default view.

Sends record_viewed signal and renders template.

Parameters:
  • pid – PID object.
  • record – Record object.
  • template – Template to render.
  • **kwargs – Additional view arguments based on URL rule.
Returns:

The rendered template.

invenio_records_ui.views.export(pid, record, template=None, **kwargs)[source]

Record serialization view.

Serializes record with given format and renders record export template.

Parameters:
  • pid – PID object.
  • record – Record object.
  • template – Template to render.
  • **kwargs – Additional view arguments based on URL rule.
Returns:

The rendered template.

invenio_records_ui.views.record_view(pid_value=None, resolver=None, template=None, permission_factory=None, view_method=None, **kwargs)[source]

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:

  1. PID and record are resolved.
  2. Permission are checked.
  3. view_method is called.
Parameters:
  • pid_value – Persistent identifier value.
  • resolver – An instance of a persistent identifier resolver. A persistent identifier resolver takes care of resolving persistent identifiers into internal objects.
  • template – Template to render.
  • permission_factory – Permission factory called to check if user has enough power to execute the action.
  • view_method – Function that is called.
Returns:

Tuple (pid object, record object).

Signals

Record module signals.

invenio_records_ui.signals.record_viewed = <blinker.base.NamedSignal object at 0x7f9e2dfbd5d0; 'record-viewed'>

Signal sent when a record is viewed on any endpoint.

Parameters:

  • sender - a Flask application object.
  • pid - a persistent identifier instance.
  • record - a record instance.

Example receiver:

def receiver(sender, record=None, pid=None):
    # ...

Note, the signal is always sent in a request context, thus it is safe to access the current request and/or current user objects inside the receiver.