Permalink
Browse files

Change in PackageMixin

  • Loading branch information...
1 parent 050c210 commit 0efba8934240822937a4a77f875413e42ba12e8d @bacher09 committed May 5, 2012
Showing with 11 additions and 12 deletions.
  1. +11 −12 euscanwww/djeuscan/managers.py
@@ -5,21 +5,20 @@
from django.db import models
from djeuscan.helpers import xint, rename_fields, select_related_last_versions
-
-class PackageMixin(object):
-
- def n_packaged(self):
- res = self.aggregate(models.Sum('n_packaged'))['n_packaged__sum']
+def gen_n_function(field_name):
+ def n_method(self):
+ res = self.aggregate(models.Sum(field_name))[field_name + '__sum']
return xint(res)
+ n_method.func_name = field_name
+ return n_method
- def n_overlay(self):
- res = self.aggregate(models.Sum('n_overlay'))['n_overlay__sum']
- return xint(res)
-
- def n_versions(self):
- res = self.aggregate(models.Sum('n_versions'))['n_versions__sum']
- return xint(res)
+class PackageMixin(object):
+
+ n_packaged = gen_n_function('n_packaged')
+ n_overlay = gen_n_function('n_overlay')
+ n_versions = gen_n_function('n_versions')
+
def n_upstream(self):
return self.n_versions() - self.n_packaged() - self.n_overlay()

0 comments on commit 0efba89

Please sign in to comment.