fixed usage of group_names in *_change_receiver (#306)

* fixed usage of group_names in *_change_receiver

group_names was missing second arg (action)

* fixed group_names to include action

* made group_names a classmethod
This commit is contained in:
AlexejStukov 2016-08-23 19:13:46 +02:00 committed by Andrew Godwin
parent 6649afce8e
commit fcb2875b53
2 changed files with 7 additions and 6 deletions

View File

@ -140,7 +140,7 @@ class Binding(object):
if action == CREATE: if action == CREATE:
group_names = set() group_names = set()
else: else:
group_names = set(cls.group_names(instance)) group_names = set(cls.group_names(instance, action))
if not hasattr(instance, '_binding_group_names'): if not hasattr(instance, '_binding_group_names'):
instance._binding_group_names = {} instance._binding_group_names = {}
@ -155,7 +155,7 @@ class Binding(object):
if action == DELETE: if action == DELETE:
new_group_names = set() new_group_names = set()
else: else:
new_group_names = set(cls.group_names(instance)) new_group_names = set(cls.group_names(instance, action))
# if post delete, new_group_names should be [] # if post delete, new_group_names should be []
self = cls() self = cls()
@ -182,7 +182,8 @@ class Binding(object):
group = Group(group_name) group = Group(group_name)
group.send(message) group.send(message)
def group_names(self, instance, action): @classmethod
def group_names(cls, instance, action):
""" """
Returns the iterable of group names to send the object to based on the Returns the iterable of group names to send the object to based on the
instance and action performed on it. instance and action performed on it.

View File

@ -18,7 +18,7 @@ class TestsBinding(ChannelTestCase):
fields = ['username', 'email', 'password', 'last_name'] fields = ['username', 'email', 'password', 'last_name']
@classmethod @classmethod
def group_names(cls, instance): def group_names(cls, instance, action):
return ["users"] return ["users"]
def has_permission(self, user, action, pk): def has_permission(self, user, action, pk):
@ -60,7 +60,7 @@ class TestsBinding(ChannelTestCase):
fields = ['__all__'] fields = ['__all__']
@classmethod @classmethod
def group_names(cls, instance): def group_names(cls, instance, action):
return ["users2"] return ["users2"]
def has_permission(self, user, action, pk): def has_permission(self, user, action, pk):
@ -105,7 +105,7 @@ class TestsBinding(ChannelTestCase):
fields = ['username'] fields = ['username']
@classmethod @classmethod
def group_names(cls, instance): def group_names(cls, instance, action):
return ["users3"] return ["users3"]
def has_permission(self, user, action, pk): def has_permission(self, user, action, pk):