From d2a9753e1c2f443676067c3969943fe1c02de533 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Thu, 11 Mar 2004 03:31:35 +0000 Subject: [PATCH] * src/GenericFilter.py: Convert to ids. * src/plugins/FilterEditor.py: Convert to ids. * src/plugins/WebPage.py: Convert to ids. svn: r3002 --- gramps2/ChangeLog | 4 + gramps2/src/GenericFilter.py | 496 ++++++++++++++++------------ gramps2/src/plugins/FilterEditor.py | 16 +- gramps2/src/plugins/WebPage.py | 69 ++-- 4 files changed, 333 insertions(+), 252 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 32c6f04b1..1ccbc4963 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -3,6 +3,10 @@ Switch from list of 2^gen strings to a dict with only used entries. Clean up generation SpinButton in the dialog. + * src/GenericFilter.py: Convert to ids. + * src/plugins/FilterEditor.py: Convert to ids. + * src/plugins/WebPage.py: Convert to ids. + 2004-03-10 Leonid Mamtchenkov * src/plugins/WebPage.py: Link main photo to the original. Use alt strings. Mini tree for many generations. diff --git a/gramps2/src/GenericFilter.py b/gramps2/src/GenericFilter.py index 2cb413a45..7af6181dd 100644 --- a/gramps2/src/GenericFilter.py +++ b/gramps2/src/GenericFilter.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2002-2003 Donald N. Allingham +# Copyright (C) 2002-2004 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -135,7 +135,7 @@ class Everyone(Rule): def description(self): return _('Matches everyone in the database') - def apply(self,db,p): + def apply(self,db,p_id): return 1 #------------------------------------------------------------------------- @@ -164,13 +164,17 @@ class RelationshipPathBetween(Rule): return _("Matches the ancestors of two people back to a common ancestor, producing " "the relationship path between two people.") - def desc_list(self, p, map, first): + def desc_list(self, p_id, map, first): if not first: - map[p.get_id()] = 1 + map[p_id] = 1 - for fam in p.get_family_id_list(): - for child in fam.get_child_id_list(): - self.desc_list(child,map,0) + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_family_id_list(): + if fam_id: + fam = self.db.find_family_from_id(fam_id) + for child_id in fam.get_child_id_list(): + if child_id: + self.desc_list(child_id,map,0) def apply_filter(self,rank,person,plist,pmap): if person == None: @@ -183,15 +187,16 @@ class RelationshipPathBetween(Rule): self.apply_filter(rank+1,family.get_father_id(),plist,pmap) self.apply_filter(rank+1,family.get_mother_id(),plist,pmap) - def apply(self,db,p): + def apply(self,db,p_id): + self.db = db if not self.init: self.init = 1 - root1 = db.get_person(self.list[0]) - root2 = db.get_person(self.list[1]) + root1 = self.list[0] + root2 = self.list[1] self.init_list(root1,root2) - return self.map.has_key(p.get_id()) + return self.map.has_key(p_id) - def init_list(self,p1,p2): + def init_list(self,p1_id,p2_id): firstMap = {} firstList = [] @@ -200,24 +205,24 @@ class RelationshipPathBetween(Rule): common = [] rank = 9999999 - self.apply_filter(0,p1,firstList,firstMap) - self.apply_filter(0,p2,secondList,secondMap) + self.apply_filter(0,p1_id,firstList,firstMap) + self.apply_filter(0,p2_id,secondList,secondMap) - for person in firstList: - if person in secondList: - new_rank = firstMap[person.get_id()] + for person_id in firstList: + if person_id in secondList: + new_rank = firstMap[person_id] if new_rank < rank: rank = new_rank - common = [ person ] + common = [ person_id ] elif new_rank == rank: - common.append(person) + common.append(person_id) - path1 = { p1.get_id() : 1} - path2 = { p2.get_id() : 1} + path1 = { p1_id : 1} + path2 = { p2_id : 1} - for person in common: + for person_id in common: new_map = {} - self.desc_list(person,new_map,1) + self.desc_list(person_id,new_map,1) self.get_intersection(path1,firstMap,new_map) self.get_intersection(path2,secondMap,new_map) @@ -226,7 +231,7 @@ class RelationshipPathBetween(Rule): for e in path2: self.map[e] = 1 for e in common: - self.map[e.get_id()] = 1 + self.map[e] = 1 def get_intersection(self,target, map1, map2): for e in map1.keys(): @@ -252,8 +257,8 @@ class HasIdOf(Rule): def category(self): return _('General filters') - def apply(self,db,p): - return p.get_id() == self.list[0] + def apply(self,db,p_id): + return p_id == self.list[0] #------------------------------------------------------------------------- # @@ -274,8 +279,8 @@ class HasCompleteRecord(Rule): def description(self): return _('Matches all people whose records are complete') - def apply(self,db,p): - return p.get_complete() == 1 + def apply(self,db,p_id): + return db.find_person_from_id(p_id).get_complete() == 1 #------------------------------------------------------------------------- @@ -297,8 +302,8 @@ class IsFemale(Rule): def description(self): return _('Matches all females') - def apply(self,db,p): - return p.get_gender() == RelLib.Person.female + def apply(self,db,p_id): + return db.find_person_from_id(p_id).get_gender() == RelLib.Person.female #------------------------------------------------------------------------- # @@ -325,8 +330,9 @@ class IsDescendantOf(Rule): def description(self): return _('Matches all descendants for the specified person') - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db try: if int(self.list[1]): first = 0 @@ -337,17 +343,20 @@ class IsDescendantOf(Rule): if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_list(root,first) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_list(root_id,first) + return self.map.has_key(p_id) - def init_list(self,p,first): + def init_list(self,p_id,first): if not first: - self.map[p.get_id()] = 1 + self.map[p_id] = 1 - for fam in p.get_family_id_list(): - for child in fam.get_child_id_list(): - self.init_list(child,0) + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_family_id_list(): + if fam_id: + fam = self.db.find_family_from_id(fam_id) + for child_id in fam.get_child_id_list(): + self.init_list(child_id,0) #------------------------------------------------------------------------- # @@ -372,8 +381,9 @@ class IsDescendantOfFilterMatch(IsDescendantOf): def description(self): return _("Matches people that are descendants of someone matched by a filter") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db try: if int(self.list[1]): first = 0 @@ -385,10 +395,10 @@ class IsDescendantOfFilterMatch(IsDescendantOf): if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person in db.get_person_id_map ().values (): - if filter.apply (db, person): - self.init_list (person, first) - return self.map.has_key(p.get_id()) + for person_id in db.get_person_keys(): + if filter.apply (db, person_id): + self.init_list (person_id, first) + return self.map.has_key(p_id) #------------------------------------------------------------------------- # @@ -416,24 +426,27 @@ class IsLessThanNthGenerationDescendantOf(Rule): return _("Matches people that are descendants of a specified person " "not more than N generations away") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_list(root,0) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_list(root_id,0) + return self.map.has_key(p_id) - def init_list(self,p,gen): + def init_list(self,p_id,gen): if gen: - self.map[p.get_id()] = 1 + self.map[p_id] = 1 if gen >= int(self.list[1]): return - for fam in p.get_family_id_list(): - for child in fam.get_child_id_list(): - self.init_list(child,gen+1) + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_family_id_list(): + fam = self.db.find_family_from_id(fam_id) + for child_id in fam.get_child_id_list(): + self.init_list(child_id,gen+1) #------------------------------------------------------------------------- # @@ -461,22 +474,25 @@ class IsMoreThanNthGenerationDescendantOf(Rule): def category(self): return _("Descendant filters") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_list(root,0) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_list(root_id,0) + return self.map.has_key(p_id) - def init_list(self,p,gen): + def init_list(self,p_id,gen): if gen >= int(self.list[1]): - self.map[p.get_id()] = 1 + self.map[p_id] = 1 - for fam in p.get_family_id_list(): - for child in fam.get_child_id_list(): - self.init_list(child,gen+1) + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_family_id_list(): + fam = self.db.find_family_from_id(fam_id) + for child_id in fam.get_child_id_list(): + self.init_list(child_id,gen+1) #------------------------------------------------------------------------- # @@ -503,21 +519,24 @@ class IsChildOfFilterMatch(Rule): def category(self): return _('Family filters') - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person in db.get_person_id_map ().values (): - if filter.apply (db, person): - self.init_list (person) - return self.map.has_key(p.get_id()) + for person_id in db.get_person_keys(): + if filter.apply (db, person_id): + self.init_list (person_id) + return self.map.has_key(p_id) - def init_list(self,p): - for fam in p.get_family_id_list(): - for child in fam.get_child_id_list(): - self.map[child.get_id()] = 1 + def init_list(self,p_id): + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_family_id_list(): + fam = self.db.find_family_from_id(fam_id) + for child_id in fam.get_child_id_list(): + self.map[child_id] = 1 #------------------------------------------------------------------------- # @@ -540,33 +559,33 @@ class IsDescendantFamilyOf(Rule): return _("Matches people that are descendants or the spouse " "of a descendant of a specified person") - def apply(self,db,p): + def apply(self,db,p_id): self.map = {} - self.orig = p + self.orig_id = p_id self.db = db - return self.search(p,1) + return self.search(p_id,1) - def search(self,p,val): - if p.get_id() == self.list[0]: - self.map[p.get_id()] = 1 + def search(self,p_id,val): + if p_id == self.list[0]: + self.map[p_id] = 1 return 1 + + p = self.db.find_person_from_id(p_id) for (f,r1,r2) in p.get_parent_family_id_list(): family = self.db.find_family_from_id(f) for person_id in [family.get_mother_id(),family.get_father_id()]: if person_id: - person = self.db.find_person_from_id(person_id) - if self.search(person,0): + if self.search(person_id,0): return 1 if val: for family_id in p.get_family_id_list(): family = self.db.find_family_from_id(family_id) - if p == family.get_father_id(): + if p_id == family.get_father_id(): spouse_id = family.get_mother_id() else: spouse_id = family.get_father_id() if spouse_id: - spouse = self.db.find_person_from_id(spouse_id) - if self.search(spouse,0): + if self.search(spouse_id,0): return 1 return 0 @@ -594,9 +613,10 @@ class IsAncestorOf(Rule): def category(self): return _("Ancestral filters") - def apply(self,db,p): + def apply(self,db,p_id): """Assume that if 'Inclusive' not defined, assume inclusive""" - self.orig = p + self.orig_id = p_id + self.db = db try: if int(self.list[1]): first = 0 @@ -607,23 +627,25 @@ class IsAncestorOf(Rule): if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_ancestor_list(root,first) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_ancestor_list(root_id,first) + return self.map.has_key(p_id) - def init_ancestor_list(self,p,first): + def init_ancestor_list(self,p_id,first): if not first: - self.map[p.get_id()] = 1 + self.map[p_id] = 1 - fam = p.get_main_parents_family_id() - if fam: - f = fam.get_father_id() - m = fam.get_mother_id() + p = self.db.find_person_from_id(p_id) + fam_id = p.get_main_parents_family_id() + if fam_id: + fam = self.db.find_family_from_id(fam_id) + f_id = fam.get_father_id() + m_id = fam.get_mother_id() - if f: - self.init_ancestor_list(f,0) - if m: - self.init_ancestor_list(m,0) + if f_id: + self.init_ancestor_list(f_id,0) + if m_id: + self.init_ancestor_list(m_id,0) #------------------------------------------------------------------------- # @@ -649,8 +671,8 @@ class IsAncestorOfFilterMatch(IsAncestorOf): def category(self): return _("Ancestral filters") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id try: if int(self.list[1]): first = 0 @@ -662,10 +684,10 @@ class IsAncestorOfFilterMatch(IsAncestorOf): if not self.init: self.init = 1 filter = MatchesFilter(self.list[0]) - for person in db.get_person_id_map ().values (): - if filter.apply (db, person): - self.init_ancestor_list (person,first) - return self.map.has_key(p.get_id()) + for person_id in db.get_person_keys(): + if filter.apply (db, person_id): + self.init_ancestor_list (person_id,first) + return self.map.has_key(p_id) #------------------------------------------------------------------------- # @@ -693,31 +715,34 @@ class IsLessThanNthGenerationAncestorOf(Rule): def category(self): return _("Ancestral filters") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_ancestor_list(root,0) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_ancestor_list(root_id,0) + return self.map.has_key(p_id) - def init_ancestor_list(self,p,gen): + def init_ancestor_list(self,p_id,gen): # if self.map.has_key(p.get_id()) == 1: # loop_error(self.orig,p) if gen: - self.map[p.get_id()] = 1 + self.map[p_id] = 1 if gen >= int(self.list[1]): return - fam = p.get_main_parents_family_id() - if fam: - f = fam.get_father_id() - m = fam.get_mother_id() + p = self.db.find_person_from_id(p_id) + fam_id = p.get_main_parents_family_id() + if fam_id: + fam = self.db.find_family_from_id(fam_id) + f_id = fam.get_father_id() + m_id = fam.get_mother_id() - if f: - self.init_ancestor_list(f,gen+1) - if m: - self.init_ancestor_list(m,gen+1) + if f_id: + self.init_ancestor_list(f_id,gen+1) + if m_id: + self.init_ancestor_list(m_id,gen+1) #------------------------------------------------------------------------- # @@ -745,29 +770,32 @@ class IsMoreThanNthGenerationAncestorOf(Rule): def category(self): return _("Ancestral filters") - def apply(self,db,p): - self.orig = p + def apply(self,db,p_id): + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 - root = db.get_person(self.list[0]) - self.init_ancestor_list(root,0) - return self.map.has_key(p.get_id()) + root_id = self.list[0] + self.init_ancestor_list(root_id,0) + return self.map.has_key(p_id) - def init_ancestor_list(self,p,gen): + def init_ancestor_list(self,p_id,gen): # if self.map.has_key(p.get_id()) == 1: # loop_error(self.orig,p) if gen >= int(self.list[1]): - self.map[p.get_id()] = 1 + self.map[p_id] = 1 - fam = p.get_main_parents_family_id() - if fam: - f = fam.get_father_id() - m = fam.get_mother_id() + p = self.db.find_person_from_id(p_id) + fam_id = p.get_main_parents_family_id() + if fam_id: + fam = self.db.find_family_from_id(fam_id) + f_id = fam.get_father_id() + m_id = fam.get_mother_id() - if f: - self.init_ancestor_list(f,gen+1) - if m: - self.init_ancestor_list(m,gen+1) + if f_id: + self.init_ancestor_list(f_id,gen+1) + if m_id: + self.init_ancestor_list(m_id,gen+1) #------------------------------------------------------------------------- # @@ -795,21 +823,24 @@ class IsParentOfFilterMatch(Rule): return _('Family filters') def apply(self,db,p): - self.orig = p + self.orig_id = p_id + self.db = db if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person in db.get_person_id_map ().values (): - if filter.apply (db, person): - self.init_list (person) - return self.map.has_key(p.get_id()) + for person_id in db.get_person_keys(): + if filter.apply (db, person_id): + self.init_list (person_id) + return self.map.has_key(p_id) - def init_list(self,p): - for fam in p.get_main_parents_family_id(): - for parent in [fam.get_father_id (), fam.get_mother_id ()]: - if parent: - self.map[parent.get_id()] = 1 + def init_list(self,p_id): + p = self.db.find_person_from_id(p_id) + for fam_id in p.get_main_parents_family_id(): + fam = self.db.find_family_from_id(fam_id) + for parent_id in [fam.get_father_id (), fam.get_mother_id ()]: + if parent_id: + self.map[parent_id] = 1 #------------------------------------------------------------------------- # @@ -841,19 +872,19 @@ class HasCommonAncestorWith(Rule): def init_ancestor_cache(self,db): # list[0] is an Id, but we need to pass a Person to for_each_ancestor. - p = db.get_person(self.list[0]) - if p: + p_id = self.list[0] + if p_id: def init(self,pid): self.ancestor_cache[pid] = 1 - for_each_ancestor([p],init,self) + for_each_ancestor([p_id],init,self) - def apply(self,db,p): + def apply(self,db,p_id): # On the first call, we build the ancestor cache for the # reference person. Then, for each person to test, # we browse his ancestors until we found one in the cache. if len(self.ancestor_cache) == 0: self.init_ancestor_cache(db) - return for_each_ancestor([p], - lambda self,p: self.ancestor_cache.has_key(p), + return for_each_ancestor([p_id], + lambda self,p_id: self.ancestor_cache.has_key(p_id), self); #------------------------------------------------------------------------- @@ -883,10 +914,10 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith): def init_ancestor_cache(self,db): filter = MatchesFilter(self.list) def init(self,pid): self.ancestor_cache[pid] = 1 - for p in db.get_person_id_map ().values (): - if (not self.ancestor_cache.has_key (p.get_id ()) - and filter.apply (db, p)): - for_each_ancestor([p],init,self) + for p_id in db.get_person_keys(): + if (not self.ancestor_cache.has_key (p_id) + and filter.apply (db, p_id)): + for_each_ancestor([p_id],init,self) #------------------------------------------------------------------------- # @@ -907,8 +938,8 @@ class IsMale(Rule): def description(self): return _('Matches all males') - def apply(self,db,p): - return p.get_gender() == RelLib.Person.male + def apply(self,db,p_id): + return self.db.find_person_from_id(p_id).get_gender() == RelLib.Person.male #------------------------------------------------------------------------- # @@ -937,8 +968,12 @@ class HasEvent(Rule): def category(self): return _('Event filters') - def apply(self,db,p): - for event in p.get_event_list(): + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) + for event_id in p.get_event_list(): + if not event_id: + continue + event = db.find_event_from_id(event_id) val = 1 if self.list[0] and event.get_name() != self.list[0]: val = 0 @@ -949,11 +984,14 @@ class HasEvent(Rule): if date_cmp(self.date,event.get_date_object()): val = 0 if self.list[2]: - pn = event.get_place_name() - if find(pn.upper(),self.list[2].upper()) == -1: - val = 0 - if val == 1: - return 1 + pl_id = event.get_place_id() + if pl_id: + pl = db.find_place_from_id(pl_id) + pn = pl.get_title() + if find(pn.upper(),self.list[2].upper()) == -1: + val = 0 + if val == 1: + return 1 return 0 #------------------------------------------------------------------------- @@ -984,9 +1022,14 @@ class HasFamilyEvent(Rule): def category(self): return _('Event filters') - def apply(self,db,p): - for f in p.get_family_id_list(): - for event in f.get_event_list(): + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) + for f_id in p.get_family_id_list(): + f = db.find_family_from_id(f_id) + for event_id in f.get_event_list(): + if not event_id: + continue + event = db.find_event_from_id(event_id) val = 1 if self.list[0] and event.get_name() != self.list[0]: val = 0 @@ -996,11 +1039,14 @@ class HasFamilyEvent(Rule): if self.date: if date_cmp(self.date,event.get_date_object()): val = 0 - pn = event.get_place_name().upper() - if self.list[2] and find(pn,self.list[2].upper()) == -1: - val = 0 - if val == 1: - return 1 + pl_id = event.get_place_id() + if pl_id: + pl = db.find_place_from_id(pl_id) + pn = pl.get_title() + if self.list[2] and find(pn,self.list[2].upper()) == -1: + val = 0 + if val == 1: + return 1 return 0 #------------------------------------------------------------------------- @@ -1024,13 +1070,15 @@ class HasRelationship(Rule): def category(self): return _('Family filters') - def apply(self,db,p): + def apply(self,db,p_id): rel_type = 0 cnt = 0 + p = db.find_person_from_id(p_id) num_rel = len(p.get_family_id_list()) # count children and look for a relationship type match - for f in p.get_family_id_list(): + for f_id in p.get_family_id_list(): + f = db.find_family_from_id(f_id) cnt = cnt + len(f.get_child_id_list()) if self.list[1] and f.get_relationship() == self.list[1]: rel_type = 1 @@ -1086,17 +1134,24 @@ class HasBirth(Rule): def category(self): return _('Event filters') - def apply(self,db,p): - event = p.get_birth() + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) + event_id = p.get_birth_id() + if not event_id: + return 0 + event = db.find_event_from_id(event_id) ed = event.get_description().upper() if len(self.list) > 2 and find(ed,self.list[2].upper())==-1: return 0 if self.date: if date_cmp(self.date,event.get_date_object()) == 0: return 0 - pn = event.get_place_name().upper() - if len(self.list) > 1 and find(pn,self.list[1].upper()) == -1: - return 0 + pl_id = event.get_place_id() + if pl_id: + pl = db.find_place_from_id(pl_id) + pn = pl.get_title() + if len(self.list) > 1 and find(pn,self.list[1].upper()) == -1: + return 0 return 1 #------------------------------------------------------------------------- @@ -1126,17 +1181,24 @@ class HasDeath(Rule): def category(self): return _('Event filters') - def apply(self,db,p): - event = p.get_death() + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) + event_id = p.get_death_id() + if not event_id: + return 0 + event = db.find_event_from_id(event_id) ed = event.get_description().upper() if self.list[2] and find(ed,self.list[2].upper())==-1: return 0 if self.date: if date_cmp(self.date,event.get_date_object()) == 0: return 0 - pn = event.get_place_name().upper() - if self.list[1] and find(pn,self.list[1].upper()) == -1: - return 0 + pl_id = event.get_place_id() + if pl_id: + pl = db.find_place_from_id(pl_id) + pn = pl.get_title() + if self.list[1] and find(pn,self.list[1].upper()) == -1: + return 0 return 1 #------------------------------------------------------------------------- @@ -1152,7 +1214,8 @@ class HasAttribute(Rule): def name(self): return 'Has the personal attribute' - def apply(self,db,p): + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) for event in p.getAttributes(): if self.list[0] and event.get_type() != self.list[0]: return 0 @@ -1174,8 +1237,10 @@ class HasFamilyAttribute(Rule): def name(self): return 'Has the family attribute' - def apply(self,db,p): - for f in p.get_family_id_list(): + def apply(self,db,p_id): + p = db.find_person_from_id(p_id) + for f_id in p.get_family_id_list(): + f = db.find_family_from_id(f_id) for event in f.getAttributes(): val = 1 if self.list[0] and event.get_type() != self.list[0]: @@ -1206,11 +1271,12 @@ class HasNameOf(Rule): def category(self): return _('General filters') - def apply(self,db,p): + def apply(self,db,p_id): self.f = self.list[0] self.l = self.list[1] self.s = self.list[2] self.t = self.list[3] + p = db.find_person_from_id(p_id) for name in [p.get_primary_name()] + p.get_alternate_names(): val = 1 if self.f and find(name.get_first_name().upper(),self.f.upper()) == -1: @@ -1239,13 +1305,13 @@ class MatchesFilter(Rule): def name(self): return 'Matches the filter named' - def apply(self,db,p): + def apply(self,db,p_id): for filter in SystemFilters.get_filters(): if filter.get_name() == self.list[0]: - return filter.check(p) + return filter.check(p_id) for filter in CustomFilters.get_filters(): if filter.get_name() == self.list[0]: - return filter.check(db,p) + return filter.check(db,p_id) return 0 #------------------------------------------------------------------------- @@ -1268,15 +1334,17 @@ class IsSpouseOfFilterMatch(Rule): def category(self): return _('Family filters') - def apply(self,db,p): + def apply(self,db,p_id): filter = MatchesFilter (self.list) - for family in p.get_family_id_list (): - for spouse in [family.get_father_id (), family.get_mother_id ()]: - if not spouse: + p = db.find_person_from_id(p_id) + for family_id in p.get_family_id_list (): + family = db.find_family_from_id(family_id) + for spouse_id in [family.get_father_id (), family.get_mother_id ()]: + if not spouse_id: continue - if spouse == p: + if spouse_id == p_id: continue - if filter.apply (db, spouse): + if filter.apply (db, spouse_id): return 1 return 0 @@ -1341,10 +1409,10 @@ class GenericFilter: def get_rules(self): return self.flist - def check_or(self,db,p): + def check_or(self,db,p_id): test = 0 for rule in self.flist: - test = test or rule.apply(db,p) + test = test or rule.apply(db,p_id) if test: break if self.invert: @@ -1352,20 +1420,20 @@ class GenericFilter: else: return test - def check_xor(self,db,p): + def check_xor(self,db,p_id): test = 0 for rule in self.flist: - temp = rule.apply(db,p) + temp = rule.apply(db,p_id) test = ((not test) and temp) or (test and (not temp)) if self.invert: return not test else: return test - def check_one(self,db,p): + def check_one(self,db,p_id): count = 0 for rule in self.flist: - if rule.apply(db,p): + if rule.apply(db,p_id): count = count + 1 if count > 1: break @@ -1374,10 +1442,10 @@ class GenericFilter: else: return count == 1 - def check_and(self,db,p): + def check_and(self,db,p_id): test = 1 for rule in self.flist: - test = test and rule.apply(db,p) + test = test and rule.apply(db,p_id) if not test: break if self.invert: @@ -1392,15 +1460,15 @@ class GenericFilter: m = self.check_and return m - def check(self,db,p): - return self.get_check_func()(db,p) + def check(self,db,p_id): + return self.get_check_func()(db,p_id) - def apply(self,db,list): + def apply(self,db,id_list): m = self.get_check_func() res = [] - for p in list: - if m(db,p): - res.append(p) + for p_id in id_list: + if m(db,p_id): + res.append(p_id) return res diff --git a/gramps2/src/plugins/FilterEditor.py b/gramps2/src/plugins/FilterEditor.py index cc0f42941..3fde5208a 100644 --- a/gramps2/src/plugins/FilterEditor.py +++ b/gramps2/src/plugins/FilterEditor.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2003 Donald N. Allingham +# Copyright (C) 2000-2004 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -293,8 +293,8 @@ class FilterEditor: store,iter = self.clist.get_selected() if iter: filt = self.clist.get_object(iter) - list = filt.apply(self.db,self.db.get_person_id_map().values()) - ShowResults(list) + id_list = filt.apply(self.db,self.db.get_person_keys()) + ShowResults(self.db,id_list) def delete_filter(self,obj): store,iter = self.clist.get_selected() @@ -404,8 +404,9 @@ class FilterEditor: self.pmap = {} self.add_places = [] - for p in self.db.get_place_ids(): - self.pmap[p.get_title()] = p + for p_id in self.db.get_place_ids(): + p = self.db.find_place_from_id(p_id) + self.pmap[p.get_title()] = p_id self.active_rule = val self.rule = gtk.glade.XML(const.filterFile,'rule_editor',"gramps") @@ -588,7 +589,7 @@ class FilterEditor: self.rule_top.destroy() class ShowResults: - def __init__(self,plist): + def __init__(self,db,id_list): self.glade = gtk.glade.XML(const.filterFile,'test',"gramps") self.top = self.glade.get_widget('test') text = self.glade.get_widget('text') @@ -599,7 +600,8 @@ class ShowResults: self.glade.signal_autoconnect({'on_close_clicked' : self.close}) n = [] - for p in plist: + for p_id in id_list: + p = db.find_person_from_id(p_id) n.append ("%s [%s]\n" % (p.get_primary_name().get_name(),p.get_id())) n.sort () diff --git a/gramps2/src/plugins/WebPage.py b/gramps2/src/plugins/WebPage.py index 287e9cc22..8d8001306 100644 --- a/gramps2/src/plugins/WebPage.py +++ b/gramps2/src/plugins/WebPage.py @@ -314,7 +314,7 @@ class IndividualPage: if self.photos and len(media_list) > 0: object_id = media_list[0].get_reference_id() - object = self.database.find_object_from_id(object_id) + object = self.db.find_object_from_id(object_id) if object.get_mime_type()[0:5] == "image": src = object.get_path() junk,ext = os.path.splitext(src) @@ -405,9 +405,9 @@ class IndividualPage: my_list = [] for object_ref in self.person.get_media_list(): - object = self.database.find_object_from_id(object_ref.get_ref()) + object = self.db.find_object_from_id(object_ref.get_reference_id()) if object.get_mime_type()[0:5] == "image": - if object.get_privacy() == 0: + if object_ref.get_privacy() == 0: my_list.append(object) # if no images were found, return @@ -426,10 +426,10 @@ class IndividualPage: index = 0 for obj_id in my_list: try: - obj = self.database.find_object_from_id(obj_id) - src = obj.get_reference().get_path() + obj = self.db.find_object_from_id(obj_id) + src = obj.get_path() junk,ext = os.path.splitext(src) - base = '%s%s' % (obj.get_reference().get_id(),ext) + base = '%s%s' % (obj.get_id(),ext) if self.image_dir: shutil.copyfile(src,"%s/%s/%s" % (self.dir,self.image_dir,base)) @@ -450,7 +450,7 @@ class IndividualPage: index = 1 continue - description = obj.get_reference().get_description() + description = obj.get_description() self.doc.start_row() self.doc.start_cell("ImageCell") @@ -754,29 +754,34 @@ class WebReport(Report.Report): retval = "AFT %s" % retval return retval - def dump_gendex(self,person_list,html_dir): + def dump_gendex(self,person_id_list,html_dir): fname = "%s/gendex.txt" % html_dir try: f = open(fname,"w") except: return - for p in person_list: + for p_id in person_id_list: + p = self.db.find_person_from_id(p_id) name = p.get_primary_name() firstName = name.get_first_name() surName = name.get_surname() suffix = name.get_suffix() - f.write("%s.%s|" % (p.get_id(),self.ext)) + f.write("%s.%s|" % (p_id,self.ext)) f.write("%s|" % surName) if suffix == "": f.write("%s /%s/|" % (firstName,surName)) else: f.write("%s /%s/, %s|" % (firstName,surName, suffix)) - for e in [p.get_birth(),p.get_death()]: + for e_id in [p.get_birth_id(),p.get_death_id()]: + if e_id: + e = self.db.find_event_from_id(e_id) + else: + continue if e: f.write("%s|" % self.make_date(e.get_date_object())) if e.get_place_id(): - f.write('%s|' % e.get_place_id().get_title()) + f.write('%s|' % self.db.find_place_from_id(e.get_place_id()).get_title()) else: f.write('|') else: @@ -784,7 +789,7 @@ class WebReport(Report.Report): f.write('\n') f.close() - def dump_index(self,person_list,styles,template,html_dir): + def dump_index(self,person_id_list,styles,template,html_dir): """Writes an index file, listing all people in the person list.""" doc = HtmlLinkDoc(self.selected_style,None,template,None) @@ -796,10 +801,11 @@ class WebReport(Report.Report): doc.write_text(_("Family Tree Index")) doc.end_paragraph() - person_list.sort(sort.by_last_name) + person_id_list.sort(self.db.sort_by_name) a = {} - for person in person_list: + for person_id in person_id_list: + person = self.db.find_person_from_id(person_id) n = person.get_primary_name().get_surname() if n: a[n[0]] = 1 @@ -829,9 +835,9 @@ class WebReport(Report.Report): if self.separate_alpha: doc.close() for n in link_keys: - p_list = [ p for p in person_list if \ - (p.get_primary_name().get_surname() \ - and (p.get_primary_name().get_surname()[0] == n) ) ] + p_id_list = [ p_id for p_id in person_id_list if \ + (self.db.find_person_from_id(p_id).get_primary_name().get_surname() \ + and (self.db.find_person_from_id(p_id).get_primary_name().get_surname()[0] == n) ) ] doc = HtmlLinkDoc(self.selected_style,None,template,None) doc.set_extension(self.ext) doc.set_title(_("Section %s") % n) @@ -848,10 +854,10 @@ class WebReport(Report.Report): doc.write_raw('' % td_width) col_len = n_rows - for person in p_list: - name = person.get_primary_name().get_name() + for person_id in p_id_list: + name = self.db.find_person_from_if(person_id).get_primary_name().get_name() - doc.start_link("%s.%s" % (person.get_id(),self.ext)) + doc.start_link("%s.%s" % (person_id,self.ext)) doc.write_text(name) doc.end_link() @@ -864,7 +870,7 @@ class WebReport(Report.Report): doc.write_raw('') doc.close() else: - n_rows = len(person_list) + len(link_keys) + n_rows = len(person_id_list) + len(link_keys) n_rows = n_rows/self.n_cols td_width = 100/self.n_cols @@ -872,9 +878,9 @@ class WebReport(Report.Report): doc.write_raw('' % td_width) col_len = n_rows for n in link_keys: - p_list = [ p for p in person_list if \ - (p.get_primary_name().get_surname() \ - and (p.get_primary_name().get_surname()[0] == n) ) ] + p_id_list = [ p_id for p_id in person_id_list if \ + (self.db.find_person_from_id(p_id).get_primary_name().get_surname() \ + and (self.db.find_person_from_id(p_id).get_primary_name().get_surname()[0] == n) ) ] doc.start_paragraph('IndexLabel') if self.include_alpha_links: doc.write_linktarget("%03d" % a[n]) @@ -882,10 +888,10 @@ class WebReport(Report.Report): doc.end_paragraph() col_len = col_len - 1 - for person in p_list: - name = person.get_primary_name().get_name() + for person_id in p_id_list: + name = self.db.find_person_from_id(person_id).get_primary_name().get_name() - doc.start_link("%s.%s" % (person.get_id(),self.ext)) + doc.start_link("%s.%s" % (person_id,self.ext)) doc.write_text(name) doc.end_link() if col_len <= 0: @@ -938,7 +944,7 @@ class WebReport(Report.Report): image_dir_name) return - ind_list = self.filter.apply(self.db,self.db.get_person_id_map().values()) + ind_list = self.filter.apply(self.db,self.db.get_person_keys()) self.progress_bar_setup(float(len(ind_list))) doc = HtmlLinkDoc(self.selected_style,None,self.template_name,None) @@ -950,8 +956,9 @@ class WebReport(Report.Report): my_map = {} for l in ind_list: - my_map[l.get_id()] = l - for person in ind_list: + my_map[l] = l + for person_id in ind_list: + person = self.db.find_person_from_id(person_id) tdoc = HtmlLinkDoc(self.selected_style,None,None,None,doc) tdoc.set_extension(self.ext) tdoc.set_keywords([person.get_primary_name().get_surname(),