Commit cf5016b75e24f245faaecfb78e1cf2fc4bacb578
1 parent
358a1621
Exists in
master
and in
39 other branches
Implementing lists dashboard
Showing
5 changed files
with
68 additions
and
118 deletions
Show diff stats
src/super_archives/models.py
... | ... | @@ -77,7 +77,7 @@ class MailingList(models.Model): |
77 | 77 | last_imported_index = models.IntegerField(default=0) |
78 | 78 | |
79 | 79 | def get_absolute_url(self): |
80 | - return u'{}?list={}'.format(reverse('thread_list'), self.name) | |
80 | + return u'{}?list={}'.format(reverse('thread_list'), self.name) | |
81 | 81 | |
82 | 82 | def __unicode__(self): |
83 | 83 | return self.name | ... | ... |
src/super_archives/templates/message-list.html
... | ... | @@ -1,82 +0,0 @@ |
1 | -{% extends "base.html" %} | |
2 | -{% load i18n superarchives %} | |
3 | -{% block main-content %} | |
4 | -<div> | |
5 | - <h2>{% trans "Discussions" %}</h2> | |
6 | - <hr/> | |
7 | - | |
8 | - <div class="row"> | |
9 | - <div id="filters" class="hidden-xs hidden-sm col-md-2 col-lg-2"> | |
10 | - <h3>{% trans "Filters" %}</h3> | |
11 | - | |
12 | - <h4>{% trans "Sort by" %}</h4> | |
13 | - <ul class="unstyled-list"> | |
14 | - {% for option, dict_order in order_data.items %} | |
15 | - <li> | |
16 | - <span class="glyphicon glyphicon-chevron-right"></span> | |
17 | - <a href="{% append_to_get order=option p=1 %}"> | |
18 | - {% ifequal request.GET.order option %} | |
19 | - {% blocktrans with name=dict_order.name %}<strong>{{ name }}</strong>{% endblocktrans %}</a> | |
20 | - {% else %} | |
21 | - {% blocktrans with name=dict_order.name %}{{ name }}{% endblocktrans %}</a> | |
22 | - {% endifequal %} | |
23 | - </li> | |
24 | - {% endfor %} | |
25 | - </ul> | |
26 | - | |
27 | - <h4>{% trans "Lists" %}</h4> | |
28 | - <ul class="unstyled-list"> | |
29 | - {% for list in lists %} | |
30 | - {% with list.name|add:" "|add:selected_lists as list_name %} | |
31 | - {% if list.name in selected_lists %} | |
32 | - <li title="{% trans "Remove filter" %}" class="selected"> | |
33 | - <a href="{% pop_from_get list=list.name %}"> | |
34 | - <span class="glyphicon glyphicon-remove"></span> {{ list.name }} | |
35 | - </a> | |
36 | - </li> | |
37 | - {% else %} | |
38 | - <li> | |
39 | - <span class="glyphicon glyphicon-chevron-right"></span> | |
40 | - <a href="{% append_to_get list=list_name p=1 %}"> | |
41 | - {{ list.name }} | |
42 | - </a> | |
43 | - </li> | |
44 | - {% endif %} | |
45 | - {% endwith %} | |
46 | - {% endfor %} | |
47 | - </ul> | |
48 | - </div> | |
49 | - | |
50 | - <div class="col-xs-12 col-sm-12 col-md-10 col-lg-10"> | |
51 | - <ul class="unstyled-list"> | |
52 | - {% for thread in threads.object_list %} | |
53 | - {% include "message-preview.html" with result=thread.latest_message %} | |
54 | - {% empty %} | |
55 | - <br/><br/> | |
56 | - <span> | |
57 | - <b>{% trans "No discussion found" %}</b> | |
58 | - </span> | |
59 | - {% endfor %} | |
60 | - </ul> | |
61 | - | |
62 | - </div> | |
63 | - | |
64 | - {% if n_results %} | |
65 | - <div class="text-center"> | |
66 | - {% if threads.has_previous %} | |
67 | - <a href="{% append_to_get p=threads.previous_page_number %}">{% trans "Previous" %}</a> | |
68 | - {% endif %} | |
69 | - | |
70 | - <span> | |
71 | - {% trans "Page" %} {{ threads.number }} {% trans "of" %} {{ threads.paginator.num_pages }} | |
72 | - </span> | |
73 | - | |
74 | - {% if threads.has_next %} | |
75 | - <a href="{% append_to_get p=threads.next_page_number %}">{% trans "Next" %}</a> | |
76 | - {% endif %} | |
77 | - {% endif %} | |
78 | - | |
79 | - </div> | |
80 | -</div> | |
81 | - | |
82 | -{% endblock %} |
src/super_archives/templates/superarchives/thread-dashboard.html
0 → 100644
... | ... | @@ -0,0 +1,45 @@ |
1 | +{% extends 'base.html' %} | |
2 | +{% load i18n %} | |
3 | + | |
4 | +{% block main-content %} | |
5 | + | |
6 | + {% for listname, latest, most_relevant in lists %} | |
7 | + {% if latest or most_relevant %} | |
8 | + <h2>{{ listname|title }}</h2> | |
9 | + <hr/> | |
10 | + | |
11 | + <div class="row"> | |
12 | + <div class="col-lg-6"> | |
13 | + <h4>{% trans 'latest'|title %}</h4> | |
14 | + <ul class="message-list"> | |
15 | + {% for thread in latest %} | |
16 | + {% include "message-preview.html" with result=thread.latest_message %} | |
17 | + {% endfor %} | |
18 | + </ul> | |
19 | + <div class="text-right"> | |
20 | + <a href="{% url 'haystack_search' %}?order=latest&list={{ listname }}&type=thread"> | |
21 | + {% trans "more..." %} | |
22 | + </a> | |
23 | + </div> | |
24 | + </div> | |
25 | + | |
26 | + <div class="col-lg-6"> | |
27 | + <h4>{% trans 'most relevant'|title %}</h4> | |
28 | + <ul class="message-list"> | |
29 | + {% for thread in most_relevant %} | |
30 | + {% include "message-preview.html" with result=thread %} | |
31 | + {% endfor %} | |
32 | + </ul> | |
33 | + <div class="text-right"> | |
34 | + <a href="{% url 'haystack_search' %}?list={{ listname }}&type=thread"> | |
35 | + {% trans "more..." %} | |
36 | + </a> | |
37 | + </div> | |
38 | + </div> | |
39 | + </div> | |
40 | + | |
41 | + | |
42 | + {% endif %} | |
43 | + {% endfor %} | |
44 | + | |
45 | +{% endblock %} | ... | ... |
src/super_archives/urls.py
1 | 1 | from django.conf.urls import patterns, include, url |
2 | 2 | |
3 | -from .views import EmailView, EmailValidationView, ThreadView | |
3 | +from .views import EmailView, EmailValidationView, ThreadView, \ | |
4 | + ThreadDashboardView | |
4 | 5 | |
5 | 6 | |
6 | 7 | urlpatterns = patterns('super_archives.views', |
7 | -# url(r'thread/(?P<thread>\d+)/$', 'thread', name='thread'), | |
8 | 8 | url(r'thread/(?P<mailinglist>[-\w]+)/(?P<thread_token>[-\w]+)$', |
9 | 9 | ThreadView.as_view(), name="thread_view"), |
10 | - url(r'thread/$', 'list_messages', name='thread_list'), | |
10 | + url(r'thread/$', ThreadDashboardView.as_view(), name='thread_list'), | |
11 | 11 | url(r'manage/email/validate/?$', EmailValidationView.as_view(), |
12 | 12 | name="archive_email_validation_view"), |
13 | 13 | url(r'manage/email/(?P<key>[0-9a-z]{32})?', EmailView.as_view(), | ... | ... |
src/super_archives/views.py
... | ... | @@ -18,6 +18,8 @@ from django.utils.decorators import method_decorator |
18 | 18 | from django.contrib.auth.decorators import login_required |
19 | 19 | from django.shortcuts import render, redirect |
20 | 20 | |
21 | +from haystack.query import SearchQuerySet | |
22 | + | |
21 | 23 | from . import queries |
22 | 24 | from .utils.email import send_verification_email |
23 | 25 | from .models import MailingList, Thread, EmailAddress, EmailAddressValidation |
... | ... | @@ -108,38 +110,23 @@ class ThreadView(View): |
108 | 110 | return self.get(request, mailinglist, thread_token) |
109 | 111 | |
110 | 112 | |
111 | -def list_messages(request): | |
112 | - selected_lists = request.GET.get('list', []) | |
113 | - if selected_lists: | |
114 | - selected_lists = selected_lists.split() | |
115 | - | |
116 | - order_by = request.GET.get('order') | |
117 | - if order_by == 'hottest': | |
118 | - threads = queries.get_hottest_threads() | |
119 | - else: | |
120 | - threads = queries.get_latest_threads() | |
121 | - | |
122 | - mail_list = selected_lists | |
123 | - if mail_list: | |
124 | - threads = threads.filter(mailinglist__name__in=mail_list) | |
125 | - | |
126 | - paginator = Paginator(threads, 16) | |
127 | - try: | |
128 | - page = int(request.GET.get('p', '1')) | |
129 | - except ValueError: | |
130 | - page = 1 | |
131 | - threads = paginator.page(page) | |
132 | - | |
133 | - lists = MailingList.objects.all() | |
134 | - | |
135 | - template_data = { | |
136 | - 'lists': lists, | |
137 | - 'n_results': paginator.count, | |
138 | - 'threads': threads, | |
139 | - 'selected_lists': ' '.join(selected_lists) if selected_lists else '', | |
140 | - 'order_data': settings.ORDERING_DATA, | |
141 | - } | |
142 | - return render(request, 'message-list.html', template_data) | |
113 | +class ThreadDashboardView(View): | |
114 | + http_method_names = ['get'] | |
115 | + | |
116 | + def get(self, request): | |
117 | + MAX = 6 | |
118 | + context = {} | |
119 | + | |
120 | + context['lists'] = [] | |
121 | + lists = MailingList.objects.filter() | |
122 | + for list_ in MailingList.objects.order_by('name'): | |
123 | + context['lists'].append(( | |
124 | + list_.name, | |
125 | + list_.thread_set.filter(spam=False)[:MAX], | |
126 | + SearchQuerySet().filter(type='thread', tag=list_.name)[:MAX], | |
127 | + )) | |
128 | + | |
129 | + return render(request, 'superarchives/thread-dashboard.html', context) | |
143 | 130 | |
144 | 131 | |
145 | 132 | class EmailView(View): | ... | ... |