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

Source Code for Module gen.proxy.private

  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: private.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Proxy class for the GRAMPS databases. Filter out all data marked private. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS libraries 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib import (MediaRef, SourceRef, Attribute, Address, EventRef,  
 33                       Person, Name, Source, RepoRef, MediaObject, Place, Event,  
 34                       Family, ChildRef, Repository) 
 35  from proxybase import ProxyDbBase 
 36   
37 -class PrivateProxyDb(ProxyDbBase):
38 """ 39 A proxy to a Gramps database. This proxy will act like a Gramps database, 40 but all data marked private will be hidden from the user. 41 """ 42
43 - def __init__(self,db):
44 """ 45 Create a new PrivateProxyDb instance. 46 """ 47 ProxyDbBase.__init__(self, db)
48
49 - def get_person_from_handle(self, handle):
50 """ 51 Finds a Person in the database from the passed gramps' ID. 52 If no such Person exists, None is returned. 53 """ 54 person = self.db.get_person_from_handle(handle) 55 if person and not person.get_privacy(): 56 return sanitize_person(self.db,person) 57 return None
58
59 - def get_source_from_handle(self, handle):
60 """ 61 Finds a Source in the database from the passed gramps' ID. 62 If no such Source exists, None is returned. 63 """ 64 source = self.db.get_source_from_handle(handle) 65 if source and not source.get_privacy(): 66 return sanitize_source(self.db,source) 67 return None
68
69 - def get_object_from_handle(self, handle):
70 """ 71 Finds an Object in the database from the passed gramps' ID. 72 If no such Object exists, None is returned. 73 """ 74 media = self.db.get_object_from_handle(handle) 75 if media and not media.get_privacy(): 76 return sanitize_media(self.db,media) 77 return None
78
79 - def get_place_from_handle(self, handle):
80 """ 81 Finds a Place in the database from the passed gramps' ID. 82 If no such Place exists, None is returned. 83 """ 84 place = self.db.get_place_from_handle(handle) 85 if place and not place.get_privacy(): 86 return sanitize_place(self.db,place) 87 return None
88
89 - def get_event_from_handle(self, handle):
90 """ 91 Finds a Event in the database from the passed gramps' ID. 92 If no such Event exists, None is returned. 93 """ 94 event = self.db.get_event_from_handle(handle) 95 if event and not event.get_privacy(): 96 return sanitize_event(self.db,event) 97 return None
98
99 - def get_family_from_handle(self, handle):
100 """ 101 Finds a Family in the database from the passed gramps' ID. 102 If no such Family exists, None is returned. 103 """ 104 family = self.db.get_family_from_handle(handle) 105 if family and not family.get_privacy(): 106 return sanitize_family(self.db,family) 107 return None
108
109 - def get_repository_from_handle(self, handle):
110 """ 111 Finds a Repository in the database from the passed gramps' ID. 112 If no such Repository exists, None is returned. 113 """ 114 repository = self.db.get_repository_from_handle(handle) 115 if repository and not repository.get_privacy(): 116 return sanitize_repository(self.db,repository) 117 return None
118
119 - def get_note_from_handle(self, handle):
120 """ 121 Finds a Note in the database from the passed gramps' ID. 122 If no such Note exists, None is returned. 123 """ 124 note = self.db.get_note_from_handle(handle) 125 if note and not note.get_privacy(): 126 return note 127 return None
128
129 - def get_person_from_gramps_id(self, val):
130 """ 131 Finds a Person in the database from the passed GRAMPS ID. 132 If no such Person exists, None is returned. 133 """ 134 person = self.db.get_person_from_gramps_id(val) 135 if not person.get_privacy(): 136 return sanitize_person(self.db,person) 137 return None
138
139 - def get_family_from_gramps_id(self, val):
140 """ 141 Finds a Family in the database from the passed GRAMPS ID. 142 If no such Family exists, None is returned. 143 """ 144 family = self.db.get_family_from_gramps_id(val) 145 if not family.get_privacy(): 146 return sanitize_family(self.db,family) 147 return None
148
149 - def get_event_from_gramps_id(self, val):
150 """ 151 Finds an Event in the database from the passed GRAMPS ID. 152 If no such Event exists, None is returned. 153 """ 154 event = self.db.get_event_from_gramps_id(val) 155 if not event.get_privacy(): 156 return sanitize_event(self.db,event) 157 return None
158
159 - def get_place_from_gramps_id(self, val):
160 """ 161 Finds a Place in the database from the passed gramps' ID. 162 If no such Place exists, None is returned. 163 """ 164 place = self.db.get_place_from_gramps_id(val) 165 if not place.get_privacy(): 166 return sanitize_place(self.db,place) 167 return None
168
169 - def get_source_from_gramps_id(self, val):
170 """ 171 Finds a Source in the database from the passed gramps' ID. 172 If no such Source exists, None is returned. 173 """ 174 source = self.db.get_source_from_gramps_id(val) 175 if not source.get_privacy(): 176 return sanitize_source(self.db,source) 177 return None
178
179 - def get_object_from_gramps_id(self, val):
180 """ 181 Finds a MediaObject in the database from the passed gramps' ID. 182 If no such MediaObject exists, None is returned. 183 """ 184 object = self.db.get_object_from_gramps_id(val) 185 if not object.get_privacy(): 186 return sanitize_media(self.db, object) 187 return None
188
189 - def get_repository_from_gramps_id(self, val):
190 """ 191 Finds a Repository in the database from the passed gramps' ID. 192 If no such Repository exists, None is returned. 193 """ 194 repository = self.db.get_repository_from_gramps_id(val) 195 if not repository.get_privacy(): 196 return sanitize_repository(self.db,repository) 197 return None
198
199 - def get_note_from_gramps_id(self, val):
200 """ 201 Finds a Note in the database from the passed gramps' ID. 202 If no such Note exists, None is returned. 203 """ 204 note = self.db.get_note_from_gramps_id(val) 205 if not note.get_privacy(): 206 return note 207 return None
208
209 - def get_person_handles(self, sort_handles=True):
210 """ 211 Return a list of database handles, one handle for each Person in 212 the database. If sort_handles is True, the list is sorted by surnames 213 """ 214 handles = [] 215 for handle in self.db.get_person_handles(sort_handles): 216 person = self.db.get_person_from_handle(handle) 217 if not person.get_privacy(): 218 handles.append(handle) 219 return handles
220
221 - def get_place_handles(self, sort_handles=True):
222 """ 223 Return a list of database handles, one handle for each Place in 224 the database. If sort_handles is True, the list is sorted by 225 Place title. 226 """ 227 handles = [] 228 for handle in self.db.get_place_handles(sort_handles): 229 place = self.db.get_place_from_handle(handle) 230 if not place.get_privacy(): 231 handles.append(handle) 232 return handles
233
234 - def get_source_handles(self, sort_handles=True):
235 """ 236 Return a list of database handles, one handle for each Source in 237 the database. If sort_handles is True, the list is sorted by 238 Source title. 239 """ 240 handles = [] 241 for handle in self.db.get_source_handles(sort_handles): 242 source = self.db.get_source_from_handle(handle) 243 if not source.get_privacy(): 244 handles.append(handle) 245 return handles
246
247 - def get_media_object_handles(self, sort_handles=True):
248 """ 249 Return a list of database handles, one handle for each MediaObject in 250 the database. If sort_handles is True, the list is sorted by title. 251 """ 252 handles = [] 253 for handle in self.db.get_media_object_handles(sort_handles): 254 object = self.db.get_object_from_handle(handle) 255 if not object.get_privacy(): 256 handles.append(handle) 257 return handles
258
259 - def get_event_handles(self):
260 """ 261 Return a list of database handles, one handle for each Event in 262 the database. 263 """ 264 handles = [] 265 for handle in self.db.get_event_handles(): 266 event = self.db.get_event_from_handle(handle) 267 if not event.get_privacy(): 268 handles.append(handle) 269 return handles
270
271 - def get_family_handles(self):
272 """ 273 Return a list of database handles, one handle for each Family in 274 the database. 275 """ 276 handles = [] 277 for handle in self.db.get_family_handles(): 278 family = self.db.get_family_from_handle(handle) 279 if not family.get_privacy(): 280 handles.append(handle) 281 return handles
282
283 - def get_repository_handles(self):
284 """ 285 Return a list of database handles, one handle for each Repository in 286 the database. 287 """ 288 handles = [] 289 for handle in self.db.get_repository_handles(): 290 repository = self.db.get_repository_from_handle(handle) 291 if not repository.get_privacy(): 292 handles.append(handle) 293 return handles
294
295 - def get_note_handles(self):
296 """ 297 Return a list of database handles, one handle for each Note in 298 the database. 299 """ 300 handles = [] 301 for handle in self.db.get_note_handles(): 302 note = self.db.get_note_from_handle(handle) 303 if not note.get_privacy(): 304 handles.append(handle) 305 return handles
306
307 - def get_researcher(self):
308 """returns the Researcher instance, providing information about 309 the owner of the database""" 310 return self.db.get_researcher()
311
312 - def get_default_person(self):
313 """returns the default Person of the database""" 314 person = self.db.get_default_person() 315 if person and not person.get_privacy(): 316 return sanitize_person(self.db,person) 317 return None
318
319 - def get_default_handle(self):
320 """returns the default Person of the database""" 321 handle = self.db.get_default_handle() 322 person = self.db.get_person_from_handle(handle) 323 if person and not person.get_privacy(): 324 return handle 325 return None
326
327 - def has_person_handle(self, handle):
328 """ 329 returns True if the handle exists in the current Person database. 330 """ 331 has_person = False 332 person = self.db.get_person_from_handle() 333 if person and not person.get_privacy(): 334 has_person = True 335 return has_person
336
337 - def has_event_handle(self, handle):
338 """ 339 returns True if the handle exists in the current Event database. 340 """ 341 has_event = False 342 event = self.db.get_event_from_handle() 343 if event and not event.get_privacy(): 344 has_event = True 345 return has_event
346
347 - def has_source_handle(self, handle):
348 """ 349 returns True if the handle exists in the current Source database. 350 """ 351 has_source = False 352 source = self.db.get_source_from_handle() 353 if source and not source.get_privacy(): 354 has_source = True 355 return has_source
356
357 - def has_place_handle(self, handle):
358 """ 359 returns True if the handle exists in the current Place database. 360 """ 361 has_place = False 362 place = self.db.get_place_from_handle() 363 if place and not place.get_privacy(): 364 has_place = True 365 return has_place
366
367 - def has_family_handle(self, handle):
368 """ 369 returns True if the handle exists in the current Family database. 370 """ 371 has_family = False 372 family = self.db.get_family_from_handle() 373 if family and not family.get_privacy(): 374 has_family = True 375 return has_family
376
377 - def has_object_handle(self, handle):
378 """ 379 returns True if the handle exists in the current MediaObjectdatabase. 380 """ 381 has_object = False 382 object = self.db.get_object_from_handle() 383 if object and not object.get_privacy(): 384 has_object = True 385 return has_object
386
387 - def has_repository_handle(self, handle):
388 """ 389 returns True if the handle exists in the current Repository database. 390 """ 391 has_repository = False 392 repository = self.db.get_repository_from_handle() 393 if repository and not repository.get_privacy(): 394 has_repository = True 395 return has_repository
396
397 - def has_note_handle(self, handle):
398 """ 399 returns True if the handle exists in the current Note database. 400 """ 401 has_note = False 402 note = self.db.get_note_from_handle() 403 if note and not note.get_privacy(): 404 has_note = True 405 return has_note
406 458 459
460 -def copy_media_ref_list(db, original_obj,clean_obj):
461 """ 462 Copies media references from one object to another - excluding private 463 references and references to private objects. 464 465 @param db: GRAMPS database to which the references belongs 466 @type db: GrampsDbBase 467 @param original_obj: Object that may have private references 468 @type original_obj: MediaBase 469 @param clean_obj: Object that will have only non-private references 470 @type original_obj: MediaBase 471 @returns: Nothing 472 """ 473 for media_ref in original_obj.get_media_list(): 474 if not media_ref.get_privacy(): 475 handle = media_ref.get_reference_handle() 476 media_object = db.get_object_from_handle(handle) 477 if not media_object.get_privacy(): 478 clean_obj.add_media_reference(MediaRef(media_ref))
479
480 -def copy_source_ref_list(db, original_obj,clean_obj):
481 """ 482 Copies source references from one object to another - excluding private 483 references and references to private objects. 484 485 @param db: GRAMPS database to which the references belongs 486 @type db: GrampsDbBase 487 @param original_obj: Object that may have private references 488 @type original_obj: SourceBase 489 @param clean_obj: Object that will have only non-private references 490 @type original_obj: SourceBase 491 @returns: Nothing 492 """ 493 for ref in original_obj.get_source_references(): 494 if not ref.get_privacy(): 495 handle = ref.get_reference_handle() 496 source = db.get_source_from_handle(handle) 497 if not source.get_privacy(): 498 clean_obj.add_source_reference(SourceRef(ref))
499
500 -def copy_notes(db, original_obj,clean_obj):
501 """ 502 Copies notes from one object to another - excluding references to private 503 notes. 504 505 @param db: GRAMPS database to which the references belongs 506 @type db: GrampsDbBase 507 @param original_obj: Object that may have private references 508 @type original_obj: NoteBase 509 @param clean_obj: Object that will have only non-private references 510 @type original_obj: NoteBase 511 @returns: Nothing 512 """ 513 for note_handle in original_obj.get_note_list(): 514 note = db.get_note_from_handle(note_handle) 515 if not note.get_privacy(): 516 clean_obj.add_note(note_handle)
517
518 -def copy_attributes(db, original_obj,clean_obj):
519 """ 520 Copies attributes from one object to another - excluding references to 521 private attributes. 522 523 @param db: GRAMPS database to which the references belongs 524 @type db: GrampsDbBase 525 @param original_obj: Object that may have private references 526 @type original_obj: AttributeBase 527 @param clean_obj: Object that will have only non-private references 528 @type original_obj: AttributeBase 529 @returns: Nothing 530 """ 531 for attribute in original_obj.get_attribute_list(): 532 if not attribute.get_privacy(): 533 new_attribute = Attribute() 534 new_attribute.set_type(attribute.get_type()) 535 new_attribute.set_value(attribute.get_value()) 536 copy_notes(db,attribute, new_attribute) 537 copy_source_ref_list(db,attribute, new_attribute) 538 clean_obj.add_attribute(new_attribute)
539
540 -def copy_urls(db, original_obj,clean_obj):
541 """ 542 Copies urls from one object to another - excluding references to 543 private urls. 544 545 @param db: GRAMPS database to which the references belongs 546 @type db: GrampsDbBase 547 @param original_obj: Object that may have urls 548 @type original_obj: UrlBase 549 @param clean_obj: Object that will have only non-private urls 550 @type original_obj: UrlBase 551 @returns: Nothing 552 """ 553 for url in original_obj.get_url_list(): 554 if not url.get_privacy(): 555 clean_obj.add_url(url)
556
557 -def copy_lds_ords(db, original_obj,clean_obj):
558 """ 559 Copies LDS ORDs from one object to another - excluding references to 560 private LDS ORDs. 561 562 @param db: GRAMPS database to which the references belongs 563 @type db: GrampsDbBase 564 @param original_obj: Object that may have LDS ORDs 565 @type original_obj: LdsOrdBase 566 @param clean_obj: Object that will have only non-private LDS ORDs 567 @type original_obj: LdsOrdBase 568 @returns: Nothing 569 """ 570 for lds_ord in original_obj.get_lds_ord_list(): 571 if not lds_ord.get_privacy(): 572 clean_obj.add_lds_ord( lds_ord )
573
574 -def copy_addresses(db, original_obj,clean_obj):
575 """ 576 Copies addresses from one object to another - excluding references to 577 private addresses. 578 579 @param db: GRAMPS database to which the references belongs 580 @type db: GrampsDbBase 581 @param original_obj: Object that may have addresses 582 @type original_obj: AddressBase 583 @param clean_obj: Object that will have only non-private addresses 584 @type original_obj: AddressBase 585 @returns: Nothing 586 """ 587 for address in original_obj.get_address_list(): 588 if not address.get_privacy(): 589 clean_obj.add_address(Address(address))
590
591 -def sanitize_name(db, name):
592 """ 593 Create a new Name instance based off the passed Name 594 instance. The returned instance has all private records 595 removed from it. 596 597 @param db: GRAMPS database to which the Person object belongs 598 @type db: GrampsDbBase 599 @param name: source Name object that will be copied with 600 privacy records removed 601 @type name: Name 602 @returns: 'cleansed' Name object 603 @rtype: Name 604 """ 605 new_name = Name() 606 new_name.set_group_as(name.get_group_as()) 607 new_name.set_sort_as(name.get_sort_as()) 608 new_name.set_display_as(name.get_display_as()) 609 new_name.set_call_name(name.get_call_name()) 610 new_name.set_surname_prefix(name.get_surname_prefix()) 611 new_name.set_type(name.get_type()) 612 new_name.set_first_name(name.get_first_name()) 613 new_name.set_patronymic(name.get_patronymic()) 614 new_name.set_surname(name.get_surname()) 615 new_name.set_suffix(name.get_suffix()) 616 new_name.set_title(name.get_title()) 617 new_name.set_date_object(name.get_date_object()) 618 619 copy_source_ref_list(db, name, new_name) 620 copy_notes(db, name, new_name) 621 622 return new_name
623
624 -def sanitize_event_ref(db,event_ref):
625 """ 626 Create a new EventRef instance based off the passed EventRef 627 instance. The returned instance has all private records 628 removed from it. 629 630 @param db: GRAMPS database to which the Person object belongs 631 @type db: GrampsDbBase 632 @param event_ref: source EventRef object that will be copied with 633 privacy records removed 634 @type event_ref: EventRef 635 @returns: 'cleansed' EventRef object 636 @rtype: EventRef 637 """ 638 new_ref = EventRef() 639 640 new_ref.set_reference_handle(event_ref.get_reference_handle()) 641 new_ref.set_role(event_ref.get_role()) 642 copy_notes(db,event_ref, new_ref) 643 copy_attributes(db,event_ref, new_ref) 644 645 return new_ref
646
647 -def sanitize_person(db,person):
648 """ 649 Create a new Person instance based off the passed Person 650 instance. The returned instance has all private records 651 removed from it. 652 653 @param db: GRAMPS database to which the Person object belongs 654 @type db: GrampsDbBase 655 @param person: source Person object that will be copied with 656 privacy records removed 657 @type person: Person 658 @returns: 'cleansed' Person object 659 @rtype: Person 660 """ 661 new_person = Person() 662 663 # copy gender 664 new_person.set_gender(person.get_gender()) 665 new_person.set_gramps_id(person.get_gramps_id()) 666 new_person.set_handle(person.get_handle()) 667 668 # copy names if not private 669 name = person.get_primary_name() 670 if name.get_privacy() or person.get_privacy(): 671 # Do this so a person always has a primary name of some sort. 672 name = Name() 673 name.set_surname(_('Private')) 674 else: 675 name = sanitize_name(db, name) 676 new_person.set_primary_name(name) 677 678 # copy Family reference list 679 for handle in person.get_family_handle_list(): 680 family = db.get_family_from_handle(handle) 681 if not family.get_privacy(): 682 new_person.add_family_handle(handle) 683 684 # copy Family reference list 685 for handle in person.get_parent_family_handle_list(): 686 family = db.get_family_from_handle(handle) 687 if family.get_privacy(): 688 continue 689 child_ref_list = family.get_child_ref_list() 690 for child_ref in child_ref_list: 691 if child_ref.get_reference_handle() == person.get_handle(): 692 if not child_ref.get_privacy(): 693 new_person.add_parent_family_handle(handle) 694 break 695 696 for name in person.get_alternate_names(): 697 if not name.get_privacy(): 698 new_person.add_alternate_name(sanitize_name(db, name)) 699 700 # set complete flag 701 new_person.set_marker(person.get_marker()) 702 703 # copy event list 704 for event_ref in person.get_event_ref_list(): 705 if event_ref and not event_ref.get_privacy(): 706 event = db.get_event_from_handle(event_ref.ref) 707 if not event.get_privacy(): 708 new_person.add_event_ref(sanitize_event_ref(db,event_ref)) 709 710 # Copy birth and death after event list to maintain the order. 711 # copy birth event 712 event_ref = person.get_birth_ref() 713 if event_ref and not event_ref.get_privacy(): 714 event = db.get_event_from_handle(event_ref.ref) 715 if not event.get_privacy(): 716 new_person.set_birth_ref(sanitize_event_ref(db,event_ref)) 717 718 # copy death event 719 event_ref = person.get_death_ref() 720 if event_ref and not event_ref.get_privacy(): 721 event = db.get_event_from_handle(event_ref.ref) 722 if not event.get_privacy(): 723 new_person.set_death_ref(sanitize_event_ref(db,event_ref)) 724 725 copy_addresses(db,person, new_person) 726 copy_attributes(db,person, new_person) 727 copy_source_ref_list(db,person, new_person) 728 copy_urls(db,person, new_person) 729 copy_media_ref_list(db,person, new_person) 730 copy_lds_ords(db,person, new_person) 731 copy_notes(db,person, new_person) 732 733 return new_person
734
735 -def sanitize_source(db,source):
736 """ 737 Create a new Source instance based off the passed Source 738 instance. The returned instance has all private records 739 removed from it. 740 741 @param db: GRAMPS database to which the Person object belongs 742 @type db: GrampsDbBase 743 @param source: source Source object that will be copied with 744 privacy records removed 745 @type source: Source 746 @returns: 'cleansed' Source object 747 @rtype: Source 748 """ 749 new_source = Source() 750 751 new_source.set_author(source.get_author()) 752 new_source.set_title(source.get_title()) 753 new_source.set_publication_info(source.get_publication_info()) 754 new_source.set_abbreviation(source.get_abbreviation()) 755 new_source.set_gramps_id(source.get_gramps_id()) 756 new_source.set_handle(source.get_handle()) 757 new_source.set_marker(source.get_marker()) 758 new_source.set_data_map(source.get_data_map()) 759 760 for repo_ref in source.get_reporef_list(): 761 if not repo_ref.get_privacy(): 762 handle = repo_ref.get_reference_handle() 763 repo = db.get_repository_from_handle(handle) 764 if not repo.get_privacy(): 765 new_source.add_repo_reference(RepoRef(repo_ref)) 766 767 copy_media_ref_list(db,source, new_source) 768 copy_notes(db,source, new_source) 769 770 return new_source
771
772 -def sanitize_media(db,media):
773 """ 774 Create a new MediaObject instance based off the passed Media 775 instance. The returned instance has all private records 776 removed from it. 777 778 @param db: GRAMPS database to which the Person object belongs 779 @type db: GrampsDbBase 780 @param media: source Media object that will be copied with 781 privacy records removed 782 @type media: MediaObject 783 @returns: 'cleansed' Media object 784 @rtype: MediaObject 785 """ 786 new_media = MediaObject() 787 788 new_media.set_mime_type(media.get_mime_type()) 789 new_media.set_path(media.get_path()) 790 new_media.set_description(media.get_description()) 791 new_media.set_gramps_id(media.get_gramps_id()) 792 new_media.set_handle(media.get_handle()) 793 new_media.set_date_object(media.get_date_object()) 794 new_media.set_marker(media.get_marker()) 795 796 copy_source_ref_list(db,media, new_media) 797 copy_attributes(db,media, new_media) 798 copy_notes(db,media, new_media) 799 800 return new_media
801
802 -def sanitize_place(db,place):
803 """ 804 Create a new Place instance based off the passed Place 805 instance. The returned instance has all private records 806 removed from it. 807 808 @param db: GRAMPS database to which the Person object belongs 809 @type db: GrampsDbBase 810 @param place: source Place object that will be copied with 811 privacy records removed 812 @type place: Place 813 @returns: 'cleansed' Place object 814 @rtype: Place 815 """ 816 new_place = Place() 817 818 new_place.set_title(place.get_title()) 819 new_place.set_gramps_id(place.get_gramps_id()) 820 new_place.set_handle(place.get_handle()) 821 new_place.set_longitude(place.get_longitude()) 822 new_place.set_latitude(place.get_latitude()) 823 new_place.set_main_location(place.get_main_location()) 824 new_place.set_alternate_locations(place.get_alternate_locations()) 825 new_place.set_marker(place.get_marker()) 826 827 copy_source_ref_list(db,place, new_place) 828 copy_notes(db,place, new_place) 829 copy_media_ref_list(db,place, new_place) 830 copy_urls(db,place, new_place) 831 832 return new_place
833
834 -def sanitize_event(db,event):
835 """ 836 Create a new Event instance based off the passed Event 837 instance. The returned instance has all private records 838 removed from it. 839 840 @param db: GRAMPS database to which the Person object belongs 841 @type db: GrampsDbBase 842 @param event: source Event object that will be copied with 843 privacy records removed 844 @type event: Event 845 @returns: 'cleansed' Event object 846 @rtype: Event 847 """ 848 new_event = Event() 849 850 new_event.set_type(event.get_type()) 851 new_event.set_description(event.get_description()) 852 new_event.set_gramps_id(event.get_gramps_id()) 853 new_event.set_handle(event.get_handle()) 854 new_event.set_date_object(event.get_date_object()) 855 new_event.set_marker(event.get_marker()) 856 857 copy_source_ref_list(db,event, new_event) 858 copy_notes(db,event, new_event) 859 copy_media_ref_list(db,event, new_event) 860 copy_attributes(db,event, new_event) 861 862 place_handle = event.get_place_handle() 863 place = db.get_place_from_handle(place_handle) 864 if place and not place.get_privacy(): 865 new_event.set_place_handle(place_handle) 866 867 return new_event
868
869 -def sanitize_family(db,family):
870 """ 871 Create a new Family instance based off the passed Family 872 instance. The returned instance has all private records 873 removed from it. 874 875 @param db: GRAMPS database to which the Person object belongs 876 @type db: GrampsDbBase 877 @param family: source Family object that will be copied with 878 privacy records removed 879 @type family: Family 880 @returns: 'cleansed' Family object 881 @rtype: Family 882 """ 883 new_family = Family() 884 885 new_family.set_gramps_id(family.get_gramps_id()) 886 new_family.set_handle(family.get_handle()) 887 new_family.set_marker(family.get_marker()) 888 new_family.set_relationship(family.get_relationship()) 889 890 # Copy the father handle. 891 father_handle = family.get_father_handle() 892 if father_handle: 893 father = db.get_person_from_handle(father_handle) 894 if not father.get_privacy(): 895 new_family.set_father_handle(father_handle) 896 897 # Copy the mother handle. 898 mother_handle = family.get_mother_handle() 899 if mother_handle: 900 mother = db.get_person_from_handle(mother_handle) 901 if not mother.get_privacy(): 902 new_family.set_mother_handle(mother_handle) 903 904 # Copy child references. 905 for child_ref in family.get_child_ref_list(): 906 if child_ref.get_privacy(): 907 continue 908 child_handle = child_ref.get_reference_handle() 909 child = db.get_person_from_handle(child_handle) 910 if child.get_privacy(): 911 continue 912 # Copy this reference 913 new_ref = ChildRef() 914 new_ref.set_reference_handle(child_ref.get_reference_handle()) 915 new_ref.set_father_relation(child_ref.get_father_relation()) 916 new_ref.set_mother_relation(child_ref.get_mother_relation()) 917 copy_notes(db,child_ref, new_ref) 918 copy_source_ref_list(db,child_ref, new_ref) 919 new_family.add_child_ref(new_ref) 920 921 # Copy event ref list. 922 for event_ref in family.get_event_ref_list(): 923 if event_ref and not event_ref.get_privacy(): 924 event = db.get_event_from_handle(event_ref.ref) 925 if not event.get_privacy(): 926 new_family.add_event_ref(sanitize_event_ref(db,event_ref)) 927 928 copy_source_ref_list(db,family, new_family) 929 copy_notes(db,family, new_family) 930 copy_media_ref_list(db,family, new_family) 931 copy_attributes(db,family, new_family) 932 copy_lds_ords(db,family, new_family) 933 934 return new_family
935
936 -def sanitize_repository(db,repository):
937 """ 938 Create a new Repository instance based off the passed Repository 939 instance. The returned instance has all private records 940 removed from it. 941 942 @param db: GRAMPS database to which the Person object belongs 943 @type db: GrampsDbBase 944 @param repository: source Repsitory object that will be copied with 945 privacy records removed 946 @type repository: Repository 947 @returns: 'cleansed' Repository object 948 @rtype: Repository 949 """ 950 new_repository = Repository() 951 952 new_repository.set_type(repository.get_type()) 953 new_repository.set_name(repository.get_name()) 954 new_repository.set_gramps_id(repository.get_gramps_id()) 955 new_repository.set_handle(repository.get_handle()) 956 new_repository.set_marker(repository.get_marker()) 957 958 copy_notes(db,repository, new_repository) 959 copy_addresses(db,repository, new_repository) 960 copy_urls(db,repository, new_repository) 961 962 return new_repository
963