Package gen :: Package proxy :: Module living
[frames] | no frames]

Source Code for Module gen.proxy.living

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2007       Brian G. Matherly 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful,  
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 19  # 
 20   
 21  # $Id: living.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Proxy class for the GRAMPS databases. Filter out all living people. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS libraries 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from proxybase import ProxyDbBase 
 33  from gen.lib import Date, Person, Name 
 34  from Utils import probably_alive 
 35   
 36  #------------------------------------------------------------------------- 
 37  # 
 38  # LivingProxyDb 
 39  # 
 40  #------------------------------------------------------------------------- 
41 -class LivingProxyDb(ProxyDbBase):
42 """ 43 A proxy to a Gramps database. This proxy will act like a Gramps database, 44 but all living people will be hidden from the user. 45 """ 46 MODE_EXCLUDE = 0 47 MODE_RESTRICT = 1 48
49 - def __init__(self,db,mode,current_year=None,years_after_death=0):
50 """ 51 Create a new LivingProxyDb instance. 52 53 @param db: The database to be a proxy for 54 @type db: DbBase 55 @param mode: The method for handling living people. 56 LivingProxyDb.MODE_EXCLUDE will remove living people altogether. 57 LivingProxyDb.MODE_RESTRICT will remove all information and change their 58 given name to "Living". 59 @type mode: int 60 @param current_year: The current year to use for living determination. 61 If None is supplied, the current year will be found from the system. 62 @type current_year: int or None 63 @param years_after_death: The number of years after a person's death to 64 still consider them living. 65 @type years_after_death: int 66 """ 67 ProxyDbBase.__init__(self, db) 68 self.mode = mode 69 if current_year != None: 70 self.current_date = Date() 71 self.current_date.set_year(current_year) 72 else: 73 self.current_date = None 74 self.years_after_death = years_after_death
75
76 - def get_person_from_handle(self, handle):
77 """ 78 Finds a Person in the database from the passed gramps ID. 79 If no such Person exists, None is returned. 80 """ 81 person = self.db.get_person_from_handle(handle) 82 if person and self.__is_living(person): 83 if self.mode == self.MODE_EXCLUDE: 84 person = None 85 elif self.mode == self.MODE_RESTRICT: 86 person = _restrict_person(person) 87 return person
88
89 - def get_source_from_handle(self, handle):
90 """ 91 Finds a Source in the database from the passed gramps ID. 92 If no such Source exists, None is returned. 93 """ 94 return self.db.get_source_from_handle(handle)
95
96 - def get_object_from_handle(self, handle):
97 """ 98 Finds an Object in the database from the passed gramps ID. 99 If no such Object exists, None is returned. 100 """ 101 return self.db.get_object_from_handle(handle)
102
103 - def get_place_from_handle(self, handle):
104 """ 105 Finds a Place in the database from the passed gramps ID. 106 If no such Place exists, None is returned. 107 """ 108 return self.db.get_place_from_handle(handle)
109
110 - def get_event_from_handle(self, handle):
111 """ 112 Finds a Event in the database from the passed gramps ID. 113 If no such Event exists, None is returned. 114 """ 115 return self.db.get_event_from_handle(handle)
116
117 - def get_family_from_handle(self, handle):
118 """ 119 Finds a Family in the database from the passed handle. 120 If no such Family exists, None is returned. 121 """ 122 family = self.db.get_family_from_handle(handle) 123 family = self.__remove_living_from_family(family) 124 return family
125
126 - def get_repository_from_handle(self, handle):
127 """ 128 Finds a Repository in the database from the passed gramps' ID. 129 If no such Repository exists, None is returned. 130 """ 131 return self.db.get_repository_from_handle(handle)
132
133 - def get_note_from_handle(self, handle):
134 """ 135 Finds a Note in the database from the passed gramps' ID. 136 If no such Note exists, None is returned. 137 """ 138 return self.db.get_note_from_handle(handle)
139
140 - def get_person_from_gramps_id(self, val):
141 """ 142 Finds a Person in the database from the passed GRAMPS ID. 143 If no such Person exists, None is returned. 144 """ 145 person = self.db.get_person_from_gramps_id(val) 146 if self.__is_living(person): 147 if self.mode == self.MODE_EXCLUDE: 148 return None 149 else: 150 return _restrict_person(person) 151 else: 152 return person
153
154 - def get_family_from_gramps_id(self, val):
155 """ 156 Finds a Family in the database from the passed GRAMPS ID. 157 If no such Family exists, None is returned. 158 """ 159 family = self.db.get_family_from_gramps_id(val) 160 family = self.__remove_living_from_family(family) 161 return family
162
163 - def get_event_from_gramps_id(self, val):
164 """ 165 Finds an Event in the database from the passed GRAMPS ID. 166 If no such Event exists, None is returned. 167 """ 168 return self.db.get_event_from_gramps_id(val)
169
170 - def get_place_from_gramps_id(self, val):
171 """ 172 Finds a Place in the database from the passed gramps' ID. 173 If no such Place exists, None is returned. 174 """ 175 return self.db.get_place_from_gramps_id(val)
176
177 - def get_source_from_gramps_id(self, val):
178 """ 179 Finds a Source in the database from the passed gramps' ID. 180 If no such Source exists, None is returned. 181 """ 182 return self.db.get_source_from_gramps_id(val)
183
184 - def get_object_from_gramps_id(self, val):
185 """ 186 Finds a MediaObject in the database from the passed gramps' ID. 187 If no such MediaObject exists, None is returned. 188 """ 189 return self.db.get_object_from_gramps_id(val)
190
191 - def get_repository_from_gramps_id(self, val):
192 """ 193 Finds a Repository in the database from the passed gramps' ID. 194 If no such Repository exists, None is returned. 195 """ 196 return self.db.get_repository_from_gramps_id(val)
197
198 - def get_note_from_gramps_id(self, val):
199 """ 200 Finds a Note in the database from the passed gramps' ID. 201 If no such Note exists, None is returned. 202 """ 203 return self.db.get_note_from_gramps_id(val)
204
205 - def get_person_handles(self, sort_handles=True):
206 """ 207 Return a list of database handles, one handle for each Person in 208 the database. If sort_handles is True, the list is sorted by surnames 209 """ 210 handles = [] 211 if self.mode == self.MODE_EXCLUDE: 212 for handle in self.db.get_person_handles(sort_handles): 213 person = self.db.get_person_from_handle(handle) 214 if not self.__is_living(person): 215 handles.append(handle) 216 elif self.mode == self.MODE_RESTRICT: 217 handles = self.db.get_person_handles(sort_handles) 218 return handles
219
220 - def get_place_handles(self, sort_handles=True):
221 """ 222 Return a list of database handles, one handle for each Place in 223 the database. If sort_handles is True, the list is sorted by 224 Place title. 225 """ 226 return self.db.get_place_handles(sort_handles)
227
228 - def get_source_handles(self, sort_handles=True):
229 """ 230 Return a list of database handles, one handle for each Source in 231 the database. If sort_handles is True, the list is sorted by 232 Source title. 233 """ 234 return self.db.get_source_handles(sort_handles)
235
236 - def get_media_object_handles(self, sort_handles=True):
237 """ 238 Return a list of database handles, one handle for each MediaObject in 239 the database. If sort_handles is True, the list is sorted by title. 240 """ 241 return self.db.get_media_object_handles(sort_handles)
242
243 - def get_event_handles(self):
244 """ 245 Return a list of database handles, one handle for each Event in 246 the database. 247 """ 248 return self.db.get_event_handles()
249
250 - def get_family_handles(self):
251 """ 252 Return a list of database handles, one handle for each Family in 253 the database. 254 """ 255 return self.db.get_family_handles()
256
257 - def get_repository_handles(self):
258 """ 259 Return a list of database handles, one handle for each Repository in 260 the database. 261 """ 262 return self.db.get_repository_handles()
263
264 - def get_note_handles(self):
265 """ 266 Return a list of database handles, one handle for each Note in 267 the database. 268 """ 269 return self.db.get_note_handles()
270
271 - def get_researcher(self):
272 """returns the Researcher instance, providing information about 273 the owner of the database""" 274 return self.db.get_researcher()
275
276 - def get_default_person(self):
277 """returns the default Person of the database""" 278 person_handle = self.db.get_default_handle() 279 return self.get_person_from_handle(person_handle)
280
281 - def get_default_handle(self):
282 """returns the default Person of the database""" 283 person_handle = self.db.get_default_handle() 284 if self.get_person_from_handle(person_handle): 285 return person_handle 286 return None
287
288 - def has_person_handle(self, handle):
289 """ 290 returns True if the handle exists in the current Person database. 291 """ 292 if self.get_person_from_handle(handle): 293 return True 294 return False
295
296 - def has_event_handle(self, handle):
297 """ 298 returns True if the handle exists in the current Event database. 299 """ 300 return self.db.has_event_handle(handle)
301
302 - def has_source_handle(self, handle):
303 """ 304 returns True if the handle exists in the current Source database. 305 """ 306 return self.db.has_source_handle(handle)
307
308 - def has_place_handle(self, handle):
309 """ 310 returns True if the handle exists in the current Place database. 311 """ 312 return self.db.has_place_handle(handle)
313
314 - def has_family_handle(self, handle):
315 """ 316 returns True if the handle exists in the current Family database. 317 """ 318 return self.db.has_family_handle(handle)
319
320 - def has_object_handle(self, handle):
321 """ 322 returns True if the handle exists in the current MediaObjectdatabase. 323 """ 324 return self.db.has_object_handle(handle)
325
326 - def has_repository_handle(self, handle):
327 """ 328 returns True if the handle exists in the current Repository database. 329 """ 330 return self.db.has_repository_handle(handle)
331
332 - def has_note_handle(self, handle):
333 """ 334 returns True if the handle exists in the current Note database. 335 """ 336 return self.db.has_note_handle(handle)
337 366
367 - def __is_living(self,person):
368 return probably_alive( person, 369 self.db, 370 self.current_date, 371 self.years_after_death )
372
373 - def __remove_living_from_family(self,family):
374 parent_is_living = False 375 376 father_handle = family.get_father_handle() 377 if father_handle: 378 father = self.db.get_person_from_handle(father_handle) 379 if self.__is_living(father): 380 parent_is_living = True 381 if self.mode == self.MODE_EXCLUDE: 382 family.set_father_handle(None) 383 384 mother_handle = family.get_mother_handle() 385 if mother_handle: 386 mother = self.db.get_person_from_handle(mother_handle) 387 if self.__is_living(mother): 388 parent_is_living = True 389 if self.mode == self.MODE_EXCLUDE: 390 family.set_mother_handle(None) 391 392 if parent_is_living: 393 # Clear all events for families where a parent is living. 394 family.set_event_ref_list([]) 395 396 if self.mode == self.MODE_EXCLUDE: 397 for child_ref in family.get_child_ref_list(): 398 child_handle = child_ref.get_reference_handle() 399 child = self.db.get_person_from_handle(child_handle) 400 if self.__is_living(child): 401 family.remove_child_ref(child_ref) 402 403 return family
404
405 -def _restrict_person(person):
406 new_person = Person() 407 new_name = Name() 408 old_name = person.get_primary_name() 409 410 new_name.set_group_as(old_name.get_group_as()) 411 new_name.set_sort_as(old_name.get_sort_as()) 412 new_name.set_display_as(old_name.get_display_as()) 413 new_name.set_surname_prefix(old_name.get_surname_prefix()) 414 new_name.set_type(old_name.get_type()) 415 new_name.set_first_name(_(u'Living')) 416 new_name.set_patronymic(old_name.get_patronymic()) 417 new_name.set_surname(old_name.get_surname()) 418 new_name.set_privacy(old_name.get_privacy()) 419 420 new_person.set_primary_name(new_name) 421 new_person.set_privacy(person.get_privacy()) 422 new_person.set_gender(person.get_gender()) 423 new_person.set_gramps_id(person.get_gramps_id()) 424 new_person.set_handle(person.get_handle()) 425 new_person.set_family_handle_list(person.get_family_handle_list()) 426 new_person.set_parent_family_handle_list( 427 person.get_parent_family_handle_list() ) 428 429 return new_person
430