Commit b68b6b67cbb76321cb005f775ab65f04d5802a54
1 parent
f3acac32
Exists in
master
and in
10 other branches
Refactored ThreadDashboard
- Removed the behavior of passing a list of tuples from queryset - Return a list of MailingLists from queryset - Adapted the view for the new list Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com> Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
4 changed files
with
28 additions
and
26 deletions
Show diff stats
colab/super_archives/models.py
... | ... | @@ -88,6 +88,8 @@ class MailingList(models.Model): |
88 | 88 | last_imported_index = models.IntegerField(default=0) |
89 | 89 | is_private = models.BooleanField(default=False) |
90 | 90 | |
91 | + _max_latest_threads = 6 | |
92 | + | |
91 | 93 | def update_privacy(self): |
92 | 94 | self.is_private = mailman.is_private_list(self.name) |
93 | 95 | |
... | ... | @@ -100,6 +102,20 @@ class MailingList(models.Model): |
100 | 102 | return u'{}?{}'.format(reverse('haystack_search'), |
101 | 103 | urllib.urlencode(params)) |
102 | 104 | |
105 | + def get_latest(self): | |
106 | + not_spam_latest = self.thread_set.filter(spam=False) | |
107 | + ordered_latest = not_spam_latest.order_by( | |
108 | + '-latest_message__received_time') | |
109 | + return ordered_latest[:self._max_latest_threads] | |
110 | + | |
111 | + def get_most_relevant(self): | |
112 | + all_most_relevant = Thread.highest_score.filter( | |
113 | + mailinglist__name=self.name)[:self._max_latest_threads] | |
114 | + return [thread.latest_message for thread in all_most_relevant] | |
115 | + | |
116 | + def get_number_of_users(self): | |
117 | + return len(mailman.list_users(self.name)) | |
118 | + | |
103 | 119 | def __unicode__(self): |
104 | 120 | return self.name |
105 | 121 | ... | ... |
colab/super_archives/templates/superarchives/thread-dashboard.html
... | ... | @@ -7,11 +7,11 @@ |
7 | 7 | <h2>{% trans 'Groups'|title %}</h2> |
8 | 8 | <hr/> |
9 | 9 | |
10 | - {% for listname, description, latest, most_relevant, number_of_users in lists %} | |
11 | - {% if latest or most_relevant %} | |
12 | - <h3><b>{{ listname|title|lower }} {% if description %} ({{ description }}){% endif %}</b></h3> | |
10 | + {% for mailinglist in lists %} | |
11 | + {% if mailinglist.get_latest or mailinglist.get_most_relevant %} | |
12 | + <h3><b>{{ mailinglist.name|title|lower }} {% if mailinglist.description %} ({{ mailinglist.description }}){% endif %}</b></h3> | |
13 | 13 | <div class="btn-group btn-group-sm"> |
14 | - <a href="#" class="btn btn-default" disabled="disabled">{% blocktrans %}{{ number_of_users }} members{% endblocktrans %}</a> | |
14 | + <a href="#" class="btn btn-default" disabled="disabled">{% blocktrans with number_of_users=mailinglist.get_number_of_users %}{{ number_of_users }} members{% endblocktrans %}</a> | |
15 | 15 | </div> |
16 | 16 | <hr/> |
17 | 17 | |
... | ... | @@ -19,12 +19,12 @@ |
19 | 19 | <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> |
20 | 20 | <h4>{% trans 'latest'|title %}</h4> |
21 | 21 | <ul class="message-list"> |
22 | - {% for thread in latest %} | |
22 | + {% for thread in mailinglist.get_latest %} | |
23 | 23 | {% include "message-preview.html" with result=thread.latest_message %} |
24 | 24 | {% endfor %} |
25 | 25 | </ul> |
26 | 26 | <div class="text-right"> |
27 | - <a href="{% url 'haystack_search' %}?order=latest&list={{ listname }}&type=thread"> | |
27 | + <a href="{% url 'haystack_search' %}?order=latest&list={{ mailinglist.name }}&type=thread"> | |
28 | 28 | {% trans "more..." %} |
29 | 29 | </a> |
30 | 30 | </div> |
... | ... | @@ -33,12 +33,12 @@ |
33 | 33 | <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> |
34 | 34 | <h4>{% trans 'most relevant'|title %}</h4> |
35 | 35 | <ul class="message-list"> |
36 | - {% for thread in most_relevant %} | |
36 | + {% for thread in mailinglist.get_most_relevant %} | |
37 | 37 | {% include "message-preview.html" with result=thread %} |
38 | 38 | {% endfor %} |
39 | 39 | </ul> |
40 | 40 | <div class="text-right"> |
41 | - <a href="{% url 'haystack_search' %}?list={{ listname }}&type=thread"> | |
41 | + <a href="{% url 'haystack_search' %}?list={{ mailinglist.name }}&type=thread"> | |
42 | 42 | {% trans "more..." %} |
43 | 43 | </a> |
44 | 44 | </div> | ... | ... |
colab/super_archives/tests/test_privatelist.py
... | ... | @@ -27,8 +27,8 @@ class ArchivesViewTest(TestCase): |
27 | 27 | |
28 | 28 | list_data = request.context['lists'] |
29 | 29 | |
30 | - self.assertEqual('lista', list_data[0][0]) | |
31 | - self.assertEqual('privatelist', list_data[1][0]) | |
30 | + self.assertEqual('lista', list_data[0].name) | |
31 | + self.assertEqual('privatelist', list_data[1].name) | |
32 | 32 | self.assertEqual(2, len(list_data)) |
33 | 33 | |
34 | 34 | def test_see_only_public_if_not_logged_in(self): |
... | ... | @@ -36,7 +36,7 @@ class ArchivesViewTest(TestCase): |
36 | 36 | |
37 | 37 | list_data = request.context['lists'] |
38 | 38 | |
39 | - self.assertEqual('lista', list_data[0][0]) | |
39 | + self.assertEqual('lista', list_data[0].name) | |
40 | 40 | self.assertEqual(1, len(list_data)) |
41 | 41 | |
42 | 42 | def test_see_private_thread_in_dashboard_if_member(self): | ... | ... |
colab/super_archives/views.py
... | ... | @@ -144,9 +144,6 @@ class ThreadDashboardView(ListView): |
144 | 144 | template_name = 'superarchives/thread-dashboard.html' |
145 | 145 | |
146 | 146 | def get_queryset(self): |
147 | - MAX = 6 | |
148 | - queryset = [] | |
149 | - | |
150 | 147 | listnames_for_user = [] |
151 | 148 | if self.request.user.is_authenticated(): |
152 | 149 | user = User.objects.get(username=self.request.user) |
... | ... | @@ -155,19 +152,8 @@ class ThreadDashboardView(ListView): |
155 | 152 | lists_for_user) |
156 | 153 | |
157 | 154 | query = Q(is_private=False) | Q(name__in=listnames_for_user) |
158 | - for list_ in MailingList.objects.filter(query).order_by('name'): | |
159 | - queryset.append(( | |
160 | - list_.name, | |
161 | - mailman.get_list_description(list_.name), | |
162 | - list_.thread_set.filter(spam=False).order_by( | |
163 | - '-latest_message__received_time' | |
164 | - )[:MAX], | |
165 | - [t.latest_message for t in Thread.highest_score.filter( | |
166 | - mailinglist__name=list_.name)[:MAX]], | |
167 | - len(mailman.list_users(list_.name)), | |
168 | - )) | |
169 | 155 | |
170 | - return queryset | |
156 | + return MailingList.objects.filter(query).order_by('name') | |
171 | 157 | |
172 | 158 | |
173 | 159 | class EmailView(View): | ... | ... |