From 48de5022ba72a8319c99c4c9fbcf5f6424e40207 Mon Sep 17 00:00:00 2001 From: volpino Date: Tue, 1 May 2012 17:08:49 +0200 Subject: [PATCH] one more function moved to manager, some docs --- euscanwww/djeuscan/managers.py | 21 +++++++++++++++++++++ euscanwww/djeuscan/views.py | 5 +---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/euscanwww/djeuscan/managers.py b/euscanwww/djeuscan/managers.py index f9f6156..0c9b3b6 100644 --- a/euscanwww/djeuscan/managers.py +++ b/euscanwww/djeuscan/managers.py @@ -23,6 +23,9 @@ class PackageManager(models.Manager): return self.n_versions() - self.n_packaged() - self.n_overlay() def categories(self): + """ + Returns all the available categories + """ return self.values('category').annotate( n_packaged=models.Sum('n_packaged'), n_overlay=models.Sum('n_overlay'), @@ -30,6 +33,9 @@ class PackageManager(models.Manager): ) def herds(self): + """ + Returns all the available herds + """ # FIXME: optimize the query, it uses 'LEFT OUTER JOIN' instead of # 'INNER JOIN' res = self.filter(herds__isnull=False) @@ -41,6 +47,9 @@ class PackageManager(models.Manager): return res def maintainers(self): + """ + Returns all the available maintainers + """ res = self.filter(maintainers__isnull=False).values( 'maintainers__id', 'maintainers__name', 'maintainers__email' ) @@ -52,5 +61,17 @@ class PackageManager(models.Manager): return res def overlays(self): + """ + Returns the all available overlays + """ res = self.values('version__overlay').exclude(version__overlay='') return res.distinct() + + def for_overlay(self, overlay): + """ + Returns packages that belong to the given overlay + """ + packages = self.values( + 'id', 'name', 'category', 'n_versions', 'n_packaged', 'n_overlay' + ) + return packages.filter(version__overlay=overlay).distinct() diff --git a/euscanwww/djeuscan/views.py b/euscanwww/djeuscan/views.py index 3ce67ec..ee618a2 100644 --- a/euscanwww/djeuscan/views.py +++ b/euscanwww/djeuscan/views.py @@ -96,10 +96,7 @@ def overlays(request): @render_to('euscan/overlay.html') def overlay(request, overlay): - packages = Package.objects.values('id', 'name', 'category', - 'n_versions', 'n_packaged', - 'n_overlay') - packages = packages.filter(version__overlay=overlay).distinct() + packages = Package.objects.for_overlay(overlay) if not packages: raise Http404 return {'overlay': overlay, 'packages': packages}