summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:05:35 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2011-08-03 16:05:35 -0300
commitfbd23db51b7160a308cd88e407e676994eb08b10 (patch)
treee3816cc4e3f0ee07539fb4464b2d886a43ecc318 /public
parenta8b2fc84ba96c83ec1addf89ac04608fbf572705 (diff)
parent0f6c80e9a36bc5770e95543b4374c5ace4383cf5 (diff)
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts: packages/urls.py templates/packages/details.html
Diffstat (limited to 'public')
-rw-r--r--public/utils.py38
1 files changed, 13 insertions, 25 deletions
diff --git a/public/utils.py b/public/utils.py
index 0be3ebaa..5900c674 100644
--- a/public/utils.py
+++ b/public/utils.py
@@ -1,7 +1,7 @@
from operator import attrgetter
from main.models import Arch, Package, Repo
-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):
@@ -59,20 +53,14 @@ def get_recent_updates(number=15):
for arch in Arch.objects.all():
pkgs += list(Package.objects.normal().filter(
arch=arch).order_by('-last_update')[:fetch])
- pkgs.sort(key=attrgetter('last_update'))
+ 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]