views.py 3.36 KB
Newer Older
1
from django.conf import settings
2
from django.contrib.auth.models import User
Dan McGee's avatar
Dan McGee committed
3
from django.http import Http404
4
from django.views.decorators.cache import cache_control
5
from django.views.generic import list_detail
6
from django.views.generic.simple import direct_to_template
7

Dan McGee's avatar
Dan McGee committed
8
9
10
11
from devel.models import MasterKey
from main.models import Arch, Repo, Donor
from mirrors.models import MirrorUrl
from news.models import News
Dan McGee's avatar
Dan McGee committed
12
from .utils import get_recent_updates
Ismael Carnales's avatar
Ismael Carnales committed
13

14
@cache_control(max_age=300)
15
def index(request):
Dan McGee's avatar
Dan McGee committed
16
    pkgs = get_recent_updates()
Ismael Carnales's avatar
Ismael Carnales committed
17
    context = {
Olivier Keun's avatar
Olivier Keun committed
18
        'news_updates': News.objects.order_by('-postdate', '-id')[:15],
19
        'pkg_updates': pkgs,
Ismael Carnales's avatar
Ismael Carnales committed
20
    }
21
    return direct_to_template(request, 'public/index.html', context)
22

Dan McGee's avatar
Dan McGee committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
USER_LISTS = {
    'devs': {
        'user_type': 'Developers',
        'description': "This is a list of the current Arch Linux Developers. They maintain the [core] and [extra] package repositories in addition to doing any other developer duties.",
    },
    'tus': {
        'user_type': 'Trusted Users',
        'description': "Here are all your friendly Arch Linux Trusted Users who are in charge of the [community] repository.",
    },
    'fellows': {
        'user_type': 'Fellows',
        'description': "Below you can find a list of ex-developers (aka project fellows). These folks helped make Arch what it is today. Thanks!",
    },
}

38
@cache_control(max_age=300)
39
def userlist(request, user_type='devs'):
40
41
    users = User.objects.order_by(
            'first_name', 'last_name').select_related('userprofile')
42
    if user_type == 'devs':
43
        users = users.filter(is_active=True, groups__name="Developers")
44
    elif user_type == 'tus':
45
        users = users.filter(is_active=True, groups__name="Trusted Users")
46
    elif user_type == 'fellows':
47
48
        users = users.filter(is_active=False,
                groups__name__in=["Developers", "Trusted Users"])
Dan McGee's avatar
Dan McGee committed
49
50
    else:
        raise Http404
51

52
    users = users.distinct()
53
    context = USER_LISTS[user_type].copy()
Dan McGee's avatar
Dan McGee committed
54
    context['users'] = users
55
    return direct_to_template(request, 'public/userlist.html', context)
56

57
@cache_control(max_age=300)
58
def donate(request):
59
    context = {
Dan McGee's avatar
Dan McGee committed
60
        'donors': Donor.objects.filter(visible=True).order_by('name'),
61
    }
62
    return direct_to_template(request, 'public/donate.html', context)
63

64
@cache_control(max_age=300)
65
def download(request):
Dan McGee's avatar
Dan McGee committed
66
    qset = MirrorUrl.objects.select_related('mirror', 'protocol').filter(
67
            protocol__is_download=True,
68
69
            mirror__public=True, mirror__active=True, mirror__isos=True
    )
70
71
    context = {
        'releng_iso_url': settings.ISO_LIST_URL,
72
        'releng_pxeboot_url': settings.PXEBOOT_URL,
73
    }
74
    return list_detail.object_list(request, 
75
            qset.order_by('mirror__country', 'mirror__name', 'protocol'),
76
            template_name="public/download.html",
77
78
            template_object_name="mirror_url",
            extra_context=context)
79

80
@cache_control(max_age=300)
81
82
83
84
85
def feeds(request):
    context = {
        'arches': Arch.objects.all(),
        'repos': Repo.objects.all(),
    }
86
    return direct_to_template(request, 'public/feeds.html', context)
87

88
@cache_control(max_age=300)
Dan McGee's avatar
Dan McGee committed
89
90
def keys(request):
    context = {
91
92
        'keys': MasterKey.objects.select_related('owner', 'revoker',
            'owner__userprofile', 'revoker__userprofile').all(),
Dan McGee's avatar
Dan McGee committed
93
94
95
    }
    return direct_to_template(request, 'public/keys.html', context)

96
# vim: set ts=4 sw=4 et: