fairdm.contrib.import_export.utils#

Format lookups, metadata rendering and ZIP packaging for exports.

Module Contents#

Classes#

DataPackage

Build a ZIP package holding a dataset’s licence, readme, metadata and records.

Functions#

get_formats

Return the available import and export formats.

get_export_formats

Return the available export formats.

get_import_formats

Return the formats that can be imported.

build_metadata

Render a dataset’s DataCite metadata as indented XML.

build_export_for_datatype

Export a queryset of one data type for inclusion in a ZIP file.

Data#

API#

get_formats()#

Return the available import and export formats.

Returns: The IMPORT_EXPORT_FORMATS setting, or the library defaults.

get_export_formats()#

Return the available export formats.

Returns: The EXPORT_FORMATS setting, or all available formats.

get_import_formats()#

Return the formats that can be imported.

Returns: A map of format title to format class.

export_choices#

None

import_choices#

None

build_metadata(dataset, request)#

Render a dataset’s DataCite metadata as indented XML.

Args: dataset: The dataset to describe. request: The current request, used to build the dataset’s absolute URL.

Returns: The pretty-printed XML.

build_export_for_datatype(dataset, queryset, fmt='csv')#

Export a queryset of one data type for inclusion in a ZIP file.

Args: dataset: The dataset the records belong to. queryset: The records to export. fmt: The tablib export format.

Returns: The exported data.

class DataPackage(dataset, request)#

Build a ZIP package holding a dataset’s licence, readme, metadata and records.

Args: dataset: The dataset to package. request: The current request.

Initialization

build_package()#

Build the ZIP package.

Returns: A rewound buffer holding the ZIP.

add_license(zip_file)#

Add the dataset’s licence text, if it has a licence.

Args: zip_file: The open ZIP file.

add_readme(zip_file)#

Add a readme file.

Args: zip_file: The open ZIP file.

add_metadata(zip_file)#

Add the dataset’s XML metadata.

Args: zip_file: The open ZIP file.

add_samples(zip_file)#

Add one CSV per sample type in the dataset.

Args: zip_file: The open ZIP file.

add_measurements(zip_file)#

Add one CSV per measurement type in the dataset.

Args: zip_file: The open ZIP file.