StoredObject¶
-
class
modularodm.storedobject.
StoredObject
(**kwargs)[source]¶ Base class to be used for models.
-
get_changed_fields
(cached_data, storage_data)[source]¶ Get fields that differ between the cache_sandbox and the current object. Validation and after_save methods should only be run on diffed fields.
Parameters: - cached_data – Storage-formatted data from cache_sandbox
- storage_data – Storage-formatted data from object
Returns: List of diffed fields
-
classmethod
migrate
(old, new, verbose=True, dry_run=False, rm_refs=True)[source]¶ Migrate record to new schema.
Parameters: - old – Record from original schema
- new – Record from new schema
- verbose – Print detailed info
- dry_run – Dry run; make no changes if true
- rm_refs – Remove references on deleted fields
-
save
(*args, **kwargs)[source]¶ Save a record.
Parameters: force (bool) – Save even if no fields have changed; used to update back-references Returns: List of changed fields
-
update_fields
(**kwargs)[source]¶ Update multiple fields, specified by keyword arguments.
Example:
person.update(given_name='Fred', family_name='Mercury')
... is equivalent to ...
person.given_name = 'Fred' person.family_name = 'Mercury'
Parameters: **kwargs – field names and the values to set
-
classmethod
find
(*args, **kwargs)[source]¶ Parameters: - query –
- kwargs –
Returns: an iterable of
StoredObject
instances
-
classmethod
delegate
(method, conflict=None, *args, **kwargs)[source]¶ Execute or queue a database action. Variable positional and keyword arguments are passed to the provided method.
Parameters: - method (function) – Method to execute or queue
- conflict (bool) – Potential conflict between cache_sandbox and backend, e.g., in the event of bulk updates or removes that bypass the cache_sandbox
-
classmethod
start_queue
()[source]¶ Start the queue. Between calling
start_queue
andcommit_queue
, all writes will be deferred to the queue.
-
classmethod
cancel_queue
()[source]¶ Cancel any pending actions. This method clears the queue and also clears caches if any actions are pending.
-
classmethod
commit_queue
()[source]¶ Commit all queued actions. If any actions fail, clear caches. Note: the queue will be cleared whether an error is raised or not.
-
classmethod
subscribe
(signal_name, weak=True)[source]¶ Parameters: Returns: Decorator created by
Signal::connect_via
Raises: ValueError if signal is not found
Example usage:
>>> @Schema.subscribe('before_save') ... def listener(cls, instance): ... instance.value += 1
-