diff options
author | Dan McGee <dan@archlinux.org> | 2012-07-31 07:09:28 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-07-31 07:09:28 +0200 |
commit | 0cc369e985dd6376f0367e4b57e980ce14231796 (patch) | |
tree | 0ab0829d0d3a8465815178fdf5136e358f538891 | |
parent | 56a147d5b92935bf8326230bc5445ab0e0a114e9 (diff) | |
download | archweb-0cc369e985dd6376f0367e4b57e980ce14231796.tar.gz archweb-0cc369e985dd6376f0367e4b57e980ce14231796.tar.xz |
Update several bits and pieces for staging packages
This will prevent [staging] packages from cluttering normal user's view
on the website, but allow us to still import everything from this
repository for developer use.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | feeds.py | 7 | ||||
-rw-r--r-- | main/models.py | 35 | ||||
-rw-r--r-- | public/utils.py | 12 | ||||
-rw-r--r-- | public/views.py | 5 | ||||
-rw-r--r-- | sitestatic/archweb.css | 1 |
5 files changed, 43 insertions, 17 deletions
@@ -38,6 +38,7 @@ def package_etag(request, *args, **kwargs): def package_last_modified(request, *args, **kwargs): return retrieve_latest(Package) + class PackageFeed(Feed): feed_type = GuidNotPermalinkFeed @@ -51,8 +52,7 @@ class PackageFeed(Feed): def get_object(self, request, arch='', repo=''): obj = dict() - qs = Package.objects.normal().order_by( - '-last_update') + qs = Package.objects.normal().order_by('-last_update') if arch != '': # feed for a single arch, also include 'any' packages everywhere @@ -64,6 +64,8 @@ class PackageFeed(Feed): r = Repo.objects.get(name__iexact=repo) qs = qs.filter(repo=r) obj['repo'] = r + else: + qs = qs.filter(repo__staging=False) obj['qs'] = qs[:50] return obj @@ -114,6 +116,7 @@ def news_etag(request, *args, **kwargs): def news_last_modified(request, *args, **kwargs): return retrieve_latest(News, 'last_modified') + class NewsFeed(Feed): feed_type = GuidNotPermalinkFeed diff --git a/main/models.py b/main/models.py index 6c9dfe4..577f11c 100644 --- a/main/models.py +++ b/main/models.py @@ -4,6 +4,7 @@ from itertools import groupby from pgpdump import BinaryData from django.db import models +from django.db.models import Q from django.contrib.auth.models import User from django.contrib.sites.models import Site from django.utils.timezone import now @@ -24,6 +25,12 @@ class PackageManager(models.Manager): def normal(self): return self.select_related('arch', 'repo') + def restricted(self, user=None): + qs = self.normal() + if user is not None and user.is_authenticated: + return qs + return qs.filter(repo__staging=False) + class Donor(models.Model): name = models.CharField(max_length=255, unique=True) visible = models.BooleanField(default=True, @@ -193,22 +200,26 @@ class Package(models.Model): requiredby = requiredby.filter( pkg__arch__in=self.applicable_arches()) # sort out duplicate packages; this happens if something has a double - # versioned dep such as a kernel module + # versioned depend such as a kernel module requiredby = [list(vals)[0] for _, vals in groupby(requiredby, lambda x: x.pkg.id)] + if len(requiredby) == 0: + return requiredby - # find another package by this name in the opposite testing setup - # TODO: figure out staging exclusions too - if not Package.objects.filter(pkgname=self.pkgname, - arch=self.arch).exclude(id=self.id).exclude( - repo__testing=self.repo.testing).exists(): + # find another package by this name in a different testing or staging + # repo; if we can't, we can short-circuit some checks + repo_q = (Q(repo__testing=(not self.repo.testing)) | + Q(repo__staging=(not self.repo.staging))) + if not Package.objects.filter( + repo_q, pkgname=self.pkgname, arch=self.arch + ).exclude(id=self.id).exists(): # there isn't one? short circuit, all required by entries are fine return requiredby trimmed = [] # for each unique package name, try to screen our package list down to - # those packages in the same testing category (yes or no) iff there is - # a package in the same testing category. + # those packages in the same testing and staging category (yes or no) + # iff there is a package in the same testing and staging category. for _, dep_pkgs in groupby(requiredby, lambda x: x.pkg.pkgname): dep_pkgs = list(dep_pkgs) dep = dep_pkgs[0] @@ -254,7 +265,7 @@ class Package(models.Model): return Package.objects.normal().get(arch=self.arch, repo=self.repo, pkgname=self.pkgbase) except Package.DoesNotExist: - # this package might be split across repos? just find one + # this package might be split across repos? find one # that matches the correct [testing] repo flag pkglist = Package.objects.normal().filter(arch=self.arch, repo__testing=self.repo.testing, @@ -271,8 +282,10 @@ class Package(models.Model): repo.testing and repo.staging flags. For any non-split packages, the return value will be an empty list. """ - return Package.objects.normal().filter(arch__in=self.applicable_arches(), - repo__testing=self.repo.testing, repo__staging=self.repo.staging, + return Package.objects.normal().filter( + arch__in=self.applicable_arches(), + repo__testing=self.repo.testing, + repo__staging=self.repo.staging, pkgbase=self.pkgbase).exclude(id=self.id) def flag_request(self): diff --git a/public/utils.py b/public/utils.py index a40c9b5..bf74881 100644 --- a/public/utils.py +++ b/public/utils.py @@ -1,6 +1,6 @@ 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): @@ -50,7 +50,13 @@ class RecentUpdate(object): yield PackageStandin(package) @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 +65,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) diff --git a/public/views.py b/public/views.py index 3f68545..c8854b7 100644 --- a/public/views.py +++ b/public/views.py @@ -16,7 +16,10 @@ from .utils import get_recent_updates @cache_control(max_age=300) def index(request): - pkgs = get_recent_updates() + if request.user.is_authenticated(): + pkgs = get_recent_updates(testing=True, staging=True) + else: + pkgs = get_recent_updates() context = { 'news_updates': News.objects.order_by('-postdate', '-id')[:15], 'pkg_updates': pkgs, diff --git a/sitestatic/archweb.css b/sitestatic/archweb.css index be1dde1..91cacd7 100644 --- a/sitestatic/archweb.css +++ b/sitestatic/archweb.css @@ -797,6 +797,7 @@ form#flag-pkg-form input[type=text] { #pkgdetails #metadata .virtual-dep, #pkgdetails #metadata .testing-dep, +#pkgdetails #metadata .staging-dep, #pkgdetails #metadata .opt-dep, #pkgdetails #metadata .dep-desc { font-style: italic; |