Handling of the SourceTable

svn: r1004
This commit is contained in:
Don Allingham 2002-05-25 15:23:07 +00:00
parent 3dfaf2f94f
commit eb70ab961b
4 changed files with 111 additions and 154 deletions

View File

@ -121,7 +121,6 @@ class PersonMap(Persistent, UserDict):
# This probably shouldn't be called anyway. # This probably shouldn't be called anyway.
raise NotImplementedError raise NotImplementedError
class GrampsZODB(GrampsDB): class GrampsZODB(GrampsDB):
def __init__(self): def __init__(self):
@ -145,6 +144,9 @@ class GrampsZODB(GrampsDB):
self.placeMap = OOBTree() self.placeMap = OOBTree()
self.personTable = OOBTree() self.personTable = OOBTree()
self.placeTable = OOBTree() self.placeTable = OOBTree()
self.sourceTable = OOBTree()
self.need_commit = 0
if self.conn: if self.conn:
self.db.close() self.db.close()
self.conn.close() self.conn.close()
@ -155,85 +157,98 @@ class GrampsZODB(GrampsDB):
if self.conn == None: if self.conn == None:
self.load(name,callback) self.load(name,callback)
def get_object(self,tag):
if self.root.has_key(tag):
item = self.root[tag]
else:
item = OOBTree()
self.root[tag] = item
self.need_commit = 1
return item
def get_display_table(self,src,tag):
if self.root.has_key(tag):
table = self.root[tag]
else:
table = OOBTree()
for key in src.keys():
obj = src[key]
table[key] = obj.getDisplayInfo()
self.root[tag] = table
self.need_commit = 1
return table
def load(self,name,callback): def load(self,name,callback):
self.db = DB(gdbmStorage(name,'w')) self.db = DB(gdbmStorage(name,'w'))
self.conn = self.db.open() self.conn = self.db.open()
root = self.conn.root() self.root = self.conn.root()
need_commit = 0 self.need_commit = 0
if root.has_key('fm'):
self.familyMap = root['fm'] self.familyMap = self.get_object('fm')
else:
self.familyMap = OOBTree() if self.root.has_key('pm'):
root['fm'] = self.familyMap self.personMap = self.root['pm']
need_commit = 1
if root.has_key('pm'):
self.personMap = root['pm']
else: else:
self.personMap = PersonMap() self.personMap = PersonMap()
root['pm'] = self.personMap self.root['pm'] = self.personMap
need_commit = 1 self.need_commit = 1
if root.has_key('pmt'):
self.personTable = root['pmt'] self.personTable = self.get_display_table(self.personMap,'pmt')
else:
for key in self.personMap.keys(): if self.root.has_key('surnames'):
person = self.personMap[key] self.surnames = self.root['surnames']
self.personTable[key] = person.getDisplayInfo()
root['pmt'] = self.personTable
need_commit = 1
if root.has_key('surnames'):
self.surnames = root['surnames']
else: else:
for key in self.personMap.keys(): for key in self.personMap.keys():
person = self.personMap[key] person = self.personMap[key]
self.addSurname(person.getPrimaryName().getSurname()) self.addSurname(person.getPrimaryName().getSurname())
root['surnames'] = self.surnames self.root['surnames'] = self.surnames
need_commit = 1 self.need_commit = 1
if root.has_key('sm'):
self.sourceMap = root['sm'] self.sourceMap = self.get_object('sm')
else: self.sourceTable = self.get_display_table(self.sourceMap,'smt')
self.sourceMap = OOBTree()
root['sm'] = self.sourceMap self.placeMap = self.get_object('plm')
need_commit = 1 self.placeTable = self.get_display_table(self.placeMap,'plmt')
if root.has_key('smt'):
self.sourceTable = root['smt'] if self.root.has_key('default'):
else: self.default = self.root['default']
for key in self.sourceMap.keys():
src = self.sourceMap[key]
self.sourceTable[key] = src.getDisplayInfo()
root['smt'] = self.sourceTable
need_commit = 1
if root.has_key('plm'):
self.placeMap = root['plm']
else:
self.placeMap = OOBTree()
root['plm'] = self.placeMap
need_commit = 1
if root.has_key('plmt'):
self.placeTable = root['plmt']
else:
for key in self.placeMap.keys():
place = self.placeMap[key]
self.placeTable[key] = place.getDisplayInfo()
root['plmt'] = self.placeTable
need_commit = 1
if root.has_key('default'):
self.default = root['default']
else: else:
self.default = None self.default = None
root['default'] = self.default self.root['default'] = self.default
need_commit = 1 self.need_commit = 1
if root.has_key('bookmarks'):
self.bookmarks = root['bookmarks'] if self.root.has_key('bookmarks'):
self.bookmarks = self.root['bookmarks']
else: else:
self.bookmarks = [] self.bookmarks = []
root['bookmarks'] = self.bookmarks self.root['bookmarks'] = self.bookmarks
need_commit = 1 self.need_commit = 1
if need_commit: if self.need_commit:
get_transaction().commit() get_transaction().commit()
return 1 return 1
def setDefaultPerson(self,person): def setDefaultPerson(self,person):
"""sets the default Person to the passed instance""" """sets the default Person to the passed instance"""
GrampsDB.setDefaultPerson(self,person) GrampsDB.setDefaultPerson(self,person)
self.conn.root()['default'] = person self.root()['default'] = person

View File

@ -1184,6 +1184,7 @@ class Person(Persistent):
"""adds a Family to the alternate family list, indicating the """adds a Family to the alternate family list, indicating the
relationship to the mother (mrel) and the father (frel)""" relationship to the mother (mrel) and the father (frel)"""
self.AltFamilyList.append((family,mrel,frel)) self.AltFamilyList.append((family,mrel,frel))
self._p_changed = 1
def clearAltFamilyList(self): def clearAltFamilyList(self):
self.AltFamilyList = [] self.AltFamilyList = []
@ -2280,6 +2281,13 @@ class GrampsDB(Persistent):
def getSourceDisplay(self,key): def getSourceDisplay(self,key):
return self.sourceTable[key] return self.sourceTable[key]
def buildSourceDisplay(self,nkey,okey=None):
if nkey != okey and okey != None:
del self.sourceTable[okey]
if self.sourceTable.has_key(nkey):
del self.sourceTable[nkey]
self.sourceTable[nkey] = self.sourceMap[nkey].getDisplayInfo()
def newFamily(self): def newFamily(self):
"""adds a Family to the database, assigning a gramps' ID""" """adds a Family to the database, assigning a gramps' ID"""

View File

@ -235,5 +235,6 @@ class SourceView:
self.update(0) self.update(0)
def update_display_after_edit(self,place): def update_display_after_edit(self,place):
self.db.buildSourceDisplay(place.getId())
self.update(0) self.update(0)

View File

@ -352,6 +352,7 @@ class GedcomParser:
self.source.setNote(note) self.source.setNote(note)
if not self.source.getTitle(): if not self.source.getTitle():
self.source.setTitle("No title - ID %s" % self.source.getId()) self.source.setTitle("No title - ID %s" % self.source.getId())
self.db.buildSourceDisplay(self.source.getId())
self.backup() self.backup()
return return
elif matches[1] == "TITL": elif matches[1] == "TITL":
@ -458,19 +459,7 @@ class GedcomParser:
self.backup() self.backup()
return return
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() event.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(level+1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
event.addSourceRef(source_ref)
else: else:
self.barf(1) self.barf(1)
@ -753,18 +742,7 @@ class GedcomParser:
else: else:
self.person.addEvent(event) self.person.addEvent(event)
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() source_ref = self.handle_source(matches)
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(2))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,2)
self.person.getPrimaryName().addSourceRef(source_ref) self.person.getPrimaryName().addSourceRef(source_ref)
elif matches[1] == "REFN": elif matches[1] == "REFN":
if intRE.match(matches[2]): if intRE.match(matches[2]):
@ -1048,19 +1026,7 @@ class GedcomParser:
except NameError: except NameError:
print 'please fix the val NameError' print 'please fix the val NameError'
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() ord.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(level+1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
ord.addSourceRef(source_ref)
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
if matches[2] and matches[2][0] != "@": if matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(level+1) note = matches[2] + self.parse_continue_data(level+1)
@ -1106,19 +1072,7 @@ class GedcomParser:
elif matches[1] in ["TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]: elif matches[1] in ["TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]:
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level+1)
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() event.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(level+1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
event.addSourceRef(source_ref)
elif matches[1] == "PLAC": elif matches[1] == "PLAC":
val = matches[2] val = matches[2]
n = string.strip(event.getName()) n = string.strip(event.getName())
@ -1172,19 +1126,7 @@ class GedcomParser:
elif matches[1] in ["TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]: elif matches[1] in ["TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]:
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level+1)
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() event.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
event.addSourceRef(source_ref)
elif matches[1] == "FAMC": elif matches[1] == "FAMC":
family = self.db.findFamily(matches[2],self.fmap) family = self.db.findFamily(matches[2],self.fmap)
mrel,frel = self.parse_adopt_famc(level+1); mrel,frel = self.parse_adopt_famc(level+1);
@ -1264,19 +1206,7 @@ class GedcomParser:
elif matches[1] in ["CAUS", "DATE","TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]: elif matches[1] in ["CAUS", "DATE","TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]:
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level+1)
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() attr.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(level+1))
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
attr.addSourceRef(source_ref)
elif matches[1] == "PLAC": elif matches[1] == "PLAC":
val = matches[2] val = matches[2]
if attr.getValue() == "": if attr.getValue() == "":
@ -1323,20 +1253,7 @@ class GedcomParser:
elif matches[1] in ["TIME","AGE","AGNC","ADDR","STAT","TEMP","HUSB","WIFE","OBJE","_CHUR"]: elif matches[1] in ["TIME","AGE","AGNC","ADDR","STAT","TEMP","HUSB","WIFE","OBJE","_CHUR"]:
self.ignore_sub_junk(level+1) self.ignore_sub_junk(level+1)
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
source_ref = SourceRef() event.addSourceRef(self.handle_source(matches))
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
note = matches[2] + self.parse_continue_data(level+1)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(note)
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
event.addSourceRef(source_ref)
elif matches[1] == "PLAC": elif matches[1] == "PLAC":
val = matches[2] val = matches[2]
if self.placemap.has_key(val): if self.placemap.has_key(val):
@ -1717,6 +1634,22 @@ class GedcomParser:
return dateobj return dateobj
def handle_source(self,matches):
source_ref = SourceRef()
if matches[2] and matches[2][0] != "@":
self.localref = self.localref + 1
ref = "gsr%d" % self.localref
s = self.db.findSource(ref,self.smap)
source_ref.setBase(s)
s.setTitle('Imported Source #%d' % self.localref)
s.setNote(matches[2] + self.parse_continue_data(1))
self.db.buildSourceDisplay(s.getId())
self.ignore_sub_junk(2)
else:
source_ref.setBase(self.db.findSource(matches[2],self.smap))
self.parse_source_reference(source_ref,level+1)
return source_ref
def resolve_refns(self): def resolve_refns(self):
prefix = self.db.iprefix prefix = self.db.iprefix
renamed = [] renamed = []