summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-15 22:50:14 +0200
committerDan McGee <dan@archlinux.org>2011-06-15 22:50:14 +0200
commit4a9b6867a3a2786435316ab7deefa54257bb931d (patch)
tree3b0cfc08238dcf6b67dac16b8c35bc26b14b213a /packages
parenteb231660b017eab886ecd98828bf0295e36a1112 (diff)
downloadarchweb-4a9b6867a3a2786435316ab7deefa54257bb931d.tar.gz
archweb-4a9b6867a3a2786435316ab7deefa54257bb931d.tar.xz
Refactor common select_related into manager method
For a Package object query, we almost always did .select_related('arch', 'repo). Refactor this into the manager as a 'normal()' method so we can avoid sprinkling the same logic everywhere. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/utils.py2
-rw-r--r--packages/views.py15
2 files changed, 8 insertions, 9 deletions
diff --git a/packages/utils.py b/packages/utils.py
index 29a3087..af4675b 100644
--- a/packages/utils.py
+++ b/packages/utils.py
@@ -108,7 +108,7 @@ SELECT p.id, q.id
# column A will always have a value, column B might be NULL
to_fetch.append(row[0])
# fetch all of the necessary packages
- pkgs = Package.objects.select_related('arch', 'repo').in_bulk(to_fetch)
+ pkgs = Package.objects.normal().in_bulk(to_fetch)
# now build a list of tuples containing differences
differences = []
for row in results:
diff --git a/packages/views.py b/packages/views.py
index 44a1db9..5f559d6 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -117,9 +117,8 @@ def details(request, name='', repo='', arch=''):
arches = [ arch ]
arches.extend(Arch.objects.filter(agnostic=True))
repo = get_object_or_404(Repo, name__iexact=repo)
- pkgs = Package.objects.filter(pkgbase=name,
- repo__testing=repo.testing, arch__in=arches)
- pkgs = pkgs.select_related('arch', 'repo').order_by('pkgname')
+ pkgs = Package.objects.normal().filter(pkgbase=name,
+ repo__testing=repo.testing, arch__in=arches).order_by('pkgname')
if len(pkgs) == 0:
raise Http404
context = {
@@ -156,8 +155,8 @@ def group_details(request, arch, name):
arch = get_object_or_404(Arch, name=arch)
arches = [ arch ]
arches.extend(Arch.objects.filter(agnostic=True))
- pkgs = Package.objects.filter(groups__name=name, arch__in=arches)
- pkgs = pkgs.select_related('arch', 'repo').order_by('pkgname')
+ pkgs = Package.objects.normal().filter(
+ groups__name=name, arch__in=arches).order_by('pkgname')
if len(pkgs) == 0:
raise Http404
context = {
@@ -217,7 +216,7 @@ class PackageSearchForm(forms.Form):
def search(request, page=None):
limit = 50
- packages = Package.objects.select_related('arch', 'repo')
+ packages = Package.objects.normal()
if request.GET:
form = PackageSearchForm(data=request.GET)
@@ -405,7 +404,7 @@ def flag(request, name, repo, arch):
# already flagged. do nothing.
return direct_to_template(request, 'packages/flagged.html', {'pkg': pkg})
# find all packages from (hopefully) the same PKGBUILD
- pkgs = Package.objects.select_related('arch', 'repo').filter(
+ pkgs = Package.objects.normal().filter(
pkgbase=pkg.pkgbase, flag_date__isnull=True,
repo__testing=pkg.repo.testing).order_by(
'pkgname', 'repo__name', 'arch__name')
@@ -460,7 +459,7 @@ def flag(request, name, repo, arch):
def flag_confirmed(request, name, repo, arch):
pkg = get_object_or_404(Package,
pkgname=name, repo__name__iexact=repo, arch__name=arch)
- pkgs = Package.objects.select_related('arch', 'repo').filter(
+ pkgs = Package.objects.normal().filter(
pkgbase=pkg.pkgbase, flag_date=pkg.flag_date,
repo__testing=pkg.repo.testing).order_by(
'pkgname', 'repo__name', 'arch__name')