diff --git a/channels/__init__.py b/channels/__init__.py index 2b9a471..e5d43b7 100644 --- a/channels/__init__.py +++ b/channels/__init__.py @@ -17,4 +17,4 @@ from .hacks import monkeypatch_django monkeypatch_django() # Promote channel to top-level (down here to avoid circular import errs) -from .channel import Channel +from .channel import Channel, Group diff --git a/channels/channel.py b/channels/channel.py index 6724eba..faf5f3a 100644 --- a/channels/channel.py +++ b/channels/channel.py @@ -58,7 +58,7 @@ class Group(object): of the group after an expiry time (keep re-adding to keep them in). """ - def __init__(self, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None): + def __init__(self, name, alias=DEFAULT_CHANNEL_BACKEND, channel_backend=None): self.name = name if channel_backend: self.channel_backend = channel_backend @@ -66,13 +66,13 @@ class Group(object): self.channel_backend = channel_backends[alias] def add(self, channel): - self.channel_backend.add(self.name, channel) + self.channel_backend.group_add(self.name, channel) def discard(self, channel): - self.channel_backend.discard(self.name, channel) + self.channel_backend.group_discard(self.name, channel) def channels(self): - self.channel_backend.channels(self.name) + self.channel_backend.group_channels(self.name) def send(self, **kwargs): - self.channel_backend.send_group(self, self.name, kwargs) + self.channel_backend.send_group(self.name, kwargs) diff --git a/channels/decorators.py b/channels/decorators.py index 5a94850..584f66a 100644 --- a/channels/decorators.py +++ b/channels/decorators.py @@ -5,10 +5,12 @@ from django.utils import six from channels import channel_backends, DEFAULT_CHANNEL_BACKEND -def consumer(self, alias=DEFAULT_CHANNEL_BACKEND, *channels): +def consumer(*channels, **kwargs): """ Decorator that registers a function as a consumer. """ + # We can't put a kwarg after *args in py2 + alias = kwargs.get("alias", DEFAULT_CHANNEL_BACKEND) # Upconvert if you just pass in a string if isinstance(channels, six.string_types): channels = [channels]