From cf5016b75e24f245faaecfb78e1cf2fc4bacb578 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Wed, 6 Nov 2013 19:24:52 -0200 Subject: [PATCH] Implementing lists dashboard --- src/super_archives/models.py | 2 +- src/super_archives/templates/message-list.html | 82 ---------------------------------------------------------------------------------- src/super_archives/templates/superarchives/thread-dashboard.html | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/super_archives/urls.py | 6 +++--- src/super_archives/views.py | 51 +++++++++++++++++++-------------------------------- 5 files changed, 68 insertions(+), 118 deletions(-) delete mode 100644 src/super_archives/templates/message-list.html create mode 100644 src/super_archives/templates/superarchives/thread-dashboard.html diff --git a/src/super_archives/models.py b/src/super_archives/models.py index e412230..01a6174 100644 --- a/src/super_archives/models.py +++ b/src/super_archives/models.py @@ -77,7 +77,7 @@ class MailingList(models.Model): last_imported_index = models.IntegerField(default=0) def get_absolute_url(self): - return u'{}?list={}'.format(reverse('thread_list'), self.name) + return u'{}?list={}'.format(reverse('thread_list'), self.name) def __unicode__(self): return self.name diff --git a/src/super_archives/templates/message-list.html b/src/super_archives/templates/message-list.html deleted file mode 100644 index 251ef1d..0000000 --- a/src/super_archives/templates/message-list.html +++ /dev/null @@ -1,82 +0,0 @@ -{% extends "base.html" %} -{% load i18n superarchives %} -{% block main-content %} -
-

{% trans "Discussions" %}

-
- -
- - -
-
    - {% for thread in threads.object_list %} - {% include "message-preview.html" with result=thread.latest_message %} - {% empty %} -

    - - {% trans "No discussion found" %} - - {% endfor %} -
- -
- - {% if n_results %} -
- {% if threads.has_previous %} - {% trans "Previous" %} - {% endif %} - - - {% trans "Page" %} {{ threads.number }} {% trans "of" %} {{ threads.paginator.num_pages }} - - - {% if threads.has_next %} - {% trans "Next" %} - {% endif %} - {% endif %} - -
-
- -{% endblock %} diff --git a/src/super_archives/templates/superarchives/thread-dashboard.html b/src/super_archives/templates/superarchives/thread-dashboard.html new file mode 100644 index 0000000..023829f --- /dev/null +++ b/src/super_archives/templates/superarchives/thread-dashboard.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block main-content %} + + {% for listname, latest, most_relevant in lists %} + {% if latest or most_relevant %} +

{{ listname|title }}

+
+ +
+
+

{% trans 'latest'|title %}

+
    + {% for thread in latest %} + {% include "message-preview.html" with result=thread.latest_message %} + {% endfor %} +
+ +
+ +
+

{% trans 'most relevant'|title %}

+
    + {% for thread in most_relevant %} + {% include "message-preview.html" with result=thread %} + {% endfor %} +
+ +
+
+ + + {% endif %} + {% endfor %} + +{% endblock %} diff --git a/src/super_archives/urls.py b/src/super_archives/urls.py index 46c1c8c..1ab90e2 100644 --- a/src/super_archives/urls.py +++ b/src/super_archives/urls.py @@ -1,13 +1,13 @@ from django.conf.urls import patterns, include, url -from .views import EmailView, EmailValidationView, ThreadView +from .views import EmailView, EmailValidationView, ThreadView, \ + ThreadDashboardView urlpatterns = patterns('super_archives.views', -# url(r'thread/(?P\d+)/$', 'thread', name='thread'), url(r'thread/(?P[-\w]+)/(?P[-\w]+)$', ThreadView.as_view(), name="thread_view"), - url(r'thread/$', 'list_messages', name='thread_list'), + url(r'thread/$', ThreadDashboardView.as_view(), name='thread_list'), url(r'manage/email/validate/?$', EmailValidationView.as_view(), name="archive_email_validation_view"), url(r'manage/email/(?P[0-9a-z]{32})?', EmailView.as_view(), diff --git a/src/super_archives/views.py b/src/super_archives/views.py index 645d798..42ddf5d 100644 --- a/src/super_archives/views.py +++ b/src/super_archives/views.py @@ -18,6 +18,8 @@ from django.utils.decorators import method_decorator from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect +from haystack.query import SearchQuerySet + from . import queries from .utils.email import send_verification_email from .models import MailingList, Thread, EmailAddress, EmailAddressValidation @@ -108,38 +110,23 @@ class ThreadView(View): return self.get(request, mailinglist, thread_token) -def list_messages(request): - selected_lists = request.GET.get('list', []) - if selected_lists: - selected_lists = selected_lists.split() - - order_by = request.GET.get('order') - if order_by == 'hottest': - threads = queries.get_hottest_threads() - else: - threads = queries.get_latest_threads() - - mail_list = selected_lists - if mail_list: - threads = threads.filter(mailinglist__name__in=mail_list) - - paginator = Paginator(threads, 16) - try: - page = int(request.GET.get('p', '1')) - except ValueError: - page = 1 - threads = paginator.page(page) - - lists = MailingList.objects.all() - - template_data = { - 'lists': lists, - 'n_results': paginator.count, - 'threads': threads, - 'selected_lists': ' '.join(selected_lists) if selected_lists else '', - 'order_data': settings.ORDERING_DATA, - } - return render(request, 'message-list.html', template_data) +class ThreadDashboardView(View): + http_method_names = ['get'] + + def get(self, request): + MAX = 6 + context = {} + + context['lists'] = [] + lists = MailingList.objects.filter() + for list_ in MailingList.objects.order_by('name'): + context['lists'].append(( + list_.name, + list_.thread_set.filter(spam=False)[:MAX], + SearchQuerySet().filter(type='thread', tag=list_.name)[:MAX], + )) + + return render(request, 'superarchives/thread-dashboard.html', context) class EmailView(View): -- libgit2 0.21.2