data_models Package

data_models Package

Indivo DataModels

class indivo.data_models.IndivoDataModelLoader(top)

Bases: object

_discover_python_data_models(dirpath, fileroot, ext)

Imports a python module and extracts all Indivo Fact subclasses.

_discover_sdml_data_models(dirpath, fileroot, ext)

Reads in an SDML model definition and generates Indivo Fact subclasses.

classmethod add_model_to_module(model_name, model_class, module)
classmethod detect_model_dir(dir_path)

Detects whether a directory is a properly-formatted datamodel.

This is true if:

  • It contains a model file of an appropriate type (for now, .py or .sdml)
  • More to come later (maybe)

dir_path MUST be an absolute path for this to work. Returns a tuple of (valid_p, fileroot, ext), where valid_p is True if the format is valid, fileroot is the name of the file containing the model definition (without the extention), and ext is the extension. If no such file exists, returns (False, None, None). Returns the first valid definition format.

discover_data_models()

A generator for iterating over all valid datamodels below toplevel_dir.

At each step, returns a tuple of (class_name, class), where class is a subclass of indivo.models.Fact corresponding to a datamodel.

If a model.py file fails to produce such a class, this function will silently skip it.

import_data_models(target_module)
process_data_model_extras(dirpath, model_class)

Processes extra options included in an extra.py file for a data model.

Looks for indivo.data_models.DataModelOptions classes and attaches them to the data model

indivo.data_models.attach_filter_fields(cls)
indivo.data_models.load_data_models(from_dir, target_module)

Load all datamodels under directory into module.

options Module

Options processing and loading for Indivo medical data models.

class indivo.data_models.options.DataModelOptions

Bases: object

Defines optional extra functionality for Indivo datamodels.

To add options to a datamodel, subclass this class and override its attributes.

Currently available options are:

  • model_class_name: Required. The name of the datamodel class to attach to.
  • serializers: Custom serializers for the data model. Should be set to a subclass of indivo.serializers.DataModelSerializers.
  • field_validators: Custom validators for fields on the data model. A dictionary, where keys are field names on the model, and values are lists of Django Validators to be run against the field.
classmethod attach(data_model_class)

Apply these options to a data model class.

Attaches custom serializers and field validators.

classmethod attach_p(data_model_class)

True if these options should be applied to data_model_class.

Right now, does cls.model_class_name match data_model_class.__name__?

classmethod attach_serializers(data_model_class)
classmethod attach_validators(data_model_class)
field_validators = {}
model_class_name = ''
serializers = None

Project Versions

Table Of Contents

Previous topic

indivo Package

Next topic

contrib Package

This Page