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

Source Code for Module gen.proxy.filter

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2007-2008       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: filter.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Proxy class for the GRAMPS databases. Apply filter 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS libraries 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  #from gen.lib import * 
 33  from proxybase import ProxyDbBase 
 34   
35 -class FilterProxyDb(ProxyDbBase):
36 """ 37 A proxy to a Gramps database. This proxy will act like a Gramps database, 38 but all data marked private will be hidden from the user. 39 """ 40
41 - def __init__(self, db, person_filter=None, event_filter=None):
42 """ 43 Create a new PrivateProxyDb instance. 44 """ 45 ProxyDbBase.__init__(self, db) 46 self.person_filter = person_filter 47 48 if person_filter: 49 self.plist = set(person_filter.apply( 50 self.db, self.db.get_person_handles(sort_handles=False))) 51 else: 52 self.plist = self.db.get_person_handles(sort_handles=False) 53 54 if event_filter: 55 self.elist = set(event_filter.apply( 56 self.db, self.db.get_event_handles())) 57 else: 58 self.elist = self.db.get_event_handles() 59 60 self.flist = set() 61 for handle in list(self.plist): 62 person = self.db.get_person_from_handle(handle) 63 for family_handle in person.get_family_handle_list(): 64 self.flist.add(family_handle)
65
66 - def get_person_from_handle(self, handle):
67 """ 68 Finds a Person in the database from the passed gramps' ID. 69 If no such Person exists, None is returned. 70 """ 71 if handle in self.plist: 72 person = self.db.get_person_from_handle(handle) 73 74 person.set_person_ref_list( 75 [ ref for ref in person.get_person_ref_list() 76 if ref.ref in self.plist ]) 77 78 person.set_family_handle_list( 79 [ hndl for hndl in person.get_family_handle_list() 80 if hndl in self.flist ]) 81 82 person.set_parent_family_handle_list( 83 [ hndl for hndl in person.get_parent_family_handle_list() 84 if hndl in self.flist ]) 85 86 eref_list = person.get_event_ref_list() 87 bref = person.get_birth_ref() 88 dref = person.get_death_ref() 89 90 new_eref_list = [ ref for ref in eref_list 91 if ref.ref in self.elist] 92 93 person.set_event_ref_list(new_eref_list) 94 if bref in new_eref_list: 95 person.set_birth_ref(bref) 96 if dref in new_eref_list: 97 person.set_death_ref(dref) 98 99 return person 100 else: 101 return None
102
103 - def get_source_from_handle(self, handle):
104 """ 105 Finds a Source in the database from the passed gramps' ID. 106 If no such Source exists, None is returned. 107 """ 108 return self.db.get_source_from_handle(handle)
109
110 - def get_object_from_handle(self, handle):
111 """ 112 Finds an Object in the database from the passed gramps' ID. 113 If no such Object exists, None is returned. 114 """ 115 return self.db.get_object_from_handle(handle)
116
117 - def get_place_from_handle(self, handle):
118 """ 119 Finds a Place in the database from the passed gramps' ID. 120 If no such Place exists, None is returned. 121 """ 122 return self.db.get_place_from_handle(handle)
123
124 - def get_event_from_handle(self, handle):
125 """ 126 Finds a Event in the database from the passed gramps' ID. 127 If no such Event exists, None is returned. 128 """ 129 if handle in self.elist: 130 return self.db.get_event_from_handle(handle) 131 else: 132 return None
133
134 - def get_family_from_handle(self, handle):
135 """ 136 Finds a Family in the database from the passed gramps' ID. 137 If no such Family exists, None is returned. 138 """ 139 if handle in self.flist: 140 family = self.db.get_family_from_handle(handle) 141 142 eref_list = [ eref for eref in family.get_event_ref_list() 143 if eref.ref in self.elist ] 144 family.set_event_ref_list(eref_list) 145 146 if family.get_father_handle() not in self.plist: 147 family.set_father_handle(None) 148 149 if family.get_mother_handle() not in self.plist: 150 family.set_mother_handle(None) 151 152 clist = [ cref for cref in family.get_child_ref_list() 153 if cref.ref in self.plist ] 154 family.set_child_ref_list(clist) 155 return family 156 else: 157 return None
158
159 - def get_repository_from_handle(self, handle):
160 """ 161 Finds a Repository in the database from the passed gramps' ID. 162 If no such Repository exists, None is returned. 163 """ 164 return self.db.get_repository_from_handle(handle)
165
166 - def get_note_from_handle(self, handle):
167 """ 168 Finds a Note in the database from the passed gramps' ID. 169 If no such Note exists, None is returned. 170 """ 171 return self.db.get_note_from_handle(handle)
172
173 - def get_person_from_gramps_id(self, val):
174 """ 175 Finds a Person in the database from the passed GRAMPS ID. 176 If no such Person exists, None is returned. 177 """ 178 person = self.db.get_person_from_gramps_id(val) 179 if person.get_handle() not in self.plist: 180 return None 181 else: 182 return person
183
184 - def get_family_from_gramps_id(self, val):
185 """ 186 Finds a Family in the database from the passed GRAMPS ID. 187 If no such Family exists, None is returned. 188 """ 189 return self.db.get_family_from_gramps_id(val)
190
191 - def get_event_from_gramps_id(self, val):
192 """ 193 Finds an Event in the database from the passed GRAMPS ID. 194 If no such Event exists, None is returned. 195 """ 196 event = self.db.get_event_from_gramps_id(val) 197 if event.get_handle() not in self.elist: 198 return None 199 else: 200 return event
201
202 - def get_place_from_gramps_id(self, val):
203 """ 204 Finds a Place in the database from the passed gramps' ID. 205 If no such Place exists, None is returned. 206 """ 207 return self.db.get_place_from_gramps_id(val)
208
209 - def get_source_from_gramps_id(self, val):
210 """ 211 Finds a Source in the database from the passed gramps' ID. 212 If no such Source exists, None is returned. 213 """ 214 return self.db.get_source_from_gramps_id(val)
215
216 - def get_object_from_gramps_id(self, val):
217 """ 218 Finds a MediaObject in the database from the passed gramps' ID. 219 If no such MediaObject exists, None is returned. 220 """ 221 return self.db.get_object_from_gramps_id(val)
222
223 - def get_repository_from_gramps_id(self, val):
224 """ 225 Finds a Repository in the database from the passed gramps' ID. 226 If no such Repository exists, None is returned. 227 """ 228 return self.db.get_repository_from_gramps_id(val)
229
230 - def get_note_from_gramps_id(self, val):
231 """ 232 Finds a Note in the database from the passed gramps' ID. 233 If no such Note exists, None is returned. 234 """ 235 return self.db.get_note_from_gramps_id(val)
236
237 - def get_person_handles(self, sort_handles=True):
238 """ 239 Return a list of database handles, one handle for each Person in 240 the database. If sort_handles is True, the list is sorted by surnames 241 """ 242 return list(self.plist)
243
244 - def get_place_handles(self, sort_handles=True):
245 """ 246 Return a list of database handles, one handle for each Place in 247 the database. If sort_handles is True, the list is sorted by 248 Place title. 249 """ 250 return self.db.get_place_handles(sort_handles)
251
252 - def get_source_handles(self, sort_handles=True):
253 """ 254 Return a list of database handles, one handle for each Source in 255 the database. If sort_handles is True, the list is sorted by 256 Source title. 257 """ 258 return self.db.get_source_handles(sort_handles)
259
260 - def get_media_object_handles(self, sort_handles=True):
261 """ 262 Return a list of database handles, one handle for each MediaObject in 263 the database. If sort_handles is True, the list is sorted by title. 264 """ 265 return self.db.get_media_object_handles(sort_handles)
266
267 - def get_event_handles(self):
268 """ 269 Return a list of database handles, one handle for each Event in 270 the database. 271 """ 272 return list(self.elist)
273
274 - def get_family_handles(self):
275 """ 276 Return a list of database handles, one handle for each Family in 277 the database. 278 """ 279 return list(self.flist)
280
281 - def get_repository_handles(self):
282 """ 283 Return a list of database handles, one handle for each Repository in 284 the database. 285 """ 286 return self.db.get_repository_handles()
287
288 - def get_note_handles(self):
289 """ 290 Return a list of database handles, one handle for each Note in 291 the database. 292 """ 293 return self.db.get_note_handles()
294
295 - def get_researcher(self):
296 """returns the Researcher instance, providing information about 297 the owner of the database""" 298 return self.db.get_researcher()
299
300 - def get_default_person(self):
301 """returns the default Person of the database""" 302 person = self.db.get_default_person() 303 if person and person.get_handle() in self.plist: 304 return person 305 else: 306 return None
307
308 - def get_default_handle(self):
309 """returns the default Person of the database""" 310 handle = self.db.get_default_handle() 311 if handle in self.plist: 312 return handle 313 else: 314 return None
315
316 - def has_person_handle(self, handle):
317 """ 318 returns True if the handle exists in the current Person database. 319 """ 320 return handle in self.plist
321
322 - def has_event_handle(self, handle):
323 """ 324 returns True if the handle exists in the current Event database. 325 """ 326 return handle in self.elist
327
328 - def has_source_handle(self, handle):
329 """ 330 returns True if the handle exists in the current Source database. 331 """ 332 return self.db.has_source_handle(handle)
333
334 - def has_place_handle(self, handle):
335 """ 336 returns True if the handle exists in the current Place database. 337 """ 338 return self.db.has_place_handle(handle)
339
340 - def has_family_handle(self, handle):
341 """ 342 returns True if the handle exists in the current Family database. 343 """ 344 return self.db.has_family_handle(handle)
345
346 - def has_object_handle(self, handle):
347 """ 348 returns True if the handle exists in the current MediaObjectdatabase. 349 """ 350 return self.db.has_object_handle(handle)
351
352 - def has_repository_handle(self, handle):
353 """ 354 returns True if the handle exists in the current Repository database. 355 """ 356 return self.db.has_repository_handle(handle)
357
358 - def has_note_handle(self, handle):
359 """ 360 returns True if the handle exists in the current Note database. 361 """ 362 return self.db.has_note_handle(handle)
363