dddp.api¶
Django DDP API, Collections, Cursors and Publications.
-
class
dddp.api.
APIMixin
[source]¶ Mixin to support finding API endpoints for class instances.
-
api_endpoint
(api_path)¶ Return API endpoint for given api_path.
-
api_path_map
()¶ Cached dict of api_path: func.
-
clear_api_path_map_cache
()¶ Clear out cache for api_path_map.
-
ready
()¶ Initialisation (setup lookups and signal handlers).
-
-
class
dddp.api.
Collection
[source]¶ DDP Model Collection.
-
field_schema
()¶ Generate schema for consumption by clients.
-
get_queryset
(base_qs=None)¶ Return a filtered, ordered queryset for this collection.
-
obj_change_as_msg
(obj, msg, meteor_ids=None)¶ Return DDP change message of specified type (msg) for obj.
-
objects_for_user
(user, qs=None, xmin__lte=None)¶ Find objects in queryset related to specified user.
-
queryset
¶ Return a filtered, ordered queryset for this collection.
-
schema
()¶ Return a representation of the schema for this collection.
-
serialize
(obj, meteor_ids)¶ Generate a DDP msg for obj with specified msg type.
-
user_ids_for_object
(obj)¶ Find user IDs related to object/pk in queryset.
-
user_model
¶ Cached property getter around get_user_model.
-
-
class
dddp.api.
DDP
[source]¶ Django DDP API.
-
api_providers
¶ Return an iterable of API providers.
-
do_sub
(*args, **kwargs)¶ Subscribe the current thread to the specified publication.
-
do_unsub
(id_, silent)¶ Unsubscribe the current thread from the specified subscription id.
-
get_col_by_name
(name)¶ Return collection instance for given name.
-
get_collection
(model)¶ Return collection instance for given model.
-
get_pub_by_name
(name)¶ Return publication instance for given name.
-
method
(method, params, id_)¶ Invoke a method.
-
on_m2m_changed
(sender, **kwargs)¶ M2M-changed signal handler.
-
on_post_delete
(sender, **kwargs)¶ Post-delete signal handler.
-
on_post_migrate
(sender, **kwargs)¶ Post-migrate signal handler.
-
on_post_save
(sender, **kwargs)¶ Post-save signal handler.
-
on_pre_change
(sender, **kwargs)¶ Pre change (save/delete) signal handler.
-
on_pre_migrate
(sender, **kwargs)¶ Pre-migrate signal handler.
-
qs_and_collection
(qs)¶ Return (qs, collection) from qs (which may be a tuple).
-
ready
()¶ Initialisation for django-ddp (setup lookups and signal handlers).
-
register
(api_or_iterable)¶ Register an API endpoint.
-
schema
()¶ Return schema for all registered collections.
-
send_notify
(model, obj, msg, using)¶ Dispatch PostgreSQL async NOTIFY.
-
sub
(id_, name, *params)¶ Create subscription, send matched objects that haven’t been sent.
-
sub_unique_objects
(obj, params=None, pub=None, *args, **kwargs)¶ Return objects that are only visible through given subscription.
-
unsub
(id_)¶ Remove a subscription.
-
valid_subscribers
(model, obj, using)¶ Calculate valid subscribers (connections) for obj.
-
-
class
dddp.api.
Publication
[source]¶ DDP Publication (a set of queries).
-
collections
(*params)¶ Return list of collections for this publication.
-
user_queries
(user, *params)¶ Return queries for this publication as seen by user.
-
-
dddp.api.
api_endpoint
(path_or_func=None, decorate=True)[source]¶ Decorator to mark a method as an API endpoint for later registration.
Parameters: - path_or_func – either the function to be decorated or its API path.
- decorate (bool) – Apply API_ENDPOINT_DECORATORS if True (default).
Returns: Decorated function (with optionally applied decorators).
Return type: Callable
Examples
>>> from dddp.api import APIMixin, api_endpoint >>> class Counter(APIMixin): ... value = 0 ... ... # default API path matches function name 'increment'. ... @api_endpoint ... def increment(self, amount): ... '''Increment counter value by `amount`.''' ... self.value += amount ... return self.value ... ... # excplicitly set API path to 'Decrement'. ... @api_endpoint('Decrement') ... def decrement(self, amount): ... '''Decrement counter value by `amount`.''' ... self.value -= amount ... return self.value