source: publico/colab/trunk/colab/super_archives/queries.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: 1.1 KB
Linha 
1
2from colab.super_archives.models import Thread, Vote, Message, PageHit
3
4
5def get_messages_by_date():
6    return Message.objects.order_by('received_time')
7
8
9def get_messages_by_voted():
10    """Query for the most voted messages sorting by the sum of
11    voted and after by date."""
12   
13    sql = """
14        SELECT
15            count(sav.id)
16        FROM
17            super_archives_vote AS sav
18        WHERE
19            super_archives_message.id = sav.message_id
20    """
21    messages = Message.objects.extra(
22        select={
23            'vote_count': sql,
24        }
25    )
26    return messages.order_by('-vote_count', 'received_time')
27
28
29def get_first_message_in_thread(thread_token):
30    return get_messages_by_date().filter(thread__subject_token=thread_token)[0]
31   
32
33def get_latest_threads():
34    return Thread.objects.order_by('-latest_message__received_time')
35
36
37def get_hotest_threads():
38    return Thread.objects.order_by('-score', '-latest_message__received_time')
39
40
41def get_page_hits(path_info):
42    pagehit = PageHit.objects.filter(url_path=path_info)
43   
44    if pagehit:
45        return pagehit[0].hit_count
46    return 0
47
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.