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

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

Entrega de numero 5 do Edital ATU-COLAB publicado em 2011

File size: 2.1 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, thread_token):
12
13    first_message = queries.get_first_message_in_thread(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    emails = msgs_query.exclude(id=first_message.id)
22   
23    total_votes = first_message.votes_count()
24    for email in emails:
25        total_votes += email.votes_count()
26
27    # Update relevance score
28    thread = Thread.objects.get(subject_token=thread_token)   
29    thread.update_score()
30 
31    template_data = {
32        'first_msg': first_message,
33        'emails': [first_message] + list(emails),
34        'pagehits': queries.get_page_hits(request.path_info),
35        'total_votes': total_votes,
36    }
37   
38    return render_to_response('message-thread.html', template_data,
39                              RequestContext(request))
40
41
42def list_messages(request):
43   
44    selected_list = request.GET.get('list')
45
46    order_by = request.GET.get('order')
47    if order_by == 'hotest':
48        threads = queries.get_hotest_threads()
49    else:
50        threads = queries.get_latest_threads()
51   
52    mail_list = request.GET.get('list')
53    if mail_list:
54        threads = threads.filter(mailinglist__name=mail_list)
55   
56    paginator = Paginator(threads, 16)
57    page = int(request.GET.get('p', '1'))
58    threads = paginator.page(page)
59   
60    lists = MailingList.objects.all()
61   
62    template_data = {
63        'lists': lists,
64        'n_results': paginator.count,
65        'threads': threads,
66        'selected_list': selected_list,
67        'order_by': order_by,
68    }
69    return render_to_response('message-list.html', template_data,
70                              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.