diff --git a/colab/accounts/utils/mailman.py b/colab/accounts/utils/mailman.py index e6728ba..43d86ca 100644 --- a/colab/accounts/utils/mailman.py +++ b/colab/accounts/utils/mailman.py @@ -49,10 +49,6 @@ def update_subscription(address, lists): subscribe(maillist, address) -def address_lists(address): - return mailing_lists(address=address) - - def mailing_lists(**kwargs): url = get_url() @@ -66,11 +62,14 @@ def mailing_lists(**kwargs): def is_private_list(name): - return dict(all_lists(private=True))[name] + try: + return dict(all_lists(private=True))[name] + except KeyError: + return [] -def all_lists(*args, **kwargs): - return mailing_lists(*args, **kwargs) +def all_lists(**kwargs): + return mailing_lists(**kwargs) def user_lists(user): @@ -111,8 +110,7 @@ def get_user_mailinglists(user): if user: emails = user.emails.values_list('address', flat=True) - lists_for_user = [] for email in emails: - lists_for_user.extend(address_lists(email)) + lists_for_user.extend(mailing_lists(address=email)) return lists_for_user diff --git a/colab/accounts/views.py b/colab/accounts/views.py index 96c2bcc..f8bc8d3 100644 --- a/colab/accounts/views.py +++ b/colab/accounts/views.py @@ -188,7 +188,7 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): for email in emails: lists = [] - lists_for_address = mailman.address_lists(email) + lists_for_address = mailman.mailing_lists(address=email) for listname, description in all_lists: if listname in lists_for_address: checked = True diff --git a/colab/home/views.py b/colab/home/views.py index 3c927dd..4e16481 100644 --- a/colab/home/views.py +++ b/colab/home/views.py @@ -8,6 +8,16 @@ from colab.accounts.utils import mailman from colab.accounts.models import User +def get_user_threads(threads, lists_for_user, key): + visible_threads = [] + for t in threads: + if not t.mailinglist.is_private or \ + t.mailinglist.name in lists_for_user: + visible_threads.append(key(t)) + + return visible_threads + + def dashboard(request): """Dashboard page""" @@ -22,16 +32,10 @@ def dashboard(request): user = User.objects.get(username=request.user) lists_for_user = mailman.get_user_mailinglists(user) - for t in all_threads: - if not t.mailinglist.is_private or \ - t.mailinglist.name in lists_for_user: - latest_threads.append(t) - - hottest_threads = [] - for t in highest_score_threads: - if not t.mailinglist.is_private or \ - t.mailinglist.name in lists_for_user: - hottest_threads.append(t.latest_message) + latest_threads = get_user_threads( + all_threads, lists_for_user, lambda t: t) + hottest_threads = get_user_threads( + highest_score_threads, lists_for_user, lambda t: t.latest_message) latest_results, count_types = get_collaboration_data(user) latest_results.sort(key=lambda elem: elem.modified, reverse=True) diff --git a/colab/search/utils.py b/colab/search/utils.py index 61ddbf2..b07e135 100644 --- a/colab/search/utils.py +++ b/colab/search/utils.py @@ -6,7 +6,7 @@ from collections import OrderedDict from django.core.cache import cache from django.utils.translation import ugettext as _ from django.conf import settings -from django.db.models import Q +from django.db.models import Q as Condition from colab.super_archives.models import Thread, Message from colab.proxy.utils.models import Collaboration @@ -14,16 +14,16 @@ from colab.accounts.utils import mailman def get_visible_threads_queryset(logged_user): - qs = Thread.objects + queryset = Thread.objects lists_for_user = [] if logged_user: lists_for_user = mailman.get_user_mailinglists(logged_user) - q1 = Q(mailinglist__name__in=lists_for_user) - q2 = Q(mailinglist__is_private=False) - qs = Thread.objects.filter(q1 | q2) + user_lists = Condition(mailinglist__name__in=lists_for_user) + public_lists = Condition(mailinglist__is_private=False) + queryset = Thread.objects.filter(user_lists | public_lists) - return qs + return queryset def get_visible_threads(logged_user, filter_by_user=None): diff --git a/colab/super_archives/management/commands/message.py b/colab/super_archives/management/commands/message.py index bf86c73..8bbe54b 100644 --- a/colab/super_archives/management/commands/message.py +++ b/colab/super_archives/management/commands/message.py @@ -79,7 +79,7 @@ class Message(mailbox.mboxMessage): return body.strip() def get_received_datetime(self): - if ('Received') not in self: + if 'Received' not in self: return None # The time received should always be the last element # in the `Received` attribute from the message headers diff --git a/colab/super_archives/views.py b/colab/super_archives/views.py index 5cad7f4..63789c0 100644 --- a/colab/super_archives/views.py +++ b/colab/super_archives/views.py @@ -137,8 +137,8 @@ class ThreadDashboardView(View): all_privates = {} private_mailinglist = MailingList.objects.filter(is_private=True) - for ml in private_mailinglist: - all_privates[ml.name] = True + for mailinglist in private_mailinglist: + all_privates[mailinglist.name] = True context['lists'] = [] -- libgit2 0.21.2