tg_pubsub package¶
Subpackages¶
Submodules¶
tg_pubsub.config module¶
-
tg_pubsub.config.get_extra_models()[source]¶ - Get extra models to mark as listenable. This is useful if one needs to listen to changes
on a model that is coming from external apps so subclassing variant is impossible.
TG_PUBSUB_EXTRA_MODELS: list(config_path, ...)
Return type: dict
tg_pubsub.exceptions module¶
tg_pubsub.messages module¶
tg_pubsub.models module¶
-
class
tg_pubsub.models.ListenableBase[source]¶ Bases:
objectBase mixin that declares the api for listenables
-
classmethod
has_access(instance, user)[source]¶ Does the given user has access to the model instance. This can be used to only send model data to specific users.
(Note: The user may be anonymous)
Parameters: - instance – Model instance
- user – User connected via pubsub
Return type: bool
-
classmethod
pubsub_serialize(instance, serializer)[source]¶ Serialize the given model instance before sending it to the users.
Parameters: - instance – Model instance
- serializer – Drf serializer
Returns:
-
serializer_class= None¶
-
serializer_fields= ('pk',)¶
-
classmethod
should_notify(instance, action)[source]¶ Should the given instance send out a change notification. This can be used to limit publishes to only specific instances.
Parameters: - instance – Model instance
- action – Action that triggered the notification (created, saved, deleted)
Return type: bool
-
classmethod
-
class
tg_pubsub.models.ListenableModelMixin[source]¶ Bases:
tg_pubsub.models.ListenableBaseMixin that will mark model as ‘listenable’. Such models will send messages to Redis queue whenever they’re updated.
-
class
tg_pubsub.models.ModelListenConfig[source]¶ Bases:
tg_pubsub.models.ListenableModelMixinSpecial class that can be used to mark external app models as listenable.
via: TG_PUBSUB_EXTRA_MODELS
-
model_path= None¶
-
tg_pubsub.protocol module¶
-
class
tg_pubsub.protocol.AnonymousUserServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.AnyUserServerProtocolWebSocketServerProtocol implementation that only allows anonymous users
-
class
tg_pubsub.protocol.AnyUserServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.SessionRequiredServerProtocolWebSocketServerProtocol implementation that allows any users (that provide a token)
-
class
tg_pubsub.protocol.AuthenticatedUserServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.AnyUserServerProtocolWebSocketServerProtocol implementation that only allows authenticated users
-
class
tg_pubsub.protocol.RequestServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
websockets.server.WebSocketServerProtocolWebSocketServerProtocol that gives handler a request-like object which might contain the session/user if token was provided.
-
TOKEN_PARAM= 'token'¶
-
-
class
tg_pubsub.protocol.SessionRequiredServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.RequestServerProtocolWebSocketServerProtocol which only allows handshakes with a valid token
-
class
tg_pubsub.protocol.StaffUserServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.AuthenticatedUserServerProtocolWebSocketServerProtocol implementation that only allows staff users
-
class
tg_pubsub.protocol.SuperUserServerProtocol(ws_handler, ws_server, *, origins=None, subprotocols=None, extra_headers=None, **kwds)[source]¶ Bases:
tg_pubsub.protocol.StaffUserServerProtocolWebSocketServerProtocol implementation that only allows superusers