2012-03-29 09:37:07 -07:00
from datetime import datetime
2012-04-24 23:32:57 -07:00
from operator import attrgetter
2012-03-29 09:37:07 -07:00
2011-08-19 10:38:17 -07:00
from django . conf import settings
2010-02-04 18:44:46 -08:00
from django . contrib . auth . models import User
2012-03-29 09:37:07 -07:00
from django . db . models import Count , Q
2011-02-27 09:52:27 -08:00
from django . http import Http404
2012-07-24 07:35:55 -07:00
from django . shortcuts import render
2012-01-03 13:00:49 -08:00
from django . views . decorators . cache import cache_control
2009-10-30 11:56:21 -07:00
2012-03-21 13:52:40 -07:00
from devel . models import MasterKey , PGPSignature
2011-11-30 11:55:36 -08:00
from main . models import Arch , Repo , Donor
from mirrors . models import MirrorUrl
from news . models import News
2011-12-11 17:52:27 -08:00
from . utils import get_recent_updates
2009-10-30 13:32:25 -07:00
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2009-10-30 11:56:21 -07:00
def index ( request ) :
2012-07-30 22:09:28 -07:00
if request . user . is_authenticated ( ) :
pkgs = get_recent_updates ( testing = True , staging = True )
else :
pkgs = get_recent_updates ( )
2009-10-30 13:32:25 -07:00
context = {
2011-07-22 07:25:57 -07:00
' news_updates ' : News . objects . order_by ( ' -postdate ' , ' -id ' ) [ : 15 ] ,
2010-02-04 18:44:46 -08:00
' pkg_updates ' : pkgs ,
2009-10-30 13:32:25 -07:00
}
2012-07-24 07:35:55 -07:00
return render ( request , ' public/index.html ' , context )
2009-10-30 14:08:37 -07:00
2011-02-27 09:52:27 -08:00
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! " ,
} ,
}
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2011-10-11 17:29:15 -07:00
def userlist ( request , user_type = ' devs ' ) :
2011-11-21 08:08:23 -08:00
users = User . objects . order_by (
' first_name ' , ' last_name ' ) . select_related ( ' userprofile ' )
2011-10-11 17:29:15 -07:00
if user_type == ' devs ' :
2010-03-06 07:20:35 -08:00
users = users . filter ( is_active = True , groups__name = " Developers " )
2011-10-11 17:29:15 -07:00
elif user_type == ' tus ' :
2010-03-06 07:20:35 -08:00
users = users . filter ( is_active = True , groups__name = " Trusted Users " )
2011-10-11 17:29:15 -07:00
elif user_type == ' fellows ' :
2011-11-21 08:08:23 -08:00
users = users . filter ( is_active = False ,
groups__name__in = [ " Developers " , " Trusted Users " ] )
2011-02-27 09:52:27 -08:00
else :
raise Http404
2009-10-30 11:56:21 -07:00
2012-03-09 09:26:00 -08:00
users = users . distinct ( )
2011-10-11 17:29:15 -07:00
context = USER_LISTS [ user_type ] . copy ( )
2011-02-27 09:52:27 -08:00
context [ ' users ' ] = users
2012-07-24 07:35:55 -07:00
return render ( request , ' public/userlist.html ' , context )
2009-10-30 11:56:21 -07:00
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2009-10-30 11:56:21 -07:00
def donate ( request ) :
2009-10-30 14:08:37 -07:00
context = {
2010-10-01 11:05:19 -07:00
' donors ' : Donor . objects . filter ( visible = True ) . order_by ( ' name ' ) ,
2009-10-30 14:08:37 -07:00
}
2012-07-24 07:35:55 -07:00
return render ( request , ' public/donate.html ' , context )
2009-10-30 11:56:21 -07:00
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2009-10-30 11:56:21 -07:00
def download ( request ) :
2012-04-24 23:32:57 -07:00
mirror_urls = MirrorUrl . objects . select_related ( ' mirror ' ) . filter (
protocol__default = True ,
mirror__public = True , mirror__active = True , mirror__isos = True )
sort_by = attrgetter ( ' real_country.name ' , ' mirror.name ' )
mirror_urls = sorted ( mirror_urls , key = sort_by )
2011-08-19 10:38:17 -07:00
context = {
' releng_iso_url ' : settings . ISO_LIST_URL ,
2011-12-04 08:51:36 -08:00
' releng_pxeboot_url ' : settings . PXEBOOT_URL ,
2012-04-24 23:32:57 -07:00
' mirror_urls ' : mirror_urls ,
2011-08-19 10:38:17 -07:00
}
2012-07-24 07:35:55 -07:00
return render ( request , ' public/download.html ' , context )
2009-10-30 11:56:21 -07:00
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2010-02-02 20:36:41 -08:00
def feeds ( request ) :
context = {
' arches ' : Arch . objects . all ( ) ,
' repos ' : Repo . objects . all ( ) ,
}
2012-07-24 07:35:55 -07:00
return render ( request , ' public/feeds.html ' , context )
2010-02-02 20:36:41 -08:00
2012-01-03 13:00:49 -08:00
@cache_control ( max_age = 300 )
2011-11-30 11:55:36 -08:00
def keys ( request ) :
2012-07-31 16:37:30 -07:00
users = User . objects . filter ( is_active = True ) . select_related (
' userprofile__pgp_key ' ) . order_by ( ' first_name ' , ' last_name ' )
user_key_ids = frozenset ( user . userprofile . pgp_key [ - 16 : ] for user in users
if user . userprofile . pgp_key )
2012-03-29 09:37:07 -07:00
not_expired = Q ( expires__gt = datetime . utcnow ) | Q ( expires__isnull = True )
2012-03-21 13:52:40 -07:00
master_keys = MasterKey . objects . select_related ( ' owner ' , ' revoker ' ,
' owner__userprofile ' , ' revoker__userprofile ' ) . filter (
revoked__isnull = True )
2012-07-31 16:37:30 -07:00
master_key_ids = frozenset ( key . pgp_key [ - 16 : ] for key in master_keys )
2012-03-29 09:37:07 -07:00
2012-07-31 16:37:30 -07:00
sig_counts = PGPSignature . objects . filter ( not_expired , valid = True ,
signee__in = user_key_ids ) . values_list ( ' signer ' ) . annotate (
2012-03-21 13:52:40 -07:00
Count ( ' signer ' ) )
sig_counts = dict ( ( key_id [ - 16 : ] , ct ) for key_id , ct in sig_counts )
2012-03-29 09:37:07 -07:00
2012-03-21 13:52:40 -07:00
for key in master_keys :
key . signature_count = sig_counts . get ( key . pgp_key [ - 16 : ] , 0 )
2012-03-29 09:37:07 -07:00
# frozenset because we are going to do lots of __contains__ lookups
signatures = frozenset ( PGPSignature . objects . filter (
not_expired , valid = True ) . values_list ( ' signer ' , ' signee ' ) )
2012-07-31 16:37:30 -07:00
restrict = Q ( signer__in = user_key_ids ) & Q ( signee__in = user_key_ids )
cross_signatures = PGPSignature . objects . filter ( restrict ,
not_expired , valid = True ) . order_by ( ' created ' )
2011-11-30 11:55:36 -08:00
context = {
2012-03-21 13:52:40 -07:00
' keys ' : master_keys ,
2012-03-29 09:37:07 -07:00
' active_users ' : users ,
' signatures ' : signatures ,
2012-07-31 16:37:30 -07:00
' cross_signatures ' : cross_signatures ,
2011-11-30 11:55:36 -08:00
}
2012-07-24 07:35:55 -07:00
return render ( request , ' public/keys.html ' , context )
2011-11-30 11:55:36 -08:00
2009-10-30 11:56:21 -07:00
# vim: set ts=4 sw=4 et: