Commit efd80e8cedb2f0e14951e43667c7a5b3a1f3a656
1 parent
71357f92
Exists in
master
and in
11 other branches
Moving from View to ListView
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Sergio Oliveira <sergio@tracy.com.br>
Showing
1 changed file
with
23 additions
and
28 deletions
Show diff stats
colab/super_archives/views.py
| ... | ... | @@ -11,7 +11,8 @@ from django.conf import settings |
| 11 | 11 | from django.contrib import messages |
| 12 | 12 | from django.core.urlresolvers import reverse |
| 13 | 13 | from django.db import IntegrityError |
| 14 | -from django.views.generic import View | |
| 14 | +from django.db.models import Q | |
| 15 | +from django.views.generic import View, ListView | |
| 15 | 16 | from django.utils.translation import ugettext as _ |
| 16 | 17 | from django.core.exceptions import ObjectDoesNotExist, PermissionDenied |
| 17 | 18 | from django.utils.decorators import method_decorator |
| ... | ... | @@ -137,42 +138,36 @@ class ThreadView(View): |
| 137 | 138 | return self.get(request, mailinglist, thread_token) |
| 138 | 139 | |
| 139 | 140 | |
| 140 | -class ThreadDashboardView(View): | |
| 141 | +class ThreadDashboardView(ListView): | |
| 141 | 142 | http_method_names = ['get'] |
| 143 | + context_object_name = 'lists' | |
| 144 | + template_name = 'superarchives/thread-dashboard.html' | |
| 142 | 145 | |
| 143 | - def get(self, request): | |
| 146 | + def get_queryset(self): | |
| 144 | 147 | MAX = 6 |
| 145 | - context = {} | |
| 146 | - | |
| 147 | - all_privates = {} | |
| 148 | - private_mailinglist = MailingList.objects.filter(is_private=True) | |
| 149 | - for mailinglist in private_mailinglist: | |
| 150 | - all_privates[mailinglist.name] = True | |
| 151 | - | |
| 152 | - context['lists'] = [] | |
| 148 | + queryset = [] | |
| 153 | 149 | |
| 154 | 150 | listnames_for_user = [] |
| 155 | - if request.user.is_authenticated(): | |
| 156 | - user = User.objects.get(username=request.user) | |
| 151 | + if self.request.user.is_authenticated(): | |
| 152 | + user = User.objects.get(username=self.request.user) | |
| 157 | 153 | lists_for_user = mailman.get_user_mailinglists(user) |
| 158 | 154 | listnames_for_user = mailman.extract_listname_from_list( |
| 159 | 155 | lists_for_user) |
| 160 | 156 | |
| 161 | - for list_ in MailingList.objects.order_by('name'): | |
| 162 | - if list_.name not in all_privates\ | |
| 163 | - or list_.name in listnames_for_user: | |
| 164 | - context['lists'].append(( | |
| 165 | - list_.name, | |
| 166 | - mailman.get_list_description(list_.name), | |
| 167 | - list_.thread_set.filter(spam=False).order_by( | |
| 168 | - '-latest_message__received_time' | |
| 169 | - )[:MAX], | |
| 170 | - [t.latest_message for t in Thread.highest_score.filter( | |
| 171 | - mailinglist__name=list_.name)[:MAX]], | |
| 172 | - len(mailman.list_users(list_.name)), | |
| 173 | - )) | |
| 174 | - | |
| 175 | - return render(request, 'superarchives/thread-dashboard.html', context) | |
| 157 | + 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 | + | |
| 170 | + return queryset | |
| 176 | 171 | |
| 177 | 172 | |
| 178 | 173 | class EmailView(View): | ... | ... |