/
views.py
71 lines (56 loc) · 2.08 KB
/
views.py
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
66
67
68
69
70
71
import json
import os.path
import random
from django.conf import settings
from django.http import (HttpResponseRedirect)
from django.shortcuts import render
from caching.base import cached
import commonware
from dateutil.parser import parse as date_parse
from tower import ugettext as _
from feeder.models import Entry
from wiki.models import Document, REVIEW_FLAG_TAGS
log = commonware.log.getLogger('kuma.docs')
MAX_REVIEW_DOCS = 5
def docs(request):
"""Docs landing page."""
# Accept ?next parameter for redirects from language selector.
if 'next' in request.GET:
next = request.GET['next']
# Only accept site-relative paths, not absolute URLs to anywhere.
if next.startswith('/'):
return HttpResponseRedirect(next)
# Doc of the day
dotd = cached(_get_popular_item, 'kuma_docs_dotd', 24*60*60)
# Recent updates
active_docs = []
entries = Entry.objects.filter(feed__shortname='mdc-latest')
for entry in entries:
parsed = entry.parsed
if not parsed.title.lower().startswith('en/'):
continue
# L10n: "multiple" refers to more than one author.
authorname = (parsed.author if not parsed.author == '(multiple)' else
_('(multiple)'))
active_docs.append({
'title': parsed.title[3:].replace('_', ' '),
'link': parsed.link,
'author': authorname
})
if len(active_docs) == 5:
break
review_flag_docs = dict()
for tag, description in REVIEW_FLAG_TAGS:
review_flag_docs[tag] = (Document.objects
.filter_for_review(tag_name=tag)
.order_by('-current_revision__created')
.all()[:MAX_REVIEW_DOCS])
data = {'active_docs': active_docs,
'review_flag_docs': review_flag_docs,
'dotd': dotd}
return render(request, 'docs/docs.html', data)
def _get_popular_item():
"""Get a single, random item off the popular pages list."""
# MindTouch is gone, and so is popular.json. Returning None for
# historical compatibility.
return None