diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-04-21 02:22:44 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-04-21 02:22:44 -0400 |
commit | 03fa7e4f27bdb39a8f8f5ed91a87d18bf8357b47 (patch) | |
tree | c67eafcbda55706f18400b3115a2b8a5be318394 /public/utils.py | |
parent | 91c451821ce7000cbc268cec8427d208a6cedd7e (diff) | |
parent | b8ee7b1ee281b45b245fb454228b8ad847c56200 (diff) |
Merge branch 'archweb' into archweb-generic2
Conflicts:
devel/views.py
feeds.py
public/views.py
settings.py
sitestatic/archweb.js
templates/base.html
templates/devel/profile.html
templates/mirrors/status.html
templates/news/view.html
templates/packages/flaghelp.html
templates/packages/opensearch.xml
templates/public/download.html
templates/public/feeds.html
templates/public/index.html
templates/registration/login.html
templates/releng/results.html
templates/todolists/public_list.html
Diffstat (limited to 'public/utils.py')
-rw-r--r-- | public/utils.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/public/utils.py b/public/utils.py index a40c9b53..fcfd0f77 100644 --- a/public/utils.py +++ b/public/utils.py @@ -1,6 +1,7 @@ +from collections import defaultdict from operator import attrgetter -from main.models import Arch, Package +from main.models import Arch, Repo, Package from main.utils import cache_function, groupby_preserve_order, PackageStandin class RecentUpdate(object): @@ -44,13 +45,27 @@ class RecentUpdate(object): else: # 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() + by_arch = defaultdict(list) for package in self.others: - if package.arch not in arches and not arches.add(package.arch): - yield PackageStandin(package) + by_arch[package.arch].append(package) + for arch, packages in by_arch.items(): + if len(packages) == 1: + yield packages[0] + else: + yield PackageStandin(packages[0]) + + def __unicode__(self): + return "RecentUpdate '%s %s' <%d packages>" % ( + self.pkgbase, self.version, len(self.packages)) @cache_function(62) -def get_recent_updates(number=15): +def get_recent_updates(number=15, testing=True, staging=False): + repos = Repo.objects.all() + if not testing: + repos = repos.exclude(testing=True) + if not staging: + repos = repos.exclude(staging=True) + # 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. @@ -59,7 +74,7 @@ def get_recent_updates(number=15): fetch = number * 6 for arch in Arch.objects.all(): pkgs += list(Package.objects.normal().filter( - arch=arch).order_by('-last_update')[:fetch]) + arch=arch, repo__in=repos).order_by('-last_update')[:fetch]) pkgs.sort(key=attrgetter('last_update'), reverse=True) same_pkgbase_key = lambda x: (x.repo.name, x.pkgbase) |