2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
* src/gen/db/base.py: allow not to create gramps_id on add * src/GrampsDbUtils/_ReadXML.py: on sourceref, don't create gramps_id * src/GrampsDb/_GrampsInMemDB.py: remove gid from memory map only if not None svn: r9119
This commit is contained in:
parent
96c5584960
commit
967ef1c163
@ -1,3 +1,8 @@
|
||||
2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
|
||||
* src/gen/db/base.py: allow not to create gramps_id on add
|
||||
* src/GrampsDbUtils/_ReadXML.py: on sourceref, don't create gramps_id
|
||||
* src/GrampsDb/_GrampsInMemDB.py: remove gid from memory map only if not None
|
||||
|
||||
2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
|
||||
* src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping
|
||||
* src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping
|
||||
|
@ -252,7 +252,7 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
old_data = db_map.get(obj.handle)
|
||||
if old_data:
|
||||
old_id = old_data[self.ID_INDEX]
|
||||
if obj.gramps_id != old_id:
|
||||
if old_id is not None and obj.gramps_id != old_id:
|
||||
del trans_map[old_id]
|
||||
trans_map[gid] = obj.handle
|
||||
return True
|
||||
|
@ -1265,7 +1265,9 @@ class GrampsParser(UpdateCallback):
|
||||
self.source_ref = gen.lib.SourceRef()
|
||||
try:
|
||||
handle = attrs["hlink"].replace('_', '')
|
||||
self.db.check_source_from_handle(handle, self.trans)
|
||||
#create source object to obtain handle, gid is set in start_source
|
||||
self.db.check_source_from_handle(handle, self.trans,
|
||||
set_gid = False)
|
||||
except KeyError:
|
||||
source = self.find_source_by_gramps_id(self.map_sid(attrs["ref"]))
|
||||
handle = source.handle
|
||||
|
@ -260,7 +260,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
self.repo_bookmarks = GrampsDbBookmarks()
|
||||
self.media_bookmarks = GrampsDbBookmarks()
|
||||
self.note_bookmarks = GrampsDbBookmarks()
|
||||
self._bm_changes = 0
|
||||
self._bm_changes = 0
|
||||
self.path = ""
|
||||
self.name_group = {}
|
||||
self.surname_list = []
|
||||
@ -816,12 +816,12 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
return obj
|
||||
|
||||
def __check_from_handle(self, handle, transaction, class_type, dmap,
|
||||
add_func):
|
||||
add_func, set_gid=True):
|
||||
handle = str(handle)
|
||||
if not dmap.has_key(handle):
|
||||
obj = class_type()
|
||||
obj.set_handle(handle)
|
||||
add_func(obj, transaction)
|
||||
add_func(obj, transaction, set_gid=set_gid)
|
||||
|
||||
def find_person_from_handle(self, handle, transaction):
|
||||
"""
|
||||
@ -895,14 +895,16 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
self.__check_from_handle(handle, transaction, Person,
|
||||
self.person_map, self.add_person)
|
||||
|
||||
def check_source_from_handle(self, handle, transaction):
|
||||
def check_source_from_handle(self, handle, transaction, set_gid=True):
|
||||
"""
|
||||
Checks whether a Source with the passed handle exists in the database.
|
||||
If no such Source exists, a new Source is added to the database.
|
||||
If set_gid then a new gramps_id is created, if not, None is used.
|
||||
"""
|
||||
self.__check_from_handle(handle, transaction, Source,
|
||||
self.source_map, self.add_source)
|
||||
|
||||
self.source_map, self.add_source,
|
||||
set_gid=set_gid)
|
||||
|
||||
def check_event_from_handle(self, handle, transaction):
|
||||
"""
|
||||
Checks whether an Event with the passed handle exists in the database.
|
||||
@ -1028,7 +1030,7 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
raise NotImplementedError
|
||||
|
||||
def __add_object(self, obj, transaction, find_next_func, commit_func):
|
||||
if not obj.gramps_id:
|
||||
if find_next_func and not obj.gramps_id:
|
||||
obj.gramps_id = find_next_func()
|
||||
if not obj.handle:
|
||||
obj.handle = self.create_id()
|
||||
@ -1037,41 +1039,65 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
self.genderStats.count_person (obj)
|
||||
return obj.handle
|
||||
|
||||
def add_person(self, person, transaction):
|
||||
def add_person(self, person, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Person to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(person, transaction,
|
||||
self.find_next_person_gramps_id,
|
||||
self.commit_person)
|
||||
if set_gid:
|
||||
return self.__add_object(person, transaction,
|
||||
self.find_next_person_gramps_id,
|
||||
self.commit_person)
|
||||
else:
|
||||
return self.__add_object(person, transaction,
|
||||
None,
|
||||
self.commit_person)
|
||||
|
||||
def add_family(self, family, transaction):
|
||||
def add_family(self, family, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Family to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(family, transaction,
|
||||
self.find_next_family_gramps_id,
|
||||
self.commit_family)
|
||||
if set_gid:
|
||||
return self.__add_object(family, transaction,
|
||||
self.find_next_family_gramps_id,
|
||||
self.commit_family)
|
||||
else:
|
||||
return self.__add_object(family, transaction,
|
||||
None,
|
||||
self.commit_family)
|
||||
|
||||
def add_source(self, source, transaction):
|
||||
def add_source(self, source, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Source to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(source, transaction,
|
||||
self.find_next_source_gramps_id,
|
||||
if set_gid:
|
||||
return self.__add_object(source, transaction,
|
||||
self.find_next_source_gramps_id,
|
||||
self.commit_source)
|
||||
else :
|
||||
return self.__add_object(source, transaction,
|
||||
None,
|
||||
self.commit_source)
|
||||
|
||||
def add_event(self, event, transaction):
|
||||
def add_event(self, event, transaction, set_gid=True):
|
||||
"""
|
||||
Adds an Event to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(event, transaction,
|
||||
self.find_next_event_gramps_id,
|
||||
self.commit_event)
|
||||
if set_gid:
|
||||
return self.__add_object(event, transaction,
|
||||
self.find_next_event_gramps_id,
|
||||
self.commit_event)
|
||||
else:
|
||||
return self.__add_object(event, transaction,
|
||||
None,
|
||||
self.commit_event)
|
||||
|
||||
def add_person_event(self, event, transaction):
|
||||
"""
|
||||
@ -1091,41 +1117,65 @@ class GrampsDbBase(GrampsDBCallback):
|
||||
self.family_event_names.add(str(event.type))
|
||||
return self.add_event(event, transaction)
|
||||
|
||||
def add_place(self, place, transaction):
|
||||
def add_place(self, place, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Place to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(place, transaction,
|
||||
self.find_next_place_gramps_id,
|
||||
self.commit_place)
|
||||
if set_gid:
|
||||
return self.__add_object(place, transaction,
|
||||
self.find_next_place_gramps_id,
|
||||
self.commit_place)
|
||||
else:
|
||||
return self.__add_object(place, transaction,
|
||||
None,
|
||||
self.commit_place)
|
||||
|
||||
def add_object(self, obj, transaction):
|
||||
def add_object(self, obj, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a MediaObject to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_object_gramps_id,
|
||||
self.commit_media_object)
|
||||
if set_gid:
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_object_gramps_id,
|
||||
self.commit_media_object)
|
||||
else:
|
||||
return self.__add_object(obj, transaction,
|
||||
None,
|
||||
self.commit_media_object)
|
||||
|
||||
def add_repository(self, obj, transaction):
|
||||
def add_repository(self, obj, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Repository to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_repository_gramps_id,
|
||||
self.commit_repository)
|
||||
if set_gid:
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_repository_gramps_id,
|
||||
self.commit_repository)
|
||||
else:
|
||||
return self.__add_object(obj, transaction,
|
||||
None,
|
||||
self.commit_repository)
|
||||
|
||||
def add_note(self, obj, transaction):
|
||||
def add_note(self, obj, transaction, set_gid=True):
|
||||
"""
|
||||
Adds a Note to the database, assigning internal IDs if they have
|
||||
not already been defined.
|
||||
If not set_gid, then gramps_id is not set
|
||||
"""
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_note_gramps_id,
|
||||
self.commit_note)
|
||||
if set_gid:
|
||||
return self.__add_object(obj, transaction,
|
||||
self.find_next_note_gramps_id,
|
||||
self.commit_note)
|
||||
else:
|
||||
return self.__add_object(obj, transaction,
|
||||
None,
|
||||
self.commit_note)
|
||||
|
||||
def get_name_group_mapping(self, name):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user