Welcome to elabforms’s documentation!

Module API

A set of tools to create and manage standardized forms for eLabFTW

class elabforms.Template(template_file=None)[source]

Bases: object

Class to manage a template for ElabFTW.

add_template_part(new_template_part)[source]

Add a new template part to the current template :param new_template_part: A Template object :type new_template_part: Template :param containing the new content to add.:

Returns:

Merged content.

Return type:

dict

static check_structure(template_file_content)[source]

Validates the structure of a template.

Parameters:

template_file_content (dict) – JSON content of the file.

Raises:

ValueError – If the structure is invalid.

is_empty()[source]

Checks if the template content is empty.

Returns:

True if the template content is empty, False otherwise.

Return type:

bool

static read_template(template_file)[source]

Reads a JSON template file and validates its structure.

Parameters:

template_file (str) – Path to the JSON file.

Returns:

Content of the JSON file.

Return type:

dict

Raises:

ValueError – If the structure is invalid.

save_template(template_file_path)[source]

Saves the current template content to a JSON file.

Parameters:

template_file_path (str) – Path to the output JSON file.

Returns:

None

class elabforms.TemplateBuilder(template_parts_list_file, template_file_path=None)[source]

Bases: object

Class to generate a complete template from multiple parts.

static build_template(template_parts_list_file, template_file_path)[source]

Generates a complete template by merging all the listed parts.

Parameters:

template_parts_list_file (str) – Path to the CSV file

listing the parts.

template_file_path (str): Path to the output JSON file.

Returns:

None

static read_template_parts_list(template_parts_list_file)[source]

Reads a list of template part files from a CSV file.

Parameters:

template_parts_list_file (str) – Path to the CSV file.

Returns:

List of JSON file paths.

Return type:

list

Raises:
  • ValueError – If the file extension is not supported.

  • FileNotFoundError – If a file is not found.

class elabforms.TemplatePart(template_file)[source]

Bases: Template

Class to manage a template part for ElabFTW. Inherits from the Template class.

static check_structure(template_file_content)[source]

Validates the structure of a template part.

Parameters:

template_file_content (dict) – JSON content of the file.

Raises:

ValueError – If the structure is invalid.

set_content_id(new_id)[source]

Updates the IDs of the contents in a template part.

Parameters:

new_id (int) – New ID to assign.

Returns:

The updated template part with the new ID set.

Return type:

TemplatePart

Indices and tables