From 49c9b74d6f19812aa6dd2126e9a9499eea8f3175 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 25 May 2016 17:52:53 -0700 Subject: [PATCH] Docs/flake fixes --- channels/generic/__init__.py | 2 +- channels/generic/websockets.py | 2 +- channels/utils.py | 1 + docs/generics.rst | 6 ++++-- docs/routing.rst | 5 +++++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/channels/generic/__init__.py b/channels/generic/__init__.py index 3d08a87..8374ebb 100644 --- a/channels/generic/__init__.py +++ b/channels/generic/__init__.py @@ -1 +1 @@ -from .base import BaseConsumer +from .base import BaseConsumer # NOQA isort:skip diff --git a/channels/generic/websockets.py b/channels/generic/websockets.py index 9faf75d..af81ab2 100644 --- a/channels/generic/websockets.py +++ b/channels/generic/websockets.py @@ -92,7 +92,7 @@ class WebsocketConsumer(BaseConsumer): else: raise ValueError("You must pass text or bytes") - def disconnect(self, message, **kwargs): + def raw_disconnect(self, message, **kwargs): """ Called when a WebSocket connection is closed. Base level so you don't need to call super() all the time. diff --git a/channels/utils.py b/channels/utils.py index dc96201..548c307 100644 --- a/channels/utils.py +++ b/channels/utils.py @@ -1,5 +1,6 @@ import types + def name_that_thing(thing): """ Returns either the function/class path or just the object's repr diff --git a/docs/generics.rst b/docs/generics.rst index 44f9629..064e31c 100644 --- a/docs/generics.rst +++ b/docs/generics.rst @@ -10,7 +10,7 @@ We recommend you use them if you find them valuable; normal function-based consumers are also entirely valid, however, and may result in more readable code for simpler tasks. -There is one base class-based consumer class, ``BaseConsumer``, that provides +There is one base generic consumer class, ``BaseConsumer``, that provides the pattern for method dispatch and is the thing you can build entirely custom consumers on top of, and then protocol-specific subclasses that provide extra utility - for example, the ``WebsocketConsumer`` provides automatic @@ -104,6 +104,8 @@ are used to add the socket to when it connects and to remove it from when it disconnects; you get keyword arguments too if your URL path, say, affects which group to talk to. +Additionally, the property ``self.path`` is always set to the current URL path. + The JSON-enabled consumer looks slightly different:: from channels.generic.websockets import JsonWebsocketConsumer @@ -140,7 +142,7 @@ The JSON-enabled consumer looks slightly different:: """ pass -For this subclass, ``receive`` only gets a ``content`` parameter that is the +For this subclass, ``receive`` only gets a ``content`` argument that is the already-decoded JSON as Python datastructures; similarly, ``send`` now only takes a single argument, which it JSON-encodes before sending down to the client. diff --git a/docs/routing.rst b/docs/routing.rst index d3fd116..e4b5c63 100644 --- a/docs/routing.rst +++ b/docs/routing.rst @@ -74,3 +74,8 @@ strips off the ``/liveblog`` part it matches before passing it inside:: routing = [ include(inner_routes, path=r'^/liveblog') ] + +You can also include named capture groups in the filters on an include and +they'll be passed to the consumer just like those on ``route``; note, though, +that if the keyword argument names from the ``include`` and the ``route`` +clash, the values from ``route`` will take precedence.