From b4e5ce5e3212c7cf2fa4fdc2dc8c9d5dfa61161c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Thu, 6 Nov 2008 08:43:47 +0000 Subject: [PATCH] 2465: More rules according to User Interface Object tabs - use the same logic as HasObject svn: r11262 --- src/Filters/Rules/Person/_HasAddress.py | 2 +- src/Filters/Rules/Person/_HasAssociation.py | 22 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Filters/Rules/Person/_HasAddress.py b/src/Filters/Rules/Person/_HasAddress.py index 422d05584..6722e5a7f 100755 --- a/src/Filters/Rules/Person/_HasAddress.py +++ b/src/Filters/Rules/Person/_HasAddress.py @@ -45,7 +45,7 @@ class HasAddress(Rule): labels = [ _('Number of instances:'), _('Number must be:')] name = _('People with address') - description = _("Matches peoplewith certain number of personal address") + description = _("Matches people with certain number of personal address") category = _('General filters') diff --git a/src/Filters/Rules/Person/_HasAssociation.py b/src/Filters/Rules/Person/_HasAssociation.py index 441528bc3..788cedb88 100755 --- a/src/Filters/Rules/Person/_HasAssociation.py +++ b/src/Filters/Rules/Person/_HasAssociation.py @@ -43,9 +43,27 @@ from Filters.Rules import Rule class HasAssociation(Rule): """Rule that checks for a person with a personal association""" - name = _('People with association') - description = _("Matches people with association") + labels = [ _('Number of instances:'), _('Number must be:')] + name = _('People with association') + description = _("Matches people with certain number of association") category = _('General filters') + def prepare(self, db): + # things we want to do just once, not for every handle + if self.list[1] == _('lesser than'): + self.count_type = 0 + elif self.list[1] == _('greater than'): + self.count_type = 2 + else: + self.count_type = 1 # "equal to" + + self.userSelectedCount = int(self.list[0]) + def apply(self, db, person): return len( person.get_person_ref_list()) > 0 + if self.count_type == 0: # "lesser than" + return count < self.userSelectedCount + elif self.count_type == 2: # "greater than" + return count > self.userSelectedCount + # "equal to" + return count == self.userSelectedCount