views.py
1.9 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from collections import OrderedDict
from django.conf import settings
from django.core.cache import cache
from django.shortcuts import render
from django.http import HttpResponse, Http404
from search.utils import trans
from haystack.query import SearchQuerySet
#from proxy.trac.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()
count_types['thread'] = SearchQuerySet().filter(
type='thread',
).count()
# TODO: this section should be inside trac app and only use it here
#if settings.TRAC_ENABLED:
# for type in ['changeset', 'attachment']:
# count_types[type] = SearchQuerySet().filter(
# type=type,
# ).count()
# count_types['ticket'] = sum([
# ticket.count for ticket in TicketCollabCount.objects.all()
# ])
# count_types['wiki'] = sum([
# wiki.count for wiki in WikiCollabCount.objects.all()
# ])
cache.set('home_chart', count_types)
for key in count_types.keys():
count_types[trans(key)] = count_types.pop(key)
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)
def robots(request):
if getattr(settings, 'ROBOTS_NOINDEX', False):
return HttpResponse('User-agent: *\nDisallow: /',
content_type='text/plain')
raise Http404