diff options
author | Dan McGee <dan@archlinux.org> | 2010-02-05 03:44:46 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-02-06 00:03:35 +0100 |
commit | b2f33457f646c9340059d4ab02b5b7280dbeff9d (patch) | |
tree | c0957a7592656144bb2f31342f455812f52036a3 | |
parent | 6fe8aec0abdfe284439e9d3adda85da8e5c3825b (diff) | |
download | archweb-b2f33457f646c9340059d4ab02b5b7280dbeff9d.tar.gz archweb-b2f33457f646c9340059d4ab02b5b7280dbeff9d.tar.xz |
Make recent updates group multiple architectures
It isn't the most elegant operation in the world, but attempt to only show
one line per package, grouping by architecture if multiple were updated in
the same go. This makes the recent packages view a bit more useful as a
heads up view. Implements FS#17304.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | main/models.py | 6 | ||||
-rw-r--r-- | public/utils.py | 19 | ||||
-rw-r--r-- | public/views.py | 8 | ||||
-rw-r--r-- | templates/public/index.html | 2 |
4 files changed, 31 insertions, 4 deletions
diff --git a/main/models.py b/main/models.py index 16fe73e..066e0ee 100644 --- a/main/models.py +++ b/main/models.py @@ -276,6 +276,12 @@ class Package(models.Model): return "http://bugs.archlinux.org/?project=%d&string=%s" % \ (project, self.pkgname) + def is_same_version(self, other): + 'is this package similar, name and version-wise, to another' + return self.pkgname == other.pkgname \ + and self.pkgver == other.pkgver \ + and self.pkgrel == other.pkgrel + class Signoff(models.Model): pkg = models.ForeignKey(Package) diff --git a/public/utils.py b/public/utils.py new file mode 100644 index 0000000..3a60403 --- /dev/null +++ b/public/utils.py @@ -0,0 +1,19 @@ +from archweb.main.models import Arch, Repo, Package + +def get_recent_updates(): + # This is a bit of magic. We are going to show 15 on the front page, but we + # want to try and eliminate cross-architecture wasted space. Pull enough + # packages that we can later do some screening and trim out the fat. + pkgs = [] + for a in Arch.objects.all(): + # grab a few extra so we can hopefully catch everything we need + pkgs += list(Package.objects.select_related('arch', 'repo').filter(arch=a).order_by('-last_update')[:50]) + pkgs.sort(reverse=True, key=lambda q: q.last_update) + for p in pkgs: + samepkgs = filter(lambda q: p.is_same_version(q), pkgs) + p.allarches = '/'.join(sorted([q.arch.name for q in samepkgs])) + for q in samepkgs: + if p != q: pkgs.remove(q) + return pkgs[:15] + +# vim: set ts=4 sw=4 et: diff --git a/public/views.py b/public/views.py index d4a1c80..560f9bb 100644 --- a/public/views.py +++ b/public/views.py @@ -1,6 +1,8 @@ -from django.contrib.auth.models import User from archweb.main.models import AltForum, Arch, Donor, MirrorUrl, News from archweb.main.models import Package, Repo, ExternalProject +from . import utils + +from django.contrib.auth.models import User from django.db.models import Q from django.shortcuts import render_to_response from django.template import RequestContext @@ -8,10 +10,10 @@ from django.views.generic import list_detail def index(request): + pkgs = utils.get_recent_updates() context = { 'news_updates': News.objects.order_by('-postdate', '-id')[:10], - 'pkg_updates': Package.objects.select_related('arch', 'repo').order_by('-last_update')[:15], - 'repos': Repo.objects.all() + 'pkg_updates': pkgs, } return render_to_response('public/index.html', context, context_instance=RequestContext(request)) diff --git a/templates/public/index.html b/templates/public/index.html index 0bc0af4..e708e4e 100644 --- a/templates/public/index.html +++ b/templates/public/index.html @@ -60,7 +60,7 @@ {% for pkg in pkg_updates %} <tr> <td><a href="{{ pkg.get_absolute_url }}" class="{{ pkg.repo.name|lower }}">{{ pkg.pkgname }} {{ pkg.pkgver }}-{{ pkg.pkgrel }}</a></td> - <td style="text-align:right">{{ pkg.arch.name }}</td> + <td style="text-align:right">{{ pkg.allarches }}</td> </tr> {% endfor %} <tr> |