one more function moved to manager, some docs

This commit is contained in:
volpino 2012-05-01 17:08:49 +02:00
parent a6c7a58e61
commit 48de5022ba
2 changed files with 22 additions and 4 deletions

View File

@ -23,6 +23,9 @@ class PackageManager(models.Manager):
return self.n_versions() - self.n_packaged() - self.n_overlay() return self.n_versions() - self.n_packaged() - self.n_overlay()
def categories(self): def categories(self):
"""
Returns all the available categories
"""
return self.values('category').annotate( return self.values('category').annotate(
n_packaged=models.Sum('n_packaged'), n_packaged=models.Sum('n_packaged'),
n_overlay=models.Sum('n_overlay'), n_overlay=models.Sum('n_overlay'),
@ -30,6 +33,9 @@ class PackageManager(models.Manager):
) )
def herds(self): def herds(self):
"""
Returns all the available herds
"""
# FIXME: optimize the query, it uses 'LEFT OUTER JOIN' instead of # FIXME: optimize the query, it uses 'LEFT OUTER JOIN' instead of
# 'INNER JOIN' # 'INNER JOIN'
res = self.filter(herds__isnull=False) res = self.filter(herds__isnull=False)
@ -41,6 +47,9 @@ class PackageManager(models.Manager):
return res return res
def maintainers(self): def maintainers(self):
"""
Returns all the available maintainers
"""
res = self.filter(maintainers__isnull=False).values( res = self.filter(maintainers__isnull=False).values(
'maintainers__id', 'maintainers__name', 'maintainers__email' 'maintainers__id', 'maintainers__name', 'maintainers__email'
) )
@ -52,5 +61,17 @@ class PackageManager(models.Manager):
return res return res
def overlays(self): def overlays(self):
"""
Returns the all available overlays
"""
res = self.values('version__overlay').exclude(version__overlay='') res = self.values('version__overlay').exclude(version__overlay='')
return res.distinct() 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()

View File

@ -96,10 +96,7 @@ def overlays(request):
@render_to('euscan/overlay.html') @render_to('euscan/overlay.html')
def overlay(request, overlay): def overlay(request, overlay):
packages = Package.objects.values('id', 'name', 'category', packages = Package.objects.for_overlay(overlay)
'n_versions', 'n_packaged',
'n_overlay')
packages = packages.filter(version__overlay=overlay).distinct()
if not packages: if not packages:
raise Http404 raise Http404
return {'overlay': overlay, 'packages': packages} return {'overlay': overlay, 'packages': packages}