History (objetto.history)
History object.
- objetto.history.history_descriptor(size=None)
Descriptor to be used when declaring an
objetto.objects.Objectclass.When used, every instance of the object class will hold a history that will keep track of its changes (and the changes of its children that define a history relationship), allowing for easy undo/redo operations. If accessed through an instance, the descriptor will return the history object.
>>> from objetto import Application, Object, attribute, history_descriptor >>> class Person(Object): ... history = history_descriptor() ... name = attribute(str) ... >>> app = Application() >>> person = Person(app, name="Albert") >>> person.name = "Einstein" >>> person.history.undo() >>> person.name 'Albert'
- Parameters
size (int or None) – How many changes to remember.
- Returns
History descriptor.
- Return type
objetto.history.HistoryDescriptor
- class objetto.history.HistoryObject(app, **initial)
History object.
- Inherits from:
- changes : Attribute
List of batch changes. The first one is always None.
- Type
objetto.objects.ListObject[objetto.history.BatchChanges or None]
- current_batches : Attribute
Open batches.
- set_index(index)
Undo/redo until we reach the desired index.
- Parameters
index (int) – Index.
- Raises
IndexError – Invalid index.
- undo_all()
Undo all.
- Raises
HistoryError – Can’t undo all while executing.
- redo_all()
Redo all.
- Raises
HistoryError – Can’t redo all while executing.
- redo()
Redo.
- Raises
HistoryError – Can’t redo while executing.
- undo()
Undo.
- Raises
HistoryError – Can’t undo while executing.
- flush()
Flush all changes.
- Raises
HistoryError – Can’t flush while executing.
- flush_redo()
Flush changes ahead of the current index.
- Raises
HistoryError – Can’t flush while executing.
- in_batch()
Get whether history is currently in an open batch.
- Returns
True if currently in an open batch.
- Return type
- Raises
HistoryError – Can’t check while executing.