summaryrefslogtreecommitdiff
path: root/todolists/utils.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2013-01-25 09:54:24 -0700
committerDan McGee <dan@archlinux.org>2013-01-25 09:54:24 -0700
commit4244ff7a42566949f8ee85e922ed48f4a80407f7 (patch)
tree21caf4d67aa36d06c6a921608901ad059752e744 /todolists/utils.py
parentf9252df1138ae388168cf76cb3d654a2abbce4ec (diff)
parentdc6cc49f6f876983f76f5f8c05a2285801f27ea0 (diff)
Merge branch 'on-the-plane'release_2013-01-25
Diffstat (limited to 'todolists/utils.py')
-rw-r--r--todolists/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/todolists/utils.py b/todolists/utils.py
index e86d9054..51a75a3c 100644
--- a/todolists/utils.py
+++ b/todolists/utils.py
@@ -2,6 +2,7 @@ from django.db import connections, router
from django.db.models import Count
from .models import Todolist, TodolistPackage
+from packages.models import Package
def todo_counts():
@@ -36,4 +37,22 @@ def get_annotated_todolists(incomplete_only=False):
return lists
+
+def attach_staging(packages, list_id):
+ '''Look for any staging version of the packages provided and attach them
+ to the 'staging' attribute on each package if found.'''
+ pkgnames = TodolistPackage.objects.filter(
+ todolist_id=list_id).values('pkgname')
+ staging_pkgs = Package.objects.normal().filter(repo__staging=True,
+ pkgname__in=pkgnames)
+ # now build a lookup dict to attach to the correct package
+ lookup = {(p.pkgname, p.arch): p for p in staging_pkgs}
+
+ annotated = []
+ for package in packages:
+ in_staging = lookup.get((package.pkgname, package.arch), None)
+ package.staging = in_staging
+
+ return annotated
+
# vim: set ts=4 sw=4 et: