django_prov_.generator module

class django_prov.generator.ProvenanceGenerator(config: dict | ProvenanceGeneratorConfiguration = None)

Bases: object

Handler Class for Generating Provenance Documents

activity(name=None, *, fields=None)

Decorator-function that can be applied to Views and other functions.

Parameters:
  • name – Name applied to a function, or as a prefix for methods of a class.

  • fields – Optional instance attribute names to record as entities.

Returns:

_decorator

check_derivation(label, model_name, pk)

Checks if there need to be derivations between two ProvRecords.

Parameters:
  • label – Valid namespace prefix that has been declared in settings

  • model_name – ModelBase of the instance whose ProvRecords have to be checked

  • pk – Primary key of the instance for which all existing ProvRecords have to be checked

check_foreign_keys(identifier, sender, instance, prov_class=<class 'prov.model.ProvEntity'>)

Checks if an instance of a Django model contains ForeignKeys and creates ProvRecords for them.

Parameters:
  • sender – ModelBase of the sending instance

  • instance – Instance of the ModelBase

  • kwargs – Kwargs that got passed

check_is_already_existing(record, attributes)

Checks if the exact same prov record is already existing in the current ProvDocument. If True is returned, a record with the exact same attributes is already existing.

Parameters:
  • record – ProvRecord of which the attributes have to be checked

  • attributes – List of attributes which are compared

Returns:

True if existing, False if not

clean_state(config: dict | ProvenanceGeneratorConfiguration = None)

Sets up the ProvenanceGenerator instance. Applies the configuration, sets maximum value lengths and connects Django signals.

Parameters:

config – Configuration to apply. If None, the default config is taken from settings.py

connect_signals()

Connects the Django Signals pre_save, post_save and m2m_changed with every model that is given in the settings.

create_foreign_key_entry(existing, foreign_model, foreign_pk)

Creates a related ProvRecord for the referenced ForeignKey of an existing ProvEntity or ProvAgent.

Parameters:
  • existing – The existing ProvRecord which has the ForeignKey field, identifier as str

  • foreign_model – ModelBase of the ForeignKey instance

  • foreign_pk – Primary key of the ForeignKey instance

create_m2m_entries(sender, instance, attributes)

Appends attributes of a ProvRecord for every ManyToManyField that is existing in the referenced instance. Deprecated.

Parameters:
  • sender – ModelBase of the instance

  • instance – Instance of the given class

  • attributes – Already existing List of Attributes for a new ProvRecord

Returns:

List of new Attributes

create_many_to_many_record(parent_record, obj, m2m_field)

Creates a ProvEntity for a ManyToManyField of the provided parent_record and writes it to the current ProvDocument. Links the new entity to the parent.

Parameters:
  • parent_record – Parent ProvEntity or ProvAgent of which the m2m field originates

  • obj – (ModelBase) Corresponding Object to the parent

  • m2m_field – ManyToManyField for which the new entity shall be generated

Returns:

ProvEntity

create_new_document()

Creates a new ProvDocument and needed ProvenanceGenerator instance-variables. Sets the default Namespace for the ProvDocument and adds extra namespaces.

create_prov_record(class_info, obj)

Main logic. Creates a ProvRecord (ProvEntity or ProvAgent) by a given class and object. Tries to connect the new record to older records with different ProvRelations.

Parameters:
  • class_info – ModelBase of the instance

  • obj – Instance of the given class

Returns:

Identifier of a new or an existing ProvRecord

create_relation(first, second, rel_type)

Creates relations of type ‘rel_type’ between two ProvRecords. Adds the relation to the current ProvDocument.

filter_prov_objects(label, model_name, identifier, prov_class=<class 'prov.model.ProvEntity'>)

Returns all objects that are similar to a given ProvRecord, by a given id and name. ‘Similar’ means that they describe the same instance at different timestamps with possible different attributes.

Parameters:
  • label – Valid namespace prefix that has been declared in settings

  • model_name – ModelBase of the instance whose ProvRecords have to be filtered

  • identifier – Primary key of the instance for which all existing ProvRecords have to be checked

  • prov_class – ProvType that has to be filtered

Returns:

List of related ProvRecords

classmethod get(config: dict | ProvenanceGeneratorConfiguration = None)

Returns the single instance of the class ProvenanceGenerator. Applies the Singleton-Pattern. :return:

get_fields_to_record(obj)

Returns the fields and the type of ProvRecord of an object that will be tracked. Returns ([], None) if the object should not be tracked.

handle_m2m_changed(sender, instance, **kwargs)

Receiver-function for the m2m_changed-Signal. If an m2m_changed is triggered, either a new ProvRecord is created or connected to an existing ProvRecord. :param sender: ModelBase of the instance :param instance: Instance of the given class :param kwargs: other with the signal passed kwargs

handle_post_save(sender, instance, **kwargs)

Receiver-function for the post_save-Signal. :param sender: ModelBase of the instance that got changed :param instance: Instance that got changed :param kwargs: other with the signal passed kwargs

handle_pre_save(sender, instance, **kwargs)

Receiver-function for the pre_save-Signal. :param sender: ModelBase of the instance that is going to be changed :param instance: Instance that is going to be changed :param kwargs: other with the signal passed kwargs

print_document()

Exports the most recent document into the formats that are declared in the config

classmethod reset_cls()

Resets the class. Resets the instance and every connected Django signal.

classmethod reset_receivers()

Clears all connected Django signals.

classmethod reset_settings(config=None)

Allows to reset the settings of a ProvenanceGenerator instance

Parameters:

config – New configuration. If None, the default config is taken from settings.py

Returns:

ProvenanceGenerator instance

set_max_lengths()

Sets the maximum lengths to record of function call arguments and django object fields.

exception django_prov.generator.ProvenanceGeneratorException

Bases: Exception

provenance generator exception

exception django_prov.generator.ProvenanceGeneratorWarning

Bases: Warning

provenance generator warning