Use already_notified in get_all_groups

This commit is contained in:
Tom Hubrecht 2021-10-26 18:53:31 +02:00
parent f257209f8f
commit 9c02e1e902

View file

@ -70,14 +70,20 @@ class WikiGroup(models.Model):
return False
def get_all_groups(self):
def get_all_groups(self, already_notified=None):
"""Returns the set of metagroups i.e. self plus the list of groups including
this group recursively"""
if already_notified is None:
already_notified = set()
elif self.pk in already_notified:
return set()
already_notified.add(self.pk)
groups = {self}
for metagroup in self.included_in_groups.all():
groups |= metagroup.get_all_groups()
groups |= metagroup.get_all_groups(already_notified=already_notified)
return groups