1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 Proxy class for the GRAMPS databases. Filter out all living people.
25 """
26
27
28
29
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
39
40
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
88
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
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
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
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
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
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
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
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
162
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
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
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
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
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
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
219
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
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
242
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
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
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
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
272 """returns the Researcher instance, providing information about
273 the owner of the database"""
274 return self.db.get_researcher()
275
280
287
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
297 """
298 returns True if the handle exists in the current Event database.
299 """
300 return self.db.has_event_handle(handle)
301
303 """
304 returns True if the handle exists in the current Source database.
305 """
306 return self.db.has_source_handle(handle)
307
309 """
310 returns True if the handle exists in the current Place database.
311 """
312 return self.db.has_place_handle(handle)
313
315 """
316 returns True if the handle exists in the current Family database.
317 """
318 return self.db.has_family_handle(handle)
319
321 """
322 returns True if the handle exists in the current MediaObjectdatabase.
323 """
324 return self.db.has_object_handle(handle)
325
327 """
328 returns True if the handle exists in the current Repository database.
329 """
330 return self.db.has_repository_handle(handle)
331
333 """
334 returns True if the handle exists in the current Note database.
335 """
336 return self.db.has_note_handle(handle)
337
339 """
340 Find all objects that hold a reference to the object handle.
341 Returns an interator over alist of (class_name, handle) tuples.
342
343 @param handle: handle of the object to search for.
344 @type handle: database handle
345 @param include_classes: list of class names to include in the results.
346 Default: None means include all classes.
347 @type include_classes: list of class names
348
349 This default implementation does a sequencial scan through all
350 the primary object databases and is very slow. Backends can
351 override this method to provide much faster implementations that
352 make use of additional capabilities of the backend.
353
354 Note that this is a generator function, it returns a iterator for
355 use in loops. If you want a list of the results use:
356
357 > result_list = [i for i in find_backlink_handles(handle)]
358 """
359 handle_itr = self.db.find_backlink_handles(handle, include_classes)
360 for (class_name, handle) in handle_itr:
361 if class_name == 'Person':
362 if not self.get_person_from_handle(handle):
363 continue
364 yield (class_name, handle)
365 return
366
368 return probably_alive( person,
369 self.db,
370 self.current_date,
371 self.years_after_death )
372
404
430