fairdm.contrib.import_export.resources#

django-import-export resources for samples and measurements.

Module Contents#

Classes#

BaseFairDMResource

Shared base class for Sample and Measurement resources.

SampleResource

Resource for importing and exporting samples.

SampleWidget

Resolve a sample from a UUID or from its name within the row’s dataset.

MeasurementResource

Resource for importing and exporting measurements.

API#

class BaseFairDMResource(dataset, *args, **kwargs)#

Bases: fairdm.utils.location.resources.LocatedResourceMixin, import_export.resources.ModelResource

Shared base class for Sample and Measurement resources.

A location among the fields is written and read as the four location columns.

Args: dataset: The dataset that imported rows are attributed to. *args: Passed to ModelResource. **kwargs: Passed to ModelResource.

Initialization

kwargs: An optional dict of kwargs. Subclasses can use kwargs to pass dynamic values to enhance import / exports.

for_delete(row, instance)#

Delete the row’s record when its delete column is 1.

before_import_row(row, **kwargs)#

Attribute the row to the resource’s dataset.

get_import_order()#

Append the dataset and sample columns to the import order.

get_export_order()#

Leave the dataset column out of exports but keep it for import.

class SampleResource(dataset, *args, **kwargs)#

Bases: fairdm.contrib.import_export.resources.BaseFairDMResource

Resource for importing and exporting samples.

Initialization

kwargs: An optional dict of kwargs. Subclasses can use kwargs to pass dynamic values to enhance import / exports.

class Meta#
fields#

(‘dataset’, ‘id’, ‘local_id’, ‘name’, ‘char_field’)

get_instance(instance_loader, row)#

Find the existing sample by id, or by local id within the dataset.

class SampleWidget(model=None, **kwargs)#

Bases: import_export.widgets.ForeignKeyWidget

Resolve a sample from a UUID or from its name within the row’s dataset.

Args: model: The sample model. Defaults to Sample. **kwargs: Passed to ForeignKeyWidget.

Initialization

:param coerce_to_string: If True, :meth:~import_export.widgets.Widget.render will return a string representation of the value, otherwise the value is returned.

clean(value, row=None, *args, **kwargs)#

Look the sample up by UUID (a 23-character value starting with s), else by name.

class MeasurementResource(dataset, *args, **kwargs)#

Bases: fairdm.contrib.import_export.resources.BaseFairDMResource

Resource for importing and exporting measurements.

Initialization

kwargs: An optional dict of kwargs. Subclasses can use kwargs to pass dynamic values to enhance import / exports.

sample#

‘Field(…)’

get_instance(instance_loader, row)#

Find the existing measurement by id, or by name within the dataset.