source: publico/colab/trunk/colab/super_archives/views.py @ 6126

Última Alteração nesse arquivo desde 6126 foi 6126, incluída por seocam, 8 anos atrás

Merge com a ultima versao do bitcket: https://bitbucket.org/seocam/atu-colab/src/4ee3ca57614e

File size: 2.2 KB
Linha 
1# -*- coding: utf-8 -*-
2
3from django.template import RequestContext
4from django.core.paginator import Paginator
5from django.shortcuts import render_to_response, get_list_or_404
6
7from colab.super_archives import queries
8from colab.super_archives.models import MailingList, Thread
9
10
11def thread(request, mailinglist, thread_token):
12
13    first_message = queries.get_first_message_in_thread(mailinglist, thread_token)
14    order_by = request.GET.get('order')
15    if order_by == 'voted':
16        msgs_query = queries.get_messages_by_voted()
17    else:
18        msgs_query = queries.get_messages_by_date()
19   
20    msgs_query = msgs_query.filter(thread__subject_token=thread_token)
21    msgs_query = msgs_query.filter(mailinglist__name=mailinglist)
22    emails = msgs_query.exclude(id=first_message.id)
23   
24    total_votes = first_message.votes_count()
25    for email in emails:
26        total_votes += email.votes_count()
27
28    # Update relevance score
29    query = Thread.objects.filter(mailinglist__name=mailinglist)
30    thread = query.get(subject_token=thread_token)   
31    thread.update_score()
32 
33    template_data = {
34        'first_msg': first_message,
35        'emails': [first_message] + list(emails),
36        'pagehits': queries.get_page_hits(request.path_info),
37        'total_votes': total_votes,
38    }
39   
40    return render_to_response('message-thread.html', template_data,
41                              RequestContext(request))
42
43
44def list_messages(request):
45   
46    selected_list = request.GET.get('list')
47
48    order_by = request.GET.get('order')
49    if order_by == 'hottest':
50        threads = queries.get_hottest_threads()
51    else:
52        threads = queries.get_latest_threads()
53   
54    mail_list = request.GET.get('list')
55    if mail_list:
56        threads = threads.filter(mailinglist__name=mail_list)
57   
58    paginator = Paginator(threads, 16)
59    page = int(request.GET.get('p', '1'))
60    threads = paginator.page(page)
61   
62    lists = MailingList.objects.all()
63   
64    template_data = {
65        'lists': lists,
66        'n_results': paginator.count,
67        'threads': threads,
68        'selected_list': selected_list,
69        'order_by': order_by,
70    }
71    return render_to_response('message-list.html', template_data,
72                              RequestContext(request))
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.