summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/admin.py10
-rw-r--r--packages/models.py3
-rw-r--r--packages/utils.py8
-rw-r--r--packages/views/display.py16
-rw-r--r--packages/views/flag.py6
5 files changed, 27 insertions, 16 deletions
diff --git a/packages/admin.py b/packages/admin.py
index 5e32dbb4..820bbb29 100644
--- a/packages/admin.py
+++ b/packages/admin.py
@@ -3,6 +3,7 @@ from django.contrib import admin
from .models import (PackageRelation, FlagRequest,
Signoff, SignoffSpecification, Update)
+
class PackageRelationAdmin(admin.ModelAdmin):
list_display = ('pkgbase', 'user', 'type', 'created')
list_filter = ('type', 'user')
@@ -19,6 +20,10 @@ class FlagRequestAdmin(admin.ModelAdmin):
ordering = ('-created',)
date_hierarchy = 'created'
+ def queryset(self, request):
+ qs = super(FlagRequestAdmin, self).queryset(request)
+ return qs.select_related('repo', 'user')
+
class SignoffAdmin(admin.ModelAdmin):
list_display = ('pkgbase', 'full_version', 'arch', 'repo',
@@ -28,6 +33,7 @@ class SignoffAdmin(admin.ModelAdmin):
ordering = ('-created',)
date_hierarchy = 'created'
+
class SignoffSpecificationAdmin(admin.ModelAdmin):
list_display = ('pkgbase', 'full_version', 'arch', 'repo',
'user', 'created', 'comments')
@@ -36,6 +42,10 @@ class SignoffSpecificationAdmin(admin.ModelAdmin):
ordering = ('-created',)
date_hierarchy = 'created'
+ def queryset(self, request):
+ qs = super(SignoffSpecificationAdmin, self).queryset(request)
+ return qs.select_related('arch', 'repo', 'user')
+
class UpdateAdmin(admin.ModelAdmin):
list_display = ('pkgname', 'repo', 'arch', 'action_flag',
diff --git a/packages/models.py b/packages/models.py
index ef86d8e9..ff677883 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -318,7 +318,8 @@ class Update(models.Model):
return u'%s-%s' % (self.new_pkgver, self.new_pkgrel)
def elsewhere(self):
- return Package.objects.filter(pkgname=self.pkgname, arch=self.arch)
+ return Package.objects.normal().filter(
+ pkgname=self.pkgname, arch=self.arch)
def __unicode__(self):
return u'%s of %s on %s' % (self.get_action_flag_display(),
diff --git a/packages/utils.py b/packages/utils.py
index a72404f4..49aeb8ce 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -6,6 +6,7 @@ import re
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection
from django.db.models import Count, Max, F
+from django.db.models.query import QuerySet
from django.contrib.auth.models import User
from main.models import Package, PackageFile, Arch, Repo
@@ -253,8 +254,11 @@ def attach_maintainers(packages):
'''Given a queryset or something resembling it of package objects, find all
the maintainers and attach them to the packages to prevent N+1 query
cascading.'''
- packages = list(packages)
- pkgbases = {p.pkgbase for p in packages if p is not None}
+ if isinstance(packages, QuerySet):
+ pkgbases = packages.values('pkgbase')
+ else:
+ packages = list(packages)
+ pkgbases = {p.pkgbase for p in packages if p is not None}
rels = PackageRelation.objects.filter(type=PackageRelation.MAINTAINER,
pkgbase__in=pkgbases).values_list(
'pkgbase', 'user_id').order_by().distinct()
diff --git a/packages/views/display.py b/packages/views/display.py
index 445c1abe..497c8d48 100644
--- a/packages/views/display.py
+++ b/packages/views/display.py
@@ -1,6 +1,5 @@
import datetime
import json
-from string import Template
from urllib import urlencode
from django.http import HttpResponse, Http404
@@ -168,7 +167,7 @@ def group_details(request, arch, name):
def files(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
# files are inserted in sorted order, so preserve that
fileslist = PackageFile.objects.filter(pkg=pkg).order_by('id')
@@ -185,14 +184,14 @@ def files(request, name, repo, arch):
def details_json(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
to_json = json.dumps(pkg, ensure_ascii=False, cls=PackageJSONEncoder)
return HttpResponse(to_json, content_type='application/json')
def files_json(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
# files are inserted in sorted order, so preserve that
fileslist = PackageFile.objects.filter(pkg=pkg).order_by('id')
@@ -213,7 +212,7 @@ def files_json(request, name, repo, arch):
def download(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
url = get_mirror_url_for_download()
if not url:
@@ -223,12 +222,9 @@ def download(request, name, repo, arch):
# grab the first non-any arch to fake the download path
arch = Arch.objects.exclude(agnostic=True)[0].name
values = {
- 'host': url.url,
- 'arch': arch,
- 'repo': pkg.repo.name.lower(),
- 'file': pkg.filename,
}
- url = Template('${host}${repo}/os/${arch}/${file}').substitute(values)
+ url = '{host}{repo}/os/{arch}/{filename}'.format(host=url.url,
+ repo=pkg.repo.name.lower(), arch=arch, filename=pkg.filename)
return redirect(url)
# vim: set ts=4 sw=4 et:
diff --git a/packages/views/flag.py b/packages/views/flag.py
index dadadd19..edb3f092 100644
--- a/packages/views/flag.py
+++ b/packages/views/flag.py
@@ -49,7 +49,7 @@ def flaghelp(request):
@never_cache
def flag(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
if pkg.flag_date is not None:
# already flagged. do nothing.
@@ -158,7 +158,7 @@ def flag_confirmed(request, name, repo, arch):
@permission_required('main.change_package')
def unflag(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
pkg.flag_date = None
pkg.save()
@@ -166,7 +166,7 @@ def unflag(request, name, repo, arch):
@permission_required('main.change_package')
def unflag_all(request, name, repo, arch):
- pkg = get_object_or_404(Package,
+ pkg = get_object_or_404(Package.objects.normal(),
pkgname=name, repo__name__iexact=repo, arch__name=arch)
# find all packages from (hopefully) the same PKGBUILD
pkgs = Package.objects.filter(pkgbase=pkg.pkgbase,