views,models: simplify code computing transitive closure of MailingList models

This commit is contained in:
Benjamin Dauvergne 2013-11-29 10:23:41 +01:00
parent a87ab42812
commit a2e2887bf2
2 changed files with 4 additions and 6 deletions

View File

@ -575,12 +575,11 @@ class MailingListManager(GetByNameManager):
def are_member_of(self, users):
lists = set(MailingList.objects.filter(members__in=users))
count = len(lists)
while True: # accumulate lists until it grows no more
old_count = len(lists)
lists |= set(MailingList.objects.filter(mailing_list_members__in=lists))
if count == len(lists):
if old_count == len(lists):
break
count = len(lists)
return lists

View File

@ -69,12 +69,11 @@ def user_mailing_list_names(user):
def recursive_lists(lists):
lists = set(lists)
count = len(lists)
while True:
old_count = len(lists)
lists |= set(MailingList.objects.filter(members_lists__in=lists))
if len(lists) == count:
if len(lists) == old_count:
break
count = len(lists)
return lists
def get_file_form_kwargs(request):