summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
Diffstat (limited to 'public')
-rw-r--r--public/utils.py42
-rw-r--r--public/views.py41
2 files changed, 40 insertions, 43 deletions
diff --git a/public/utils.py b/public/utils.py
index fd29a845..30c76ac1 100644
--- a/public/utils.py
+++ b/public/utils.py
@@ -1,7 +1,7 @@
from operator import attrgetter
from main.models import Arch, Package
-from main.utils import cache_function
+from main.utils import cache_function, groupby_preserve_order, PackageStandin
class RecentUpdate(object):
def __init__(self, packages):
@@ -35,18 +35,12 @@ class RecentUpdate(object):
for package in self.packages:
yield package
else:
- # time to fake out the template, this is a tad dirty
- arches = set(pkg.arch for pkg in self.others)
- for arch in arches:
- url = '/packages/%s/%s/%s/' % (
- self.repo.name.lower(), arch.name, self.pkgbase)
- package_stub = {
- 'pkgname': self.pkgbase,
- 'arch': arch,
- 'repo': self.repo,
- 'get_absolute_url': url
- }
- yield package_stub
+ # fake out the template- this is slightly hacky but yields one
+ # 'package-like' object per arch which is what the normal loop does
+ arches = set()
+ for package in self.others:
+ if package.arch not in arches and not arches.add(package.arch):
+ yield PackageStandin(package)
@cache_function(300)
def get_recent_updates(number=15):
@@ -57,22 +51,16 @@ def get_recent_updates(number=15):
# grab a few extra so we can hopefully catch everything we need
fetch = number * 6
for arch in Arch.objects.all():
- pkgs += list(Package.objects.select_related(
- 'arch', 'repo').filter(arch=arch).order_by('-last_update')[:fetch])
- pkgs.sort(key=attrgetter('last_update'))
+ pkgs += list(Package.objects.normal().filter(
+ arch=arch).order_by('-last_update')[:fetch])
+ pkgs.sort(key=attrgetter('last_update'), reverse=True)
- updates = []
- while len(pkgs) > 0:
- pkg = pkgs.pop()
-
- in_group = lambda x: pkg.repo == x.repo and pkg.pkgbase == x.pkgbase
- samepkgs = [other for other in pkgs if in_group(other)]
- samepkgs.append(pkg)
+ same_pkgbase_key = lambda x: (x.repo.name, x.pkgbase)
+ grouped = groupby_preserve_order(pkgs, same_pkgbase_key)
- # now remove all the packages we just pulled out
- pkgs = [other for other in pkgs if other not in samepkgs]
-
- update = RecentUpdate(samepkgs)
+ updates = []
+ for group in grouped:
+ update = RecentUpdate(group)
updates.append(update)
return updates[:number]
diff --git a/public/views.py b/public/views.py
index a8e2a001..af46e343 100644
--- a/public/views.py
+++ b/public/views.py
@@ -1,20 +1,20 @@
-from main.models import Arch, Repo, Donor
-from mirrors.models import MirrorUrl
-from news.models import News
-from . import utils
-
+from django.conf import settings
from django.contrib.auth.models import User
-from django.db.models import Q
from django.http import Http404
+from django.shortcuts import redirect
from django.views.generic import list_detail
from django.views.generic.simple import direct_to_template
-from django.shortcuts import redirect
+from devel.models import MasterKey
+from main.models import Arch, Repo, Donor
+from mirrors.models import MirrorUrl
+from news.models import News
+from utils import get_recent_updates
def index(request):
- pkgs = utils.get_recent_updates()
+ pkgs = get_recent_updates()
context = {
- 'news_updates': News.objects.order_by('-postdate', '-id')[:10],
+ 'news_updates': News.objects.order_by('-postdate', '-id')[:15],
'pkg_updates': pkgs,
}
return direct_to_template(request, 'public/index.html', context)
@@ -30,16 +30,18 @@ USER_LISTS = {
},
}
-def userlist(request, type='hackers'):
- users = User.objects.order_by('username').select_related('userprofile')
- if type == 'hackers':
+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 type == 'fellows':
- users = users.filter(is_active=False, groups__name__in=["Hackers"])
+ elif user_type == 'fellows':
+ users = users.filter(is_active=False,
+ groups__name__in=["Hackers"])
else:
raise Http404
- context = USER_LISTS[type].copy()
+ context = USER_LISTS[user_type].copy()
context['users'] = users
return direct_to_template(request, 'public/userlist.html', context)
@@ -50,7 +52,7 @@ def donate(request):
return direct_to_template(request, 'public/donate.html', context)
def download(request):
- return redirect('http://wiki.parabolagnulinux.org/get', permanent=True)
+ return redirect('//wiki.parabolagnulinux.org/get', permanent=True)
def feeds(request):
context = {
@@ -59,4 +61,11 @@ def feeds(request):
}
return direct_to_template(request, 'public/feeds.html', context)
+def keys(request):
+ context = {
+ 'keys': MasterKey.objects.select_related('owner', 'revoker',
+ 'owner__userprofile', 'revoker__userprofile').all(),
+ }
+ return direct_to_template(request, 'public/keys.html', context)
+
# vim: set ts=4 sw=4 et: