Commit 058dc7b08e19989dfe6e2b06a6c3bb8fbb81f3aa

Authored by Gust
Committed by Sergio Oliveira
1 parent 7399ae6f

Fix MR seggestions

Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Signed-off-by: Carolina Ramalho <carol15022@hotmail.com>
colab/accounts/utils/mailman.py
@@ -49,10 +49,6 @@ def update_subscription(address, lists): @@ -49,10 +49,6 @@ def update_subscription(address, lists):
49 subscribe(maillist, address) 49 subscribe(maillist, address)
50 50
51 51
52 -def address_lists(address):  
53 - return mailing_lists(address=address)  
54 -  
55 -  
56 def mailing_lists(**kwargs): 52 def mailing_lists(**kwargs):
57 url = get_url() 53 url = get_url()
58 54
@@ -66,11 +62,14 @@ def mailing_lists(**kwargs): @@ -66,11 +62,14 @@ def mailing_lists(**kwargs):
66 62
67 63
68 def is_private_list(name): 64 def is_private_list(name):
69 - return dict(all_lists(private=True))[name] 65 + try:
  66 + return dict(all_lists(private=True))[name]
  67 + except KeyError:
  68 + return []
70 69
71 70
72 -def all_lists(*args, **kwargs):  
73 - return mailing_lists(*args, **kwargs) 71 +def all_lists(**kwargs):
  72 + return mailing_lists(**kwargs)
74 73
75 74
76 def user_lists(user): 75 def user_lists(user):
@@ -111,8 +110,7 @@ def get_user_mailinglists(user): @@ -111,8 +110,7 @@ def get_user_mailinglists(user):
111 if user: 110 if user:
112 emails = user.emails.values_list('address', flat=True) 111 emails = user.emails.values_list('address', flat=True)
113 112
114 - lists_for_user = []  
115 for email in emails: 113 for email in emails:
116 - lists_for_user.extend(address_lists(email)) 114 + lists_for_user.extend(mailing_lists(address=email))
117 115
118 return lists_for_user 116 return lists_for_user
colab/accounts/views.py
@@ -188,7 +188,7 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): @@ -188,7 +188,7 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView):
188 188
189 for email in emails: 189 for email in emails:
190 lists = [] 190 lists = []
191 - lists_for_address = mailman.address_lists(email) 191 + lists_for_address = mailman.mailing_lists(address=email)
192 for listname, description in all_lists: 192 for listname, description in all_lists:
193 if listname in lists_for_address: 193 if listname in lists_for_address:
194 checked = True 194 checked = True
colab/home/views.py
@@ -8,6 +8,16 @@ from colab.accounts.utils import mailman @@ -8,6 +8,16 @@ from colab.accounts.utils import mailman
8 from colab.accounts.models import User 8 from colab.accounts.models import User
9 9
10 10
  11 +def get_user_threads(threads, lists_for_user, key):
  12 + visible_threads = []
  13 + for t in threads:
  14 + if not t.mailinglist.is_private or \
  15 + t.mailinglist.name in lists_for_user:
  16 + visible_threads.append(key(t))
  17 +
  18 + return visible_threads
  19 +
  20 +
11 def dashboard(request): 21 def dashboard(request):
12 """Dashboard page""" 22 """Dashboard page"""
13 23
@@ -22,16 +32,10 @@ def dashboard(request): @@ -22,16 +32,10 @@ def dashboard(request):
22 user = User.objects.get(username=request.user) 32 user = User.objects.get(username=request.user)
23 lists_for_user = mailman.get_user_mailinglists(user) 33 lists_for_user = mailman.get_user_mailinglists(user)
24 34
25 - for t in all_threads:  
26 - if not t.mailinglist.is_private or \  
27 - t.mailinglist.name in lists_for_user:  
28 - latest_threads.append(t)  
29 -  
30 - hottest_threads = []  
31 - for t in highest_score_threads:  
32 - if not t.mailinglist.is_private or \  
33 - t.mailinglist.name in lists_for_user:  
34 - hottest_threads.append(t.latest_message) 35 + latest_threads = get_user_threads(
  36 + all_threads, lists_for_user, lambda t: t)
  37 + hottest_threads = get_user_threads(
  38 + highest_score_threads, lists_for_user, lambda t: t.latest_message)
35 39
36 latest_results, count_types = get_collaboration_data(user) 40 latest_results, count_types = get_collaboration_data(user)
37 latest_results.sort(key=lambda elem: elem.modified, reverse=True) 41 latest_results.sort(key=lambda elem: elem.modified, reverse=True)
colab/search/utils.py
@@ -6,7 +6,7 @@ from collections import OrderedDict @@ -6,7 +6,7 @@ from collections import OrderedDict
6 from django.core.cache import cache 6 from django.core.cache import cache
7 from django.utils.translation import ugettext as _ 7 from django.utils.translation import ugettext as _
8 from django.conf import settings 8 from django.conf import settings
9 -from django.db.models import Q 9 +from django.db.models import Q as Condition
10 10
11 from colab.super_archives.models import Thread, Message 11 from colab.super_archives.models import Thread, Message
12 from colab.proxy.utils.models import Collaboration 12 from colab.proxy.utils.models import Collaboration
@@ -14,16 +14,16 @@ from colab.accounts.utils import mailman @@ -14,16 +14,16 @@ from colab.accounts.utils import mailman
14 14
15 15
16 def get_visible_threads_queryset(logged_user): 16 def get_visible_threads_queryset(logged_user):
17 - qs = Thread.objects 17 + queryset = Thread.objects
18 lists_for_user = [] 18 lists_for_user = []
19 if logged_user: 19 if logged_user:
20 lists_for_user = mailman.get_user_mailinglists(logged_user) 20 lists_for_user = mailman.get_user_mailinglists(logged_user)
21 21
22 - q1 = Q(mailinglist__name__in=lists_for_user)  
23 - q2 = Q(mailinglist__is_private=False)  
24 - qs = Thread.objects.filter(q1 | q2) 22 + user_lists = Condition(mailinglist__name__in=lists_for_user)
  23 + public_lists = Condition(mailinglist__is_private=False)
  24 + queryset = Thread.objects.filter(user_lists | public_lists)
25 25
26 - return qs 26 + return queryset
27 27
28 28
29 def get_visible_threads(logged_user, filter_by_user=None): 29 def get_visible_threads(logged_user, filter_by_user=None):
colab/super_archives/management/commands/message.py
@@ -79,7 +79,7 @@ class Message(mailbox.mboxMessage): @@ -79,7 +79,7 @@ class Message(mailbox.mboxMessage):
79 return body.strip() 79 return body.strip()
80 80
81 def get_received_datetime(self): 81 def get_received_datetime(self):
82 - if ('Received') not in self: 82 + if 'Received' not in self:
83 return None 83 return None
84 # The time received should always be the last element 84 # The time received should always be the last element
85 # in the `Received` attribute from the message headers 85 # in the `Received` attribute from the message headers
colab/super_archives/views.py
@@ -137,8 +137,8 @@ class ThreadDashboardView(View): @@ -137,8 +137,8 @@ class ThreadDashboardView(View):
137 137
138 all_privates = {} 138 all_privates = {}
139 private_mailinglist = MailingList.objects.filter(is_private=True) 139 private_mailinglist = MailingList.objects.filter(is_private=True)
140 - for ml in private_mailinglist:  
141 - all_privates[ml.name] = True 140 + for mailinglist in private_mailinglist:
  141 + all_privates[mailinglist.name] = True
142 142
143 context['lists'] = [] 143 context['lists'] = []
144 144