Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rewrote some for_ methods in PackageMixin class

  • Loading branch information...
commit 3a56aa4391b785ab7b73c71f500957cbe69b0430 1 parent b416231
@bacher09 bacher09 authored
Showing with 19 additions and 32 deletions.
  1. +19 −32 euscanwww/djeuscan/managers.py
View
51 euscanwww/djeuscan/managers.py
@@ -13,6 +13,22 @@ def n_method(self):
return n_method
+def gen_for_function(field):
+ def for_method(self, val, last_versions=False):
+ """
+ Returns packages that belong to the given parametrs
+ """
+ res = self.filter(**{field : val})
+
+ if last_versions:
+ select_related_last_versions(res)
+
+ return res
+
+ for_method.func_name = 'for_' + field
+ return for_method
+
+
N_LIST = ['n_packaged','n_overlay','n_versions']
ANNOTATE_DICT = { name: models.Sum(name) for name in N_LIST }
@@ -80,38 +96,9 @@ def for_overlay(self, overlay):
)
return packages.filter(version__overlay=overlay).distinct()
- def for_maintainer(self, maintainer, last_versions=False):
- """
- Returns packages that belong to the given maintainer
- """
- res = self.filter(maintainers__id=maintainer.id)
-
- if last_versions:
- select_related_last_versions(res)
-
- return res
-
- def for_herd(self, herd, last_versions=False):
- """
- Returns packages that belong to the given herd
- """
- res = self.filter(herds__id=herd.id)
-
- if last_versions:
- select_related_last_versions(res)
-
- return res
-
- def for_category(self, category, last_versions=False):
- """
- Returns packages that belong to the given category
- """
- res = self.filter(category=category)
-
- if last_versions:
- select_related_last_versions(res)
-
- return res
+ for_maintainer = gen_for_function('maintainers')
+ for_herd = gen_for_function('herds')
+ for_category = gen_for_function('category')
class PackageQuerySet(models.query.QuerySet, PackageMixin):
Please sign in to comment.
Something went wrong with that request. Please try again.