some cleaning
This commit is contained in:
parent
37a623a97a
commit
e0bb80f905
@ -5,7 +5,8 @@ djeuscan.managers
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from djeuscan.helpers import xint, rename_fields, select_related_last_versions
|
from djeuscan.helpers import xint, rename_fields, select_related_last_versions
|
||||||
|
|
||||||
def gen_n_function(field_name):
|
|
||||||
|
def _gen_n_function(field_name):
|
||||||
def n_method(self):
|
def n_method(self):
|
||||||
res = self.aggregate(models.Sum(field_name))[field_name + '__sum']
|
res = self.aggregate(models.Sum(field_name))[field_name + '__sum']
|
||||||
return xint(res)
|
return xint(res)
|
||||||
@ -13,12 +14,12 @@ def gen_n_function(field_name):
|
|||||||
return n_method
|
return n_method
|
||||||
|
|
||||||
|
|
||||||
def gen_for_function(field):
|
def _gen_for_function(field):
|
||||||
def for_method(self, val, last_versions=False):
|
def for_method(self, val, last_versions=False):
|
||||||
"""
|
"""
|
||||||
Returns packages that belong to the given parametrs
|
Returns packages that belong to the given parametrs
|
||||||
"""
|
"""
|
||||||
res = self.filter(**{field : val})
|
res = self.filter(**{field: val})
|
||||||
|
|
||||||
if last_versions:
|
if last_versions:
|
||||||
select_related_last_versions(res)
|
select_related_last_versions(res)
|
||||||
@ -29,14 +30,19 @@ def gen_for_function(field):
|
|||||||
return for_method
|
return for_method
|
||||||
|
|
||||||
|
|
||||||
N_LIST = ['n_packaged','n_overlay','n_versions']
|
N_LIST = ['n_packaged', 'n_overlay', 'n_versions']
|
||||||
|
|
||||||
|
ANNOTATE_DICT = {name: models.Sum(name) for name in N_LIST}
|
||||||
|
|
||||||
ANNOTATE_DICT = { name: models.Sum(name) for name in N_LIST }
|
|
||||||
|
|
||||||
class PackageMixin(object):
|
class PackageMixin(object):
|
||||||
|
|
||||||
|
for_maintainer = _gen_for_function('maintainers')
|
||||||
|
for_herd = _gen_for_function('herds')
|
||||||
|
for_category = _gen_for_function('category')
|
||||||
|
|
||||||
for name in N_LIST:
|
for name in N_LIST:
|
||||||
locals()[name] = gen_n_function(name)
|
locals()[name] = _gen_n_function(name)
|
||||||
|
|
||||||
def n_upstream(self):
|
def n_upstream(self):
|
||||||
return self.n_versions() - self.n_packaged() - self.n_overlay()
|
return self.n_versions() - self.n_packaged() - self.n_overlay()
|
||||||
@ -96,10 +102,6 @@ class PackageMixin(object):
|
|||||||
)
|
)
|
||||||
return packages.filter(version__overlay=overlay).distinct()
|
return packages.filter(version__overlay=overlay).distinct()
|
||||||
|
|
||||||
for_maintainer = gen_for_function('maintainers')
|
|
||||||
for_herd = gen_for_function('herds')
|
|
||||||
for_category = gen_for_function('category')
|
|
||||||
|
|
||||||
|
|
||||||
class PackageQuerySet(models.query.QuerySet, PackageMixin):
|
class PackageQuerySet(models.query.QuerySet, PackageMixin):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user