History (objetto.history)

History object.

objetto.history.history_descriptor(size=None)

Descriptor to be used when declaring an objetto.objects.Object class.

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:
size :  Attribute

How many changes to remember.

Type

int

executing :  Attribute

Whether the history is undoing or redoing.

Type

bool

undoing :  Attribute

Whether the history is undoing.

Type

bool

redoing :  Attribute

Whether the history is redoing.

Type

bool

index :  Attribute

The index of the current change.

Type

int

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.

Type

objetto.objects.ListObject[objetto.history.BatchChanges]

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

bool

Raises

HistoryError – Can’t check while executing.

format_changes()

Format changes into readable string.

Returns

Formatted changes.

Return type

str

class objetto.history.BatchChanges(app, **initial)

Batch changes.

Inherits from:
change :  Attribute

Batch change with name and metadata.

Type

objetto.changes.Batch

name :  Attribute

The batch change name.

Type

str

changes :  Attribute

Changes executed during the batch.

Type

objetto.objects.ListObject[objetto.history.BatchChanges or objetto.bases.BaseAtomicChange]

closed :  Attribute

Whether the batch has already completed or is still running.

Type

bool

format_changes()

Format changes into readable string.

Returns

Formatted changes.

Return type

str