from django.conf import settings from django.contrib.auth.models import User from django.db.models import Count from django.http import Http404 from django.shortcuts import redirect from django.views.decorators.cache import cache_control from django.views.generic import list_detail from django.views.generic.simple import direct_to_template from devel.models import MasterKey, PGPSignature from main.models import Arch, Repo, Donor from mirrors.models import MirrorUrl from news.models import News from .utils import get_recent_updates @cache_control(max_age=300) def index(request): pkgs = get_recent_updates() context = { 'news_updates': News.objects.order_by('-postdate', '-id')[:15], 'pkg_updates': pkgs, } return direct_to_template(request, 'public/index.html', context) USER_LISTS = { 'hackers': { 'user_type': 'Hackers', 'description': "This is a list of the current Parabola Hackers. They maintain the [libre] package repository and keep the [core], [extra] and [community] repositories clean of unfree software, in addition to doing any other developer duties.", }, 'fellows': { 'user_type': 'Fellows', 'description': "Below you can find a list of ex-hackers (aka project fellows). These folks helped make Parabola what it is today. Thanks!", }, } @cache_control(max_age=300) def userlist(request, user_type='hackers'): users = User.objects.order_by( 'username').select_related('userprofile') if user_type == 'hackers': users = users.filter(is_active=True, groups__name="Hackers") elif user_type == 'fellows': users = users.filter(is_active=False, groups__name__in=["Hackers"]) else: raise Http404 users = users.distinct() context = USER_LISTS[user_type].copy() context['users'] = users return direct_to_template(request, 'public/userlist.html', context) @cache_control(max_age=300) def donate(request): context = { 'donors': Donor.objects.filter(visible=True).order_by('name'), } return direct_to_template(request, 'public/donate.html', context) @cache_control(max_age=300) def download(request): return redirect('//wiki.parabolagnulinux.org/get', permanent=True) @cache_control(max_age=300) def feeds(request): context = { 'arches': Arch.objects.all(), 'repos': Repo.objects.all(), } return direct_to_template(request, 'public/feeds.html', context) @cache_control(max_age=300) def keys(request): master_keys = MasterKey.objects.select_related('owner', 'revoker', 'owner__userprofile', 'revoker__userprofile').filter( revoked__isnull=True) sig_counts = PGPSignature.objects.filter(valid=True, expires__isnull=True).values_list('signer').annotate( Count('signer')) sig_counts = dict((key_id[-16:], ct) for key_id, ct in sig_counts) for key in master_keys: key.signature_count = sig_counts.get(key.pgp_key[-16:], 0) context = { 'keys': master_keys, } return direct_to_template(request, 'public/keys.html', context) # vim: set ts=4 sw=4 et: