Commit e7efcb5d2c9204bad02b4fbcc04e6e903181b458
1 parent
69786057
Exists in
master
and in
4 other branches
Added get_list view using list_name and MAX
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Alexandre Barbosa <alexandrealmeidabarbosa@gmail.com>
Showing
3 changed files
with
89 additions
and
4 deletions
Show diff stats
colab_spb/views.py
1 | from django.shortcuts import render | 1 | from django.shortcuts import render |
2 | -from django.http import HttpResponse | 2 | +from django.utils.translation import ugettext as _ |
3 | +from colab.super_archives.models import MailingList, Thread | ||
4 | +from colab.accounts.utils import mailman | ||
3 | 5 | ||
4 | -def get_list(request,path=None,list_name=None): | ||
5 | - return HttpResponse('Hello Word') | 6 | +def get_list(request): |
7 | + list_name = None | ||
8 | + MAX = 0 | ||
9 | + if request.GET.get('list_name'): | ||
10 | + list_name = request.GET['list_name'] | ||
11 | + if request.GET.get('MAX'): | ||
12 | + MAX = request.GET['MAX'] | ||
13 | + | ||
14 | + context = {} | ||
15 | + | ||
16 | + all_privates = {} | ||
17 | + private_mailinglist = MailingList.objects.filter(is_private=True) | ||
18 | + for mailinglist in private_mailinglist: | ||
19 | + all_privates[mailinglist.name] = True | ||
20 | + | ||
21 | + context['lists'] = [] | ||
22 | + | ||
23 | + lists_for_user = [] | ||
24 | + if request.user.is_authenticated(): | ||
25 | + user = User.objects.get(username=request.user) | ||
26 | + lists_for_user = mailman.get_user_mailinglists(user) | ||
27 | + | ||
28 | + for list_ in MailingList.objects.filter(name=list_name): | ||
29 | + if list_.name not in all_privates or list_.name in lists_for_user: | ||
30 | + context['lists'].append(( | ||
31 | + list_.name, | ||
32 | + mailman.get_list_description(list_.name), | ||
33 | + list_.thread_set.filter(spam=False).order_by( | ||
34 | + '-latest_message__received_time' | ||
35 | + )[:MAX], | ||
36 | + [t.latest_message for t in Thread.highest_score.filter( | ||
37 | + mailinglist__name=list_.name)[:MAX]], | ||
38 | + len(mailman.list_users(list_.name)), | ||
39 | + )) | ||
40 | + | ||
41 | + return render(request,"discussion.html",context) |
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | + | ||
2 | + {% load i18n %} | ||
3 | + <h2>{% trans 'Groups'|title %}</h2> | ||
4 | + <hr/> | ||
5 | + | ||
6 | + {% for listname, description, latest, most_relevant, number_of_users in lists %} | ||
7 | + {% if latest or most_relevant %} | ||
8 | + <h3><b>{{ listname|title|lower }} {% if description %} ({{ description }}){% endif %}</b></h3> | ||
9 | + <div class="btn-group btn-group-sm"> | ||
10 | + <a href="#" class="btn btn-default" disabled="disabled">{% blocktrans %}{{ number_of_users }} members{% endblocktrans %}</a> | ||
11 | + {% if proxy.trac %} | ||
12 | + <a href="/wiki/grupos/{{ listname }}" class="btn btn-default">Wiki</a> | ||
13 | + {% endif %} | ||
14 | + </div> | ||
15 | + <hr/> | ||
16 | + | ||
17 | + <div class="row"> | ||
18 | + <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> | ||
19 | + <h4>{% trans 'latest'|title %}</h4> | ||
20 | + <ul class="message-list"> | ||
21 | + {% for thread in latest %} | ||
22 | + {% include "message-preview.html" with result=thread.latest_message %} | ||
23 | + {% endfor %} | ||
24 | + </ul> | ||
25 | + <div class="text-right"> | ||
26 | + <a href="{% url 'haystack_search' %}?order=latest&list={{ listname }}&type=thread"> | ||
27 | + {% trans "more..." %} | ||
28 | + </a> | ||
29 | + </div> | ||
30 | + </div> | ||
31 | + | ||
32 | + <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> | ||
33 | + <h4>{% trans 'most relevant'|title %}</h4> | ||
34 | + <ul class="message-list"> | ||
35 | + {% for thread in most_relevant %} | ||
36 | + {% include "message-preview.html" with result=thread %} | ||
37 | + {% endfor %} | ||
38 | + </ul> | ||
39 | + <div class="text-right"> | ||
40 | + <a href="{% url 'haystack_search' %}?list={{ listname }}&type=thread"> | ||
41 | + {% trans "more..." %} | ||
42 | + </a> | ||
43 | + </div> | ||
44 | + </div> | ||
45 | + </div> | ||
46 | + | ||
47 | + | ||
48 | + {% endif %} | ||
49 | + {% endfor %} |
urls.py
@@ -2,6 +2,6 @@ from django.conf.urls import patterns, url | @@ -2,6 +2,6 @@ from django.conf.urls import patterns, url | ||
2 | from . import views | 2 | from . import views |
3 | 3 | ||
4 | urlpatterns = patterns('', | 4 | urlpatterns = patterns('', |
5 | - url( r'^(?P<path>.*)$', views.get_list, name='get_list'), | 5 | + url( r'^get_list/$',views.get_list, name='get_list'), |
6 | ) | 6 | ) |
7 | 7 |