Fixed the place and family references on import

svn: r1501
This commit is contained in:
Don Allingham 2003-05-07 03:36:28 +00:00
parent 5232d9066d
commit 1298a6d04d
2 changed files with 44 additions and 12 deletions

View File

@ -873,6 +873,23 @@ class GrampsImportParser(GrampsParser):
self.func_map["placeobj"] = (self.start_placeobj,self.stop_placeobj) self.func_map["placeobj"] = (self.start_placeobj,self.stop_placeobj)
self.func_map["source"] = (self.start_source, self.stop_source) self.func_map["source"] = (self.start_source, self.stop_source)
self.func_map["sourceref"]= (self.start_sourceref, self.stop_sourceref) self.func_map["sourceref"]= (self.start_sourceref, self.stop_sourceref)
self.func_map["childof"] = (self.start_childof,None)
self.func_map["parentin"] = (self.start_parentin,None)
def start_childof(self,attrs):
family = self.db.findFamilyNoConflict(attrs["ref"],self.fmap)
if attrs.has_key("mrel"):
mrel = attrs["mrel"]
else:
mrel = "Birth"
if attrs.has_key("frel"):
frel = attrs["frel"]
else:
frel = "Birth"
self.person.AltFamilyList.append((family,mrel,frel))
def start_parentin(self,attrs):
self.person.FamilyList.append(self.db.findFamilyNoConflict(attrs["ref"],self.fmap))
def start_bmark(self,attrs): def start_bmark(self,attrs):
person = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) person = self.db.findPersonNoConflicts(attrs["ref"],self.pmap)
@ -885,16 +902,13 @@ class GrampsImportParser(GrampsParser):
self.person = self.db.findPersonNoConflicts(attrs["id"],self.pmap) self.person = self.db.findPersonNoConflicts(attrs["id"],self.pmap)
def start_father(self,attrs): def start_father(self,attrs):
father = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.Father = self.db.findPersonNoConflicts(attrs["ref"],self.pmap)
self.family.setFather(father)
def start_mother(self,attrs): def start_mother(self,attrs):
mother = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.Mother = self.db.findPersonNoConflicts(attrs["ref"],self.pmap)
self.family.setMother(mother)
def start_child(self,attrs): def start_child(self,attrs):
child = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.Children.append(self.db.findPersonNoConflicts(attrs["ref"],self.pmap))
self.family.addChild(child)
def start_family(self,attrs): def start_family(self,attrs):
if self.callback != None and self.count % self.increment == 0: if self.callback != None and self.count % self.increment == 0:
@ -950,10 +964,7 @@ class GrampsImportParser(GrampsParser):
self.placeobj.addSourceRef(self.source_ref) self.placeobj.addSourceRef(self.source_ref)
def start_place(self,attrs): def start_place(self,attrs):
if attrs.has_key('ref'): self.placeobj = self.db.findPlaceNoConflicts(attrs['ref'],self.lmap)
self.placeobj = self.db.findPlaceNoConflicts(attrs['ref'],self.lmap)
else:
self.placeobj = None
def start_placeobj(self,attrs): def start_placeobj(self,attrs):
self.placeobj = self.db.findPlaceNoConflicts(attrs['id'],self.lmap) self.placeobj = self.db.findPlaceNoConflicts(attrs['id'],self.lmap)

View File

@ -2383,7 +2383,7 @@ class GrampsDB(Persistent):
return index return index
def removeObject(self,id): def removeObject(self,id):
del self.placeMap[id] del self.objectMap[id]
def removePlace(self,id): def removePlace(self,id):
del self.placeMap[id] del self.placeMap[id]
@ -2392,6 +2392,7 @@ class GrampsDB(Persistent):
def addPlaceAs(self,place): def addPlaceAs(self,place):
self.placeMap[place.getId()] = place self.placeMap[place.getId()] = place
self.placeTable[place.getId()] = place.getDisplayInfo() self.placeTable[place.getId()] = place.getDisplayInfo()
return place.getId()
def findPlace(self,idVal,map): def findPlace(self,idVal,map):
"""finds a Place in the database using the idVal and map """finds a Place in the database using the idVal and map
@ -2419,7 +2420,6 @@ class GrampsDB(Persistent):
idVal - external ID number idVal - external ID number
map - map build by findPlace of external to gramp's IDs""" map - map build by findPlace of external to gramp's IDs"""
idVal = str(idVal)
if map.has_key(idVal): if map.has_key(idVal):
place = self.placeMap[map[idVal]] place = self.placeMap[map[idVal]]
else: else:
@ -2518,6 +2518,27 @@ class GrampsDB(Persistent):
map[idVal] = family.getId() map[idVal] = family.getId()
return family return family
def findFamilyNoConflict(self,idVal,map):
"""finds a Family in the database using the idVal and map
variables to translate between the external ID and gramps'
internal ID. If no such Family exists, a new Family instance
is created.
idVal - external ID number
map - map build by findFamily of external to gramp's IDs"""
if map.has_key(idVal):
family = self.familyMap[map[idVal]]
else:
family = self.familyMap.get(idVal)
if not family:
family = Family()
family.id = idVal
self.familyMap[idVal] = family
self.fmapIndex = self.fmapIndex + 1
map[idVal] = family.getId()
return family
def findFamilyNoMap(self,val): def findFamilyNoMap(self,val):
"""finds a Family in the database from the passed gramps' ID. """finds a Family in the database from the passed gramps' ID.
If no such Family exists, a new Family is added to the database.""" If no such Family exists, a new Family is added to the database."""