From 81821d2b4791f18635b13394aa57fa0795acddaf Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 16 Apr 2013 23:24:33 -0500 Subject: Sort required by entries by dependency type We were doing this for depends entries already, and we can do the same for required by entries via some absolutely awesome SQL query magic and injecting a few more things to our already crazy query. Signed-off-by: Dan McGee --- main/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'main') diff --git a/main/models.py b/main/models.py index 24aeed8..2f4d352 100644 --- a/main/models.py +++ b/main/models.py @@ -193,14 +193,22 @@ class Package(models.Model): category as this package if that check makes sense. """ from packages.models import Depend + sorttype = '''(CASE deptype + WHEN 'D' THEN 0 + WHEN 'O' THEN 1 + WHEN 'M' THEN 2 + WHEN 'C' THEN 3 + ELSE 1000 END)''' name_clause = '''packages_depend.name IN ( SELECT %s UNION ALL SELECT z.name FROM packages_provision z WHERE z.pkg_id = %s )''' requiredby = Depend.objects.select_related('pkg', 'pkg__arch', 'pkg__repo').extra( - where=[name_clause], params=[self.pkgname, self.id]).order_by( - 'pkg__pkgname', 'pkg__arch__name', 'pkg__repo__name') + select={'sorttype': sorttype}, + where=[name_clause], params=[self.pkgname, self.id]).order_by( + 'sorttype', 'pkg__pkgname', + 'pkg__arch__name', 'pkg__repo__name') if not self.arch.agnostic: # make sure we match architectures if possible requiredby = requiredby.filter( -- cgit v1.2.3-24-g4f1b