memento¶
Classes to interface with the Memento model, which tracks modification of changes.
This module contains the memento_types variable, which is a list of different types of changes that can be tracked. Add elements to this list to add custom tracking of changes
- class camelot.core.memento.SqlMemento(memento_types=[(1, 'before_update'), (2, 'before_delete'), (3, 'create')])[source]¶
Default Memento system, which uses camelot.model.memento.Memento to track changes into a database table. The tracking of changes happens outside the session, but using the same connection as the session.
Reimplement this class to create a custom system to track changes.
This Memento system can only track objects with an integer primary key. That means the primary_key tuple can only contain a single integer value.
Parameters: memento_types – a list with all types of changes that can be tracked and their identifier used to store them - get_changes(model, primary_key, current_attributes, from_datetime=datetime.datetime(2000, 1, 1, 0, 0), depth={})[source]¶
Query the memento system for changes made to an object.
Parameters: - model – a string with the name of the model
- primary_key – a tuple with the primary key of the changed object
- current_attributes – a dict with the current state of the attributes of the object, this is used to reconstruct the changes.
- from_datetime – the datetime upto which the changes should be reconstructed.
- depth – reserved for future usage to query the history of object trees.
Returns: generator of change_object tuples in reverse order, meaning the last change will be first generated.