Update src/gen/proxy/* for citations

svn: r18485
This commit is contained in:
Tim G L Lyons
2011-11-22 14:59:18 +00:00
parent 9f29350da4
commit 61e6a0a1c0
5 changed files with 219 additions and 84 deletions

View File

@@ -4,6 +4,7 @@
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2008 Robert Cheramy <robert@cheramy.net> # Copyright (C) 2008 Robert Cheramy <robert@cheramy.net>
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -51,7 +52,7 @@ class FilterProxyDb(ProxyDbBase):
def __init__(self, db, person_filter=None, event_filter=None, def __init__(self, db, person_filter=None, event_filter=None,
note_filter=None): note_filter=None):
""" """
Create a new PrivateProxyDb instance. Create a new FilterProxyDb instance.
""" """
ProxyDbBase.__init__(self, db) ProxyDbBase.__init__(self, db)
self.person_filter = person_filter self.person_filter = person_filter
@@ -143,6 +144,17 @@ class FilterProxyDb(ProxyDbBase):
self.sanitize_notebase(source) self.sanitize_notebase(source)
return source return source
def get_citation_from_handle(self, handle):
"""
Finds a Citation in the database from the passed gramps' ID.
If no such Citation exists, None is returned.
"""
citation = self.db.get_citation_from_handle(handle)
# Filter notes out
self.sanitize_notebase(citation)
return citation
def get_object_from_handle(self, handle): def get_object_from_handle(self, handle):
""" """
Finds a MediaObject in the database from the passed GRAMPS' handle. Finds a MediaObject in the database from the passed GRAMPS' handle.
@@ -151,7 +163,6 @@ class FilterProxyDb(ProxyDbBase):
media = self.db.get_object_from_handle(handle) media = self.db.get_object_from_handle(handle)
# Filter notes out # Filter notes out
self.sanitize_notebase(media) self.sanitize_notebase(media)
self.sanitize_sourcebase(media)
return media return media
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
@@ -162,7 +173,6 @@ class FilterProxyDb(ProxyDbBase):
place = self.db.get_place_from_handle(handle) place = self.db.get_place_from_handle(handle)
# Filter notes out # Filter notes out
self.sanitize_notebase(place) self.sanitize_notebase(place)
self.sanitize_sourcebase(place)
return place return place
def get_event_from_handle(self, handle): def get_event_from_handle(self, handle):
@@ -174,7 +184,6 @@ class FilterProxyDb(ProxyDbBase):
event = self.db.get_event_from_handle(handle) event = self.db.get_event_from_handle(handle)
# Filter all notes out # Filter all notes out
self.sanitize_notebase(event) self.sanitize_notebase(event)
self.sanitize_sourcebase(event)
return event return event
else: else:
return None return None
@@ -204,7 +213,6 @@ class FilterProxyDb(ProxyDbBase):
# Filter notes out # Filter notes out
self.sanitize_notebase(family) self.sanitize_notebase(family)
self.sanitize_sourcebase(family)
return family return family
else: else:
return None return None
@@ -275,6 +283,15 @@ class FilterProxyDb(ProxyDbBase):
if source: if source:
return self.get_source_from_handle(source.get_handle()) return self.get_source_from_handle(source.get_handle())
def get_citation_from_gramps_id(self, val):
"""
Finds a Citation in the database from the passed gramps' ID.
If no such Citation exists, None is returned.
"""
citation = self.db.get_citation_from_gramps_id(val)
if citation:
return self.get_citation_from_handle(citation.get_handle())
def get_object_from_gramps_id(self, val): def get_object_from_gramps_id(self, val):
""" """
Finds a MediaObject in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed gramps' ID.
@@ -458,23 +475,11 @@ class FilterProxyDb(ProxyDbBase):
new_note_list = [ note for note in note_list if note in self.nlist ] new_note_list = [ note for note in note_list if note in self.nlist ]
notebase.set_note_list(new_note_list) notebase.set_note_list(new_note_list)
def sanitize_sourcebase(self, sourcebase):
"""
Filter notes out of an SourceBase object
@param event: SourceBase object to clean
@type event: SourceBase
"""
if sourcebase:
sources = sourcebase.get_source_references()
for source in sources:
self.sanitize_notebase(source)
def sanitize_addressbase(self, addressbase): def sanitize_addressbase(self, addressbase):
if addressbase: if addressbase:
addresses = addressbase.get_address_list() addresses = addressbase.get_address_list()
for address in addresses: for address in addresses:
self.sanitize_notebase(address) self.sanitize_notebase(address)
self.sanitize_sourcebase(address)
def sanitize_person(self, person): def sanitize_person(self, person):
""" """
@@ -485,16 +490,13 @@ class FilterProxyDb(ProxyDbBase):
if person: if person:
# Filter note references # Filter note references
self.sanitize_notebase(person) self.sanitize_notebase(person)
self.sanitize_sourcebase(person)
self.sanitize_addressbase(person) self.sanitize_addressbase(person)
name = person.get_primary_name() name = person.get_primary_name()
self.sanitize_notebase(name) self.sanitize_notebase(name)
self.sanitize_sourcebase(name)
altnames = person.get_alternate_names() altnames = person.get_alternate_names()
for name in altnames: for name in altnames:
self.sanitize_notebase(name) self.sanitize_notebase(name)
self.sanitize_sourcebase(name)
self.sanitize_addressbase(person) self.sanitize_addressbase(person)

View File

@@ -3,6 +3,7 @@
# #
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2010 Nick Hall # Copyright (C) 2010 Nick Hall
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -31,15 +32,17 @@ Proxy class for the GRAMPS databases. Filter out all data marked private.
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import logging
LOG = logging.getLogger(".citation")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS libraries # GRAMPS libraries
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.lib import (MediaRef, SourceRef, Attribute, Address, EventRef, from gen.lib import (MediaRef, Attribute, Address, EventRef,
Person, Name, Source, RepoRef, MediaObject, Place, Event, Person, Name, Source, RepoRef, MediaObject, Place, Event,
Family, ChildRef, Repository, LdsOrd, Surname) Family, ChildRef, Repository, LdsOrd, Surname, Citation)
from proxybase import ProxyDbBase from proxybase import ProxyDbBase
class PrivateProxyDb(ProxyDbBase): class PrivateProxyDb(ProxyDbBase):
@@ -74,6 +77,16 @@ class PrivateProxyDb(ProxyDbBase):
return sanitize_source(self.db, source) return sanitize_source(self.db, source)
return None return None
def get_citation_from_handle(self, handle):
"""
Finds a Citation in the database from the passed gramps' ID.
If no such Citation exists, None is returned.
"""
citation = self.db.get_citation_from_handle(handle)
if citation and not citation.get_privacy():
return sanitize_citation(self.db, citation)
return None
def get_object_from_handle(self, handle): def get_object_from_handle(self, handle):
""" """
Finds an Object in the database from the passed gramps' ID. Finds an Object in the database from the passed gramps' ID.
@@ -184,6 +197,16 @@ class PrivateProxyDb(ProxyDbBase):
return sanitize_source(self.db, source) return sanitize_source(self.db, source)
return None return None
def get_citation_from_gramps_id(self, val):
"""
Finds a Citation in the database from the passed gramps' ID.
If no such Citation exists, None is returned.
"""
citation = self.db.get_citation_from_gramps_id(val)
if citation and not citation.get_privacy():
return sanitize_citation(self.db, citation)
return None
def get_object_from_gramps_id(self, val): def get_object_from_gramps_id(self, val):
""" """
Finds a MediaObject in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed gramps' ID.
@@ -244,6 +267,13 @@ class PrivateProxyDb(ProxyDbBase):
obj = self.get_unfiltered_source(handle) obj = self.get_unfiltered_source(handle)
return obj and not obj.get_privacy() return obj and not obj.get_privacy()
def include_citation(self, handle):
"""
Predicate returning True if object is to be included, else False
"""
obj = self.get_unfiltered_citation(handle)
return obj and not obj.get_privacy()
def include_place(self, handle): def include_place(self, handle):
""" """
Predicate returning True if object is to be included, else False Predicate returning True if object is to be included, else False
@@ -314,6 +344,15 @@ class PrivateProxyDb(ProxyDbBase):
return True return True
return False return False
def has_citation_handle(self, handle):
"""
returns True if the handle exists in the current Citation database.
"""
citation = self.db.get_citation_from_handle(handle)
if citation and not citation.get_privacy():
return True
return False
def has_place_handle(self, handle): def has_place_handle(self, handle):
""" """
returns True if the handle exists in the current Place database. returns True if the handle exists in the current Place database.
@@ -382,7 +421,7 @@ class PrivateProxyDb(ProxyDbBase):
""" """
# This isn't done yet because it doesn't check if references are # This isn't done yet because it doesn't check if references are
# private (like a SourceRef or MediaRef). It only checks if the # private (like a MediaRef). It only checks if the
# referenced object is private. # referenced object is private.
objects = { objects = {
@@ -390,6 +429,7 @@ class PrivateProxyDb(ProxyDbBase):
'Family' : self.db.get_family_from_handle, 'Family' : self.db.get_family_from_handle,
'Event' : self.db.get_event_from_handle, 'Event' : self.db.get_event_from_handle,
'Source' : self.db.get_source_from_handle, 'Source' : self.db.get_source_from_handle,
'Citation' : self.db.get_citation_from_handle,
'Place' : self.db.get_place_from_handle, 'Place' : self.db.get_place_from_handle,
'MediaObject' : self.db.get_object_from_handle, 'MediaObject' : self.db.get_object_from_handle,
'Note' : self.db.get_note_from_handle, 'Note' : self.db.get_note_from_handle,
@@ -426,25 +466,27 @@ def copy_media_ref_list(db, original_obj, clean_obj):
if media_object and not media_object.get_privacy(): if media_object and not media_object.get_privacy():
clean_obj.add_media_reference(sanitize_media_ref(db, media_ref)) clean_obj.add_media_reference(sanitize_media_ref(db, media_ref))
def copy_source_ref_list(db, original_obj, clean_obj): def copy_citation_ref_list(db, original_obj, clean_obj):
""" """
Copies source references from one object to another - excluding private Copies citation references from one object to another - excluding references
references and references to private objects. to private citations, and references to citations that refer to private
sources.
@param db: GRAMPS database to which the references belongs @param db: GRAMPS database to which the references belongs
@type db: DbBase @type db: DbBase
@param original_obj: Object that may have private references @param original_obj: Object that may have private references
@type original_obj: SourceBase @type original_obj: CitationBase
@param clean_obj: Object that will have only non-private references @param clean_obj: Object that will have only non-private references
@type original_obj: SourceBase @type original_obj: CitationBase
@returns: Nothing @returns: Nothing
""" """
for ref in original_obj.get_source_references(): for citation_handle in original_obj.get_citation_list():
if ref and not ref.get_privacy(): citation = db.get_citation_from_handle(citation_handle)
handle = ref.get_reference_handle() if citation and not citation.get_privacy():
handle = citation.get_reference_handle()
source = db.get_source_from_handle(handle) source = db.get_source_from_handle(handle)
if source and not source.get_privacy(): if source and not source.get_privacy():
clean_obj.add_source_reference(sanitize_source_ref(db, ref)) clean_obj.add_citation(citation_handle)
def copy_notes(db, original_obj, clean_obj): def copy_notes(db, original_obj, clean_obj):
""" """
@@ -504,7 +546,7 @@ def copy_attributes(db, original_obj, clean_obj):
new_attribute.set_type(attribute.get_type()) new_attribute.set_type(attribute.get_type())
new_attribute.set_value(attribute.get_value()) new_attribute.set_value(attribute.get_value())
copy_notes(db, attribute, new_attribute) copy_notes(db, attribute, new_attribute)
copy_source_ref_list(db, attribute, new_attribute) copy_citation_ref_list(db, attribute, new_attribute)
clean_obj.add_attribute(new_attribute) clean_obj.add_attribute(new_attribute)
def copy_urls(db, original_obj, clean_obj): def copy_urls(db, original_obj, clean_obj):
@@ -589,7 +631,7 @@ def sanitize_lds_ord(db, lds_ord):
if place and not place.get_privacy(): if place and not place.get_privacy():
new_lds_ord.set_place_handle(place_handle) new_lds_ord.set_place_handle(place_handle)
copy_source_ref_list(db, lds_ord, new_lds_ord) copy_citation_ref_list(db, lds_ord, new_lds_ord)
copy_notes(db, lds_ord, new_lds_ord) copy_notes(db, lds_ord, new_lds_ord)
return new_lds_ord return new_lds_ord
@@ -620,7 +662,7 @@ def sanitize_address(db, address):
new_address.set_phone(address.get_phone()) new_address.set_phone(address.get_phone())
new_address.set_date_object(address.get_date_object()) new_address.set_date_object(address.get_date_object())
copy_source_ref_list(db, address, new_address) copy_citation_ref_list(db, address, new_address)
copy_notes(db, address, new_address) copy_notes(db, address, new_address)
return new_address return new_address
@@ -653,7 +695,7 @@ def sanitize_name(db, name):
new_name.set_date_object(name.get_date_object()) new_name.set_date_object(name.get_date_object())
new_name.set_surname_list(name.get_surname_list()) new_name.set_surname_list(name.get_surname_list())
copy_source_ref_list(db, name, new_name) copy_citation_ref_list(db, name, new_name)
copy_notes(db, name, new_name) copy_notes(db, name, new_name)
return new_name return new_name
@@ -678,32 +720,37 @@ def sanitize_media_ref(db, media_ref):
new_ref.set_reference_handle(media_ref.get_reference_handle()) new_ref.set_reference_handle(media_ref.get_reference_handle())
copy_notes(db, media_ref, new_ref) copy_notes(db, media_ref, new_ref)
copy_attributes(db, media_ref, new_ref) copy_attributes(db, media_ref, new_ref)
copy_source_ref_list(db, media_ref, new_ref) copy_citation_ref_list(db, media_ref, new_ref)
return new_ref return new_ref
def sanitize_source_ref(db, source_ref): def sanitize_citation(db, citation):
""" """
Create a new SourceRef instance based off the passed SourceRef Create a new Citation instance based off the passed Citation
instance. The returned instance has all private records instance. The returned instance has all private records
removed from it. removed from it.
@param db: GRAMPS database to which the Person object belongs @param db: GRAMPS database to which the Person object belongs
@type db: DbBase @type db: DbBase
@param source_ref: source SourceRef object that will be copied with @param citation: source Citation object that will be copied with
privacy records removed privacy records removed
@type source_ref: SourceRef @type citation: Citation
@returns: 'cleansed' SourceRef object @returns: 'cleansed' Citation object
@rtype: SourceRef @rtype: Citation
""" """
new_ref = SourceRef() new_citation = Citation()
new_ref.set_date_object(source_ref.get_date_object()) new_citation.set_date_object(citation.get_date_object())
new_ref.set_page(source_ref.get_page()) new_citation.set_page(citation.get_page())
new_ref.set_confidence_level(source_ref.get_confidence_level()) new_citation.set_confidence_level(citation.get_confidence_level())
new_ref.set_reference_handle(source_ref.get_reference_handle()) new_citation.set_reference_handle(citation.get_reference_handle())
copy_notes(db, source_ref, new_ref) new_citation.set_data_map(citation.get_data_map())
new_citation.set_gramps_id(citation.get_gramps_id())
new_citation.set_handle(citation.get_handle())
new_citation.set_change_time(citation.get_change_time())
copy_notes(db, citation, new_citation)
copy_media_ref_list(db, citation, new_citation)
return new_ref return new_citation
def sanitize_event_ref(db, event_ref): def sanitize_event_ref(db, event_ref):
""" """
@@ -812,7 +859,7 @@ def sanitize_person(db, person):
copy_addresses(db, person, new_person) copy_addresses(db, person, new_person)
copy_attributes(db, person, new_person) copy_attributes(db, person, new_person)
copy_source_ref_list(db, person, new_person) copy_citation_ref_list(db, person, new_person)
copy_urls(db, person, new_person) copy_urls(db, person, new_person)
copy_media_ref_list(db, person, new_person) copy_media_ref_list(db, person, new_person)
copy_lds_ords(db, person, new_person) copy_lds_ords(db, person, new_person)
@@ -883,7 +930,7 @@ def sanitize_media(db, media):
new_media.set_date_object(media.get_date_object()) new_media.set_date_object(media.get_date_object())
new_media.set_tag_list(media.get_tag_list()) new_media.set_tag_list(media.get_tag_list())
copy_source_ref_list(db, media, new_media) copy_citation_ref_list(db, media, new_media)
copy_attributes(db, media, new_media) copy_attributes(db, media, new_media)
copy_notes(db, media, new_media) copy_notes(db, media, new_media)
@@ -914,7 +961,7 @@ def sanitize_place(db, place):
new_place.set_main_location(place.get_main_location()) new_place.set_main_location(place.get_main_location())
new_place.set_alternate_locations(place.get_alternate_locations()) new_place.set_alternate_locations(place.get_alternate_locations())
copy_source_ref_list(db, place, new_place) copy_citation_ref_list(db, place, new_place)
copy_notes(db, place, new_place) copy_notes(db, place, new_place)
copy_media_ref_list(db, place, new_place) copy_media_ref_list(db, place, new_place)
copy_urls(db, place, new_place) copy_urls(db, place, new_place)
@@ -944,7 +991,7 @@ def sanitize_event(db, event):
new_event.set_date_object(event.get_date_object()) new_event.set_date_object(event.get_date_object())
new_event.set_change_time(event.get_change_time()) new_event.set_change_time(event.get_change_time())
copy_source_ref_list(db, event, new_event) copy_citation_ref_list(db, event, new_event)
copy_notes(db, event, new_event) copy_notes(db, event, new_event)
copy_media_ref_list(db, event, new_event) copy_media_ref_list(db, event, new_event)
copy_attributes(db, event, new_event) copy_attributes(db, event, new_event)
@@ -1006,7 +1053,7 @@ def sanitize_family(db, family):
new_ref.set_father_relation(child_ref.get_father_relation()) new_ref.set_father_relation(child_ref.get_father_relation())
new_ref.set_mother_relation(child_ref.get_mother_relation()) new_ref.set_mother_relation(child_ref.get_mother_relation())
copy_notes(db, child_ref, new_ref) copy_notes(db, child_ref, new_ref)
copy_source_ref_list(db, child_ref, new_ref) copy_citation_ref_list(db, child_ref, new_ref)
new_family.add_child_ref(new_ref) new_family.add_child_ref(new_ref)
# Copy event ref list. # Copy event ref list.
@@ -1016,7 +1063,7 @@ def sanitize_family(db, family):
if event and not event.get_privacy(): if event and not event.get_privacy():
new_family.add_event_ref(sanitize_event_ref(db, event_ref)) new_family.add_event_ref(sanitize_event_ref(db, event_ref))
copy_source_ref_list(db, family, new_family) copy_citation_ref_list(db, family, new_family)
copy_notes(db, family, new_family) copy_notes(db, family, new_family)
copy_media_ref_list(db, family, new_family) copy_media_ref_list(db, family, new_family)
copy_attributes(db, family, new_family) copy_attributes(db, family, new_family)

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -52,7 +53,7 @@ class ProxyDbBase(DbReadBase):
def __init__(self, db): def __init__(self, db):
""" """
Create a new PrivateProxyDb instance. Create a new ProxyDb instance.
""" """
self.db = self.basedb = db self.db = self.basedb = db
while isinstance(self.basedb, ProxyDbBase): while isinstance(self.basedb, ProxyDbBase):
@@ -95,6 +96,7 @@ class ProxyDbBase(DbReadBase):
include_family = \ include_family = \
include_event = \ include_event = \
include_source = \ include_source = \
include_citation = \
include_place = \ include_place = \
include_media_object = \ include_media_object = \
include_repository = \ include_repository = \
@@ -142,6 +144,16 @@ class ProxyDbBase(DbReadBase):
else: else:
return [] return []
def get_citation_handles(self, sort_handles=False):
"""
Return a list of database handles, one handle for each Citation in
the database.
"""
if self.db.is_open:
return list(self.iter_citation_handles())
else:
return []
def get_place_handles(self, sort_handles=False): def get_place_handles(self, sort_handles=False):
""" """
Return a list of database handles, one handle for each Place in Return a list of database handles, one handle for each Place in
@@ -228,6 +240,13 @@ class ProxyDbBase(DbReadBase):
""" """
return ifilter(self.include_source, self.db.iter_source_handles()) return ifilter(self.include_source, self.db.iter_source_handles())
def iter_citation_handles(self):
"""
Return an iterator over database handles, one handle for each Citation
in the database.
"""
return ifilter(self.include_citation, self.db.iter_citation_handles())
def iter_place_handles(self): def iter_place_handles(self):
""" """
Return an iterator over database handles, one handle for each Place in Return an iterator over database handles, one handle for each Place in
@@ -299,6 +318,12 @@ class ProxyDbBase(DbReadBase):
""" """
return self.__iter_object(self.include_source, self.db.iter_sources) return self.__iter_object(self.include_source, self.db.iter_sources)
def iter_citations(self):
"""
Return an iterator over Citation objects in the database
"""
return self.__iter_object(self.include_citation, self.db.iter_citations)
def iter_media_objects(self): def iter_media_objects(self):
""" """
Return an iterator over Media objects in the database Return an iterator over Media objects in the database
@@ -390,6 +415,14 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_source, return self.gfilter(self.include_source,
self.db.get_source_from_handle(handle)) self.db.get_source_from_handle(handle))
def get_citation_from_handle(self, handle):
"""
Finds a Citation in the database from the passed gramps handle.
If no such Citation exists, None is returned.
"""
return self.gfilter(self.include_citation,
self.db.get_citation_from_handle(handle))
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
""" """
Finds a Place in the database from the passed gramps handle. Finds a Place in the database from the passed gramps handle.
@@ -470,6 +503,14 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_source, return self.gfilter(self.include_source,
self.db.get_source_from_gramps_id(val)) self.db.get_source_from_gramps_id(val))
def get_citation_from_gramps_id(self, val):
"""
Finds a Citation in the database from the passed gramps' ID.
If no such Citation exists, None is returned.
"""
return self.gfilter(self.include_citation,
self.db.get_citation_from_gramps_id(val))
def get_object_from_gramps_id(self, val): def get_object_from_gramps_id(self, val):
""" """
Finds a MediaObject in the database from the passed gramps' ID. Finds a MediaObject in the database from the passed gramps' ID.
@@ -550,6 +591,12 @@ class ProxyDbBase(DbReadBase):
""" """
return self.db.get_number_of_sources() return self.db.get_number_of_sources()
def get_number_of_citations(self):
"""
Return the number of Citations currently in the database.
"""
return self.db.get_number_of_citations()
def get_number_of_media_objects(self): def get_number_of_media_objects(self):
""" """
Return the number of media objects currently in the database. Return the number of media objects currently in the database.
@@ -666,6 +713,9 @@ class ProxyDbBase(DbReadBase):
def get_raw_source_data(self, handle): def get_raw_source_data(self, handle):
return self.db.get_raw_source_data(handle) return self.db.get_raw_source_data(handle)
def get_raw_citation_data(self, handle):
return self.db.get_raw_citation_data(handle)
def get_raw_repository_data(self, handle): def get_raw_repository_data(self, handle):
return self.db.get_raw_repository_data(handle) return self.db.get_raw_repository_data(handle)
@@ -703,6 +753,13 @@ class ProxyDbBase(DbReadBase):
return self.gfilter(self.include_source, return self.gfilter(self.include_source,
self.db.get_source_from_handle(handle)) is not None self.db.get_source_from_handle(handle)) is not None
def has_citation_handle(self, handle):
"""
returns True if the handle exists in the current Citation database.
"""
return self.gfilter(self.include_citation,
self.db.get_citation_from_handle(handle)) is not None
def has_place_handle(self, handle): def has_place_handle(self, handle):
""" """
returns True if the handle exists in the current Place database. returns True if the handle exists in the current Place database.

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2008 Gary Burton # Copyright (C) 2008 Gary Burton
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -45,6 +46,7 @@ class ReferencedProxyDb(ProxyDbBase):
ProxyDbBase.__init__(self, dbase) ProxyDbBase.__init__(self, dbase)
self.unreferenced_events = set() self.unreferenced_events = set()
self.unreferenced_places = set() self.unreferenced_places = set()
self.unreferenced_citations = set()
self.unreferenced_sources = set() self.unreferenced_sources = set()
self.unreferenced_repositories = set() self.unreferenced_repositories = set()
self.unreferenced_media_objects = set() self.unreferenced_media_objects = set()
@@ -72,6 +74,12 @@ class ReferencedProxyDb(ProxyDbBase):
""" """
return handle not in self.unreferenced_events return handle not in self.unreferenced_events
def include_citation(self, handle):
"""
Filter for citations
"""
return handle not in self.unreferenced_citations
def include_source(self, handle): def include_source(self, handle):
""" """
Filter for sources Filter for sources
@@ -126,6 +134,7 @@ class ReferencedProxyDb(ProxyDbBase):
unref = { unref = {
"Event" : self.unreferenced_events, "Event" : self.unreferenced_events,
"Place" : self.unreferenced_places, "Place" : self.unreferenced_places,
"Citation" : self.unreferenced_citations,
"Source" : self.unreferenced_sources, "Source" : self.unreferenced_sources,
"Repository" : self.unreferenced_repositories, "Repository" : self.unreferenced_repositories,
"MediaObject" : self.unreferenced_media_objects, "MediaObject" : self.unreferenced_media_objects,
@@ -156,6 +165,7 @@ class ReferencedProxyDb(ProxyDbBase):
unrefs = ( unrefs = (
(self.unreferenced_events, self.get_event_handles), (self.unreferenced_events, self.get_event_handles),
(self.unreferenced_places, self.get_place_handles), (self.unreferenced_places, self.get_place_handles),
(self.unreferenced_citations, self.get_citation_handles),
(self.unreferenced_sources, self.get_source_handles), (self.unreferenced_sources, self.get_source_handles),
(self.unreferenced_repositories, (self.unreferenced_repositories,
self.get_repository_handles), self.get_repository_handles),

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2010 Doug Blank <doug.blank@gmail.com> # Copyright (C) 2010 Doug Blank <doug.blank@gmail.com>
# Copyright (C) 2011 Tim G Lyons
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@@ -18,7 +19,6 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# gen/proxy/referencedbyselection.py
# $Id$ # $Id$
""" """
@@ -84,6 +84,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
"Event": set(), "Event": set(),
"Place": set(), "Place": set(),
"Source": set(), "Source": set(),
"Citation": set(),
"Repository": set(), "Repository": set(),
"MediaObject": set(), "MediaObject": set(),
"Note": set(), "Note": set(),
@@ -111,6 +112,10 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
obj = self.db.get_source_from_handle(handle) obj = self.db.get_source_from_handle(handle)
if obj: if obj:
self.process_source(obj) self.process_source(obj)
elif class_name == "Citation":
obj = self.db.get_citation_from_handle(handle)
if obj:
self.process_citation(obj)
elif class_name == "Repository": elif class_name == "Repository":
obj = self.db.get_repository_from_handle(handle) obj = self.db.get_repository_from_handle(handle)
if obj: if obj:
@@ -175,7 +180,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
self.process_addresses(person) self.process_addresses(person)
self.process_attributes(person) self.process_attributes(person)
self.process_source_ref_list(person) self.process_citation_ref_list(person)
self.process_urls(person) self.process_urls(person)
self.process_media_ref_list(person) self.process_media_ref_list(person)
self.process_lds_ords(person) self.process_lds_ords(person)
@@ -199,7 +204,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
continue continue
self.process_object("Person", child_ref.ref) self.process_object("Person", child_ref.ref)
self.process_notes(child_ref) self.process_notes(child_ref)
self.process_source_ref_list(child_ref) self.process_citation_ref_list(child_ref)
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
@@ -207,7 +212,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if event: if event:
self.process_event_ref(event_ref) self.process_event_ref(event_ref)
self.process_source_ref_list(family) self.process_citation_ref_list(family)
self.process_notes(family) self.process_notes(family)
self.process_media_ref_list(family) self.process_media_ref_list(family)
self.process_attributes(family) self.process_attributes(family)
@@ -221,7 +226,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if event is None or event.handle in self.referenced["Event"]: if event is None or event.handle in self.referenced["Event"]:
return return
self.referenced["Event"].add(event.handle) self.referenced["Event"].add(event.handle)
self.process_source_ref_list(event) self.process_citation_ref_list(event)
self.process_notes(event) self.process_notes(event)
self.process_media_ref_list(event) self.process_media_ref_list(event)
self.process_attributes(event) self.process_attributes(event)
@@ -239,7 +244,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if place is None or place.handle in self.referenced["Place"]: if place is None or place.handle in self.referenced["Place"]:
return return
self.referenced["Place"].add(place.handle) self.referenced["Place"].add(place.handle)
self.process_source_ref_list(place) self.process_citation_ref_list(place)
self.process_notes(place) self.process_notes(place)
self.process_media_ref_list(place) self.process_media_ref_list(place)
self.process_urls(place) self.process_urls(place)
@@ -262,6 +267,22 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
self.process_media_ref_list(source) self.process_media_ref_list(source)
self.process_notes(source) self.process_notes(source)
def process_citation(self, citation):
"""
Follow the citation object and find all of the primary objects
that it references.
"""
if citation is None or citation.handle in self.referenced["Citation"]:
return
self.referenced["Citation"].add(citation.handle)
source_handle = citation.get_reference_handle()
if source_handle:
source = self.db.get_source_from_handle(source_handle)
if source:
self.process_source(source)
self.process_media_ref_list(citation)
self.process_notes(citation)
def process_repository(self, repository): def process_repository(self, repository):
""" """
Follow the repository object and find all of the primary objects Follow the repository object and find all of the primary objects
@@ -282,7 +303,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if media is None or media.handle in self.referenced["MediaObject"]: if media is None or media.handle in self.referenced["MediaObject"]:
return return
self.referenced["MediaObject"].add(media.handle) self.referenced["MediaObject"].add(media.handle)
self.process_source_ref_list(media) self.process_citation_ref_list(media)
self.process_attributes(media) self.process_attributes(media)
self.process_notes(media) self.process_notes(media)
@@ -316,7 +337,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
def process_name(self, name): def process_name(self, name):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
self.process_source_ref_list(name) self.process_citation_ref_list(name)
self.process_notes(name) self.process_notes(name)
def process_addresses(self, original_obj): def process_addresses(self, original_obj):
@@ -327,7 +348,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
def process_address(self, address): def process_address(self, address):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
self.process_source_ref_list(address) self.process_citation_ref_list(address)
self.process_notes(address) self.process_notes(address)
def process_attributes(self, original_obj): def process_attributes(self, original_obj):
@@ -335,23 +356,15 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
for attribute in original_obj.get_attribute_list(): for attribute in original_obj.get_attribute_list():
if attribute: if attribute:
self.process_notes(attribute) self.process_notes(attribute)
self.process_source_ref_list(attribute) self.process_citation_ref_list(attribute)
def process_source_ref_list(self, original_obj): def process_citation_ref_list(self, original_obj):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
for ref in original_obj.get_source_references(): for handle in original_obj.get_citation_list():
if ref: if handle:
handle = ref.get_reference_handle() citation = self.db.get_citation_from_handle(handle)
source = self.db.get_source_from_handle(handle) if citation:
if source: self.process_citation(citation)
self.process_source_ref(ref)
def process_source_ref(self, srcref):
""" Find all of the primary objects referred to """
source = self.db.get_source_from_handle(srcref.ref)
if source:
self.process_source(source)
self.process_notes(srcref)
def process_urls(self, original_obj): def process_urls(self, original_obj):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
@@ -363,7 +376,7 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if media_ref: if media_ref:
self.process_notes(media_ref) self.process_notes(media_ref)
self.process_attributes(media_ref) self.process_attributes(media_ref)
self.process_source_ref_list(media_ref) self.process_citation_ref_list(media_ref)
handle = media_ref.get_reference_handle() handle = media_ref.get_reference_handle()
media_object = self.db.get_object_from_handle(handle) media_object = self.db.get_object_from_handle(handle)
if media_object: if media_object:
@@ -387,14 +400,14 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
if place: if place:
self.process_place(place) self.process_place(place)
self.process_source_ref_list(lds_ord) self.process_citation_ref_list(lds_ord)
self.process_notes(lds_ord) self.process_notes(lds_ord)
def process_associations(self, original_obj): def process_associations(self, original_obj):
""" Find all of the primary objects referred to """ """ Find all of the primary objects referred to """
for person_ref in original_obj.get_person_ref_list(): for person_ref in original_obj.get_person_ref_list():
if person_ref: if person_ref:
self.process_source_ref_list(person_ref) self.process_citation_ref_list(person_ref)
self.process_notes(person_ref) self.process_notes(person_ref)
person = self.db.get_person_from_handle(person_ref.ref) person = self.db.get_person_from_handle(person_ref.ref)
if person: if person:
@@ -446,6 +459,12 @@ class ReferencedBySelectionProxyDb(ProxyDbBase):
""" """
return handle in self.referenced["Source"] return handle in self.referenced["Source"]
def include_citation(self, handle):
"""
Filter for citations
"""
return handle in self.referenced["Citation"]
def include_repository(self, handle): def include_repository(self, handle):
""" """
Filter for repositories Filter for repositories