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 data marked private.
25 """
26
27
28
29
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
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
48
58
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
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
88
98
108
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
128
138
148
158
168
178
188
198
208
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
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
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
258
270
282
294
306
308 """returns the Researcher instance, providing information about
309 the owner of the database"""
310 return self.db.get_researcher()
311
318
326
336
346
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
366
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
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
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
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
408 """
409 Find all objects that hold a reference to the object handle.
410 Returns an interator over alist of (class_name, handle) tuples.
411
412 @param handle: handle of the object to search for.
413 @type handle: database handle
414 @param include_classes: list of class names to include in the results.
415 Default: None means include all classes.
416 @type include_classes: list of class names
417
418 This default implementation does a sequencial scan through all
419 the primary object databases and is very slow. Backends can
420 override this method to provide much faster implementations that
421 make use of additional capabilities of the backend.
422
423 Note that this is a generator function, it returns a iterator for
424 use in loops. If you want a list of the results use:
425
426 > result_list = [i for i in find_backlink_handles(handle)]
427 """
428
429 raise NotImplementedError
430
431
432
433
434 handle_itr = self.db.find_backlink_handles(handle, include_classes)
435 for (class_name, handle) in handle_itr:
436 if class_name == 'Person':
437 obj = self.db.get_person_from_handle(handle)
438 elif class_name == 'Family':
439 obj = self.db.get_family_from_handle(handle)
440 elif class_name == 'Event':
441 obj = self.db.get_event_from_handle(handle)
442 elif class_name == 'Source':
443 obj = self.db.get_source_from_handle(handle)
444 elif class_name == 'Place':
445 obj = self.db.get_place_from_handle(handle)
446 elif class_name == 'MediaObject':
447 obj = self.db.get_object_from_handle(handle)
448 elif class_name == 'Note':
449 obj = self.db.get_note_from_handle(handle)
450 elif class_name == 'Repository':
451 obj = self.db.get_repository_from_handle(handle)
452 else:
453 raise NotImplementedError
454
455 if not obj.get_privacy():
456 yield (class_name, handle)
457 return
458
459
479
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
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
539
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
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
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
623
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
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
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
669 name = person.get_primary_name()
670 if name.get_privacy() or person.get_privacy():
671
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
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
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
701 new_person.set_marker(person.get_marker())
702
703
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
711
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
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
771
801
833
868
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
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
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
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
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
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
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