From 7adff92c9cd028d934bbf965149edaa516a66b21 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 5 Nov 2008 12:44:15 +0000 Subject: [PATCH] #2465 clean up hasgallery rule, extend haslds rule svn: r11253 --- src/FilterEditor/_EditRule.py | 2 +- src/Filters/Rules/Family/_HasLDS.py | 4 ++-- src/Filters/Rules/Person/_HasLDS.py | 4 ++-- src/Filters/Rules/_HasGalleryBase.py | 4 ++-- src/Filters/Rules/_HasLDSBase.py | 24 +++++++++++++++++++++--- src/Filters/Rules/_HasNoteBase.py | 2 +- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/FilterEditor/_EditRule.py b/src/FilterEditor/_EditRule.py index 61a4e9b7b..42e81ae4c 100644 --- a/src/FilterEditor/_EditRule.py +++ b/src/FilterEditor/_EditRule.py @@ -477,7 +477,7 @@ class EditRule(ManagedWindow.ManagedWindow): t = MyInteger(0, 999) elif v == _('Reference count must be:'): t = MyLesserEqualGreater() - elif v == _('Number must be'): + elif v == _('Number must be:'): t = MyLesserEqualGreater(1) elif v == _('Number of generations:'): t = MyInteger(1, 32) diff --git a/src/Filters/Rules/Family/_HasLDS.py b/src/Filters/Rules/Family/_HasLDS.py index d80da7efd..c511810cb 100755 --- a/src/Filters/Rules/Family/_HasLDS.py +++ b/src/Filters/Rules/Family/_HasLDS.py @@ -43,5 +43,5 @@ from Filters.Rules._HasLDSBase import HasLDSBase class HasLDS(HasLDSBase): """Rule that checks for family with a LDS event""" - name = _('Families with LDS event') - description = _("Matches families with LDS event") + name = _('Families with LDS events') + description = _("Matches families with a certain number of LDS events") diff --git a/src/Filters/Rules/Person/_HasLDS.py b/src/Filters/Rules/Person/_HasLDS.py index 6bcac5401..8f28192eb 100755 --- a/src/Filters/Rules/Person/_HasLDS.py +++ b/src/Filters/Rules/Person/_HasLDS.py @@ -43,5 +43,5 @@ from Filters.Rules._HasLDSBase import HasLDSBase class HasLDS(HasLDSBase): """Rule that checks for a person with a LDS event""" - name = _('People with LDS event') - description = _("Matches people with LDS event") + name = _('People with LDS events') + description = _("Matches people with a certain number of LDS events") diff --git a/src/Filters/Rules/_HasGalleryBase.py b/src/Filters/Rules/_HasGalleryBase.py index f13d2bdd5..f7acde660 100755 --- a/src/Filters/Rules/_HasGalleryBase.py +++ b/src/Filters/Rules/_HasGalleryBase.py @@ -40,8 +40,8 @@ from Filters.Rules import Rule class HasGalleryBase(Rule): """Objects who have Media Object""" - labels = [ _('Number of instances:'), _('Number must be')] - name = _('Object with Media reference') + labels = [ _('Number of instances:'), _('Number must be:')] + name = _('Object with Media references') description = _("Matches objects with certain number of items in the gallery") category = _('General filters') diff --git a/src/Filters/Rules/_HasLDSBase.py b/src/Filters/Rules/_HasLDSBase.py index c8d2e083b..4b6237ff6 100755 --- a/src/Filters/Rules/_HasLDSBase.py +++ b/src/Filters/Rules/_HasLDSBase.py @@ -43,9 +43,27 @@ from Filters.Rules import Rule class HasLDSBase(Rule): """Rule that checks for object with a LDS event""" - name = _('Object with LDS event') - description = _("Matches object with LDS event") + labels = [ _('Number of instances:'), _('Number must be:')] + name = _('Objects with LDS events') + description = _("Matches objects with LDS events") 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, obj): - return len( obj.get_lds_ord_list()) > 0 + count = len( obj.get_lds_ord_list()) + 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 diff --git a/src/Filters/Rules/_HasNoteBase.py b/src/Filters/Rules/_HasNoteBase.py index 92c5fa4fa..45cb14ed3 100755 --- a/src/Filters/Rules/_HasNoteBase.py +++ b/src/Filters/Rules/_HasNoteBase.py @@ -41,7 +41,7 @@ from Filters.Rules._Rule import Rule class HasNoteBase(Rule): """Objects having notes""" - labels = [ _('Number of instances:'), _('Number must be')] + labels = [ _('Number of instances:'), _('Number must be:')] name = _('Object with notes') description = _("Matches objects that have a certain number of notes") category = _('General filters')