l.s.w.snapshot : module documentation

Part of lp.services.webapp

Snapshot helpers.
Function snapshot_sql_result Snapshot adapter for the Storm result set.
Function notify_modified A context manager that notifies about modifications to an object.
@implementer(ISnapshotValueFactory)
@adapter(IResultSet)
def snapshot_sql_result(value):
Snapshot adapter for the Storm result set.
@contextmanager
def notify_modified(obj, edited_fields, snapshot_names=None, user=None):

A context manager that notifies about modifications to an object.

Use this as follows:

with notify_modified(obj, ["attr"]):
    obj.attr = value

Or:

edited_fields = set()
with notify_modified(obj, edited_fields):
    if obj.attr != new_attr:
        obj.attr = new_attr
        edited_fields.add("attr")

Or even:

edited_fields = set()
with notify_modified(obj, edited_fields) as previous_obj:
    do_something()
    if obj.attr != previous_obj.attr:
        edited_fields.add("attr")
ParametersobjThe object being modified.
edited_fieldsAn iterable of fields being modified. This is not used until after the block wrapped by the context manager has finished executing, so you can safely pass a mutable object and add items to it from inside the block as you determine which fields are being modified. A notification will only be sent if edited_fields is non-empty.
snapshot_namesIf not None, only snapshot these names. This may be used if snapshotting some of the object's attributes is expensive in some contexts (and they can't be wrapped by doNotSnapshot for some reason).
userIf not None, the user making these changes. If None, defaults to the principal registered in the current interaction.
API Documentation for Launchpad, generated by pydoctor at 2018-11-17 00:00:08.