views.py
1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from collections import OrderedDict
from django.core.cache import cache
from django.shortcuts import render
from search.utils import trans
from haystack.query import SearchQuerySet
from proxy.models import WikiCollabCount, TicketCollabCount
from super_archives.models import Thread
def index(request):
"""Index page view"""
latest_threads = Thread.objects.all()[:6]
hottest_threads = Thread.highest_score.from_haystack()[:6]
count_types = cache.get('home_chart')
if count_types is None:
count_types = OrderedDict()
for type in ['thread', 'changeset', 'attachment']:
count_types[trans(type)] = SearchQuerySet().filter(
type=type,
).count()
count_types[trans('ticket')] = sum([
ticket.count for ticket in TicketCollabCount.objects.all()
])
count_types[trans('wiki')] = sum([
wiki.count for wiki in WikiCollabCount.objects.all()
])
cache.set('home_chart', count_types)
context = {
'hottest_threads': hottest_threads[:6],
'latest_threads': latest_threads,
'type_count': count_types,
'latest_results': SearchQuerySet().all().order_by(
'-modified', '-created'
)[:6],
}
return render(request, 'home.html', context)