one more function moved to manager, some docs
This commit is contained in:
parent
a6c7a58e61
commit
48de5022ba
@ -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()
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user