fairdm.contrib.import_export.resources#
django-import-export resources for samples and measurements.
Module Contents#
Classes#
Shared base class for Sample and Measurement resources. |
|
Resource for importing and exporting samples. |
|
Resolve a sample from a UUID or from its name within the row’s dataset. |
|
Resource for importing and exporting measurements. |
API#
- class BaseFairDMResource(dataset, *args, **kwargs)#
Bases:
fairdm.utils.location.resources.LocatedResourceMixin,import_export.resources.ModelResourceShared base class for Sample and Measurement resources.
A
locationamong 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 toModelResource.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
deletecolumn is1.
- 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.BaseFairDMResourceResource for importing and exporting samples.
Initialization
kwargs: An optional dict of kwargs. Subclasses can use kwargs to pass dynamic values to enhance import / exports.
- 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.ForeignKeyWidgetResolve a sample from a UUID or from its name within the row’s dataset.
Args: model: The sample model. Defaults to
Sample. **kwargs: Passed toForeignKeyWidget.Initialization
:param coerce_to_string: If True, :meth:
~import_export.widgets.Widget.renderwill 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.BaseFairDMResourceResource 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.