Handling of the SourceTable
svn: r1004
This commit is contained in:
parent
3dfaf2f94f
commit
eb70ab961b
@ -121,7 +121,6 @@ class PersonMap(Persistent, UserDict):
|
||||
# This probably shouldn't be called anyway.
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class GrampsZODB(GrampsDB):
|
||||
|
||||
def __init__(self):
|
||||
@ -145,6 +144,9 @@ class GrampsZODB(GrampsDB):
|
||||
self.placeMap = OOBTree()
|
||||
self.personTable = OOBTree()
|
||||
self.placeTable = OOBTree()
|
||||
self.sourceTable = OOBTree()
|
||||
self.need_commit = 0
|
||||
|
||||
if self.conn:
|
||||
self.db.close()
|
||||
self.conn.close()
|
||||
@ -155,85 +157,98 @@ class GrampsZODB(GrampsDB):
|
||||
if self.conn == None:
|
||||
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):
|
||||
self.db = DB(gdbmStorage(name,'w'))
|
||||
self.conn = self.db.open()
|
||||
root = self.conn.root()
|
||||
need_commit = 0
|
||||
if root.has_key('fm'):
|
||||
self.familyMap = root['fm']
|
||||
else:
|
||||
self.familyMap = OOBTree()
|
||||
root['fm'] = self.familyMap
|
||||
need_commit = 1
|
||||
if root.has_key('pm'):
|
||||
self.personMap = root['pm']
|
||||
self.root = self.conn.root()
|
||||
self.need_commit = 0
|
||||
|
||||
self.familyMap = self.get_object('fm')
|
||||
|
||||
if self.root.has_key('pm'):
|
||||
self.personMap = self.root['pm']
|
||||
else:
|
||||
self.personMap = PersonMap()
|
||||
root['pm'] = self.personMap
|
||||
need_commit = 1
|
||||
if root.has_key('pmt'):
|
||||
self.personTable = root['pmt']
|
||||
else:
|
||||
for key in self.personMap.keys():
|
||||
person = self.personMap[key]
|
||||
self.personTable[key] = person.getDisplayInfo()
|
||||
root['pmt'] = self.personTable
|
||||
need_commit = 1
|
||||
if root.has_key('surnames'):
|
||||
self.surnames = root['surnames']
|
||||
self.root['pm'] = self.personMap
|
||||
self.need_commit = 1
|
||||
|
||||
self.personTable = self.get_display_table(self.personMap,'pmt')
|
||||
|
||||
if self.root.has_key('surnames'):
|
||||
self.surnames = self.root['surnames']
|
||||
else:
|
||||
for key in self.personMap.keys():
|
||||
person = self.personMap[key]
|
||||
self.addSurname(person.getPrimaryName().getSurname())
|
||||
root['surnames'] = self.surnames
|
||||
need_commit = 1
|
||||
if root.has_key('sm'):
|
||||
self.sourceMap = root['sm']
|
||||
else:
|
||||
self.sourceMap = OOBTree()
|
||||
root['sm'] = self.sourceMap
|
||||
need_commit = 1
|
||||
if root.has_key('smt'):
|
||||
self.sourceTable = root['smt']
|
||||
else:
|
||||
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']
|
||||
self.root['surnames'] = self.surnames
|
||||
self.need_commit = 1
|
||||
|
||||
self.sourceMap = self.get_object('sm')
|
||||
self.sourceTable = self.get_display_table(self.sourceMap,'smt')
|
||||
|
||||
self.placeMap = self.get_object('plm')
|
||||
self.placeTable = self.get_display_table(self.placeMap,'plmt')
|
||||
|
||||
if self.root.has_key('default'):
|
||||
self.default = self.root['default']
|
||||
else:
|
||||
self.default = None
|
||||
root['default'] = self.default
|
||||
need_commit = 1
|
||||
if root.has_key('bookmarks'):
|
||||
self.bookmarks = root['bookmarks']
|
||||
self.root['default'] = self.default
|
||||
self.need_commit = 1
|
||||
|
||||
if self.root.has_key('bookmarks'):
|
||||
self.bookmarks = self.root['bookmarks']
|
||||
else:
|
||||
self.bookmarks = []
|
||||
root['bookmarks'] = self.bookmarks
|
||||
need_commit = 1
|
||||
if need_commit:
|
||||
self.root['bookmarks'] = self.bookmarks
|
||||
self.need_commit = 1
|
||||
if self.need_commit:
|
||||
get_transaction().commit()
|
||||
return 1
|
||||
|
||||
def setDefaultPerson(self,person):
|
||||
"""sets the default Person to the passed instance"""
|
||||
GrampsDB.setDefaultPerson(self,person)
|
||||
self.conn.root()['default'] = person
|
||||
self.root()['default'] = person
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1184,6 +1184,7 @@ class Person(Persistent):
|
||||
"""adds a Family to the alternate family list, indicating the
|
||||
relationship to the mother (mrel) and the father (frel)"""
|
||||
self.AltFamilyList.append((family,mrel,frel))
|
||||
self._p_changed = 1
|
||||
|
||||
def clearAltFamilyList(self):
|
||||
self.AltFamilyList = []
|
||||
@ -2280,6 +2281,13 @@ class GrampsDB(Persistent):
|
||||
|
||||
def getSourceDisplay(self,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):
|
||||
"""adds a Family to the database, assigning a gramps' ID"""
|
||||
|
@ -235,5 +235,6 @@ class SourceView:
|
||||
self.update(0)
|
||||
|
||||
def update_display_after_edit(self,place):
|
||||
self.db.buildSourceDisplay(place.getId())
|
||||
self.update(0)
|
||||
|
||||
|
@ -352,6 +352,7 @@ class GedcomParser:
|
||||
self.source.setNote(note)
|
||||
if not self.source.getTitle():
|
||||
self.source.setTitle("No title - ID %s" % self.source.getId())
|
||||
self.db.buildSourceDisplay(self.source.getId())
|
||||
self.backup()
|
||||
return
|
||||
elif matches[1] == "TITL":
|
||||
@ -458,19 +459,7 @@ class GedcomParser:
|
||||
self.backup()
|
||||
return
|
||||
elif matches[1] == "SOUR":
|
||||
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(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)
|
||||
event.addSourceRef(self.handle_source(matches))
|
||||
else:
|
||||
self.barf(1)
|
||||
|
||||
@ -753,18 +742,7 @@ class GedcomParser:
|
||||
else:
|
||||
self.person.addEvent(event)
|
||||
elif matches[1] == "SOUR":
|
||||
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(2))
|
||||
self.ignore_sub_junk(2)
|
||||
else:
|
||||
source_ref.setBase(self.db.findSource(matches[2],self.smap))
|
||||
self.parse_source_reference(source_ref,2)
|
||||
source_ref = self.handle_source(matches)
|
||||
self.person.getPrimaryName().addSourceRef(source_ref)
|
||||
elif matches[1] == "REFN":
|
||||
if intRE.match(matches[2]):
|
||||
@ -1048,19 +1026,7 @@ class GedcomParser:
|
||||
except NameError:
|
||||
print 'please fix the val NameError'
|
||||
elif matches[1] == "SOUR":
|
||||
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(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)
|
||||
ord.addSourceRef(self.handle_source(matches))
|
||||
elif matches[1] == "NOTE":
|
||||
if matches[2] and matches[2][0] != "@":
|
||||
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"]:
|
||||
self.ignore_sub_junk(level+1)
|
||||
elif matches[1] == "SOUR":
|
||||
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(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)
|
||||
event.addSourceRef(self.handle_source(matches))
|
||||
elif matches[1] == "PLAC":
|
||||
val = matches[2]
|
||||
n = string.strip(event.getName())
|
||||
@ -1172,19 +1126,7 @@ class GedcomParser:
|
||||
elif matches[1] in ["TIME","ADDR","AGE","AGNC","STAT","TEMP","OBJE"]:
|
||||
self.ignore_sub_junk(level+1)
|
||||
elif matches[1] == "SOUR":
|
||||
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.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)
|
||||
event.addSourceRef(self.handle_source(matches))
|
||||
elif matches[1] == "FAMC":
|
||||
family = self.db.findFamily(matches[2],self.fmap)
|
||||
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"]:
|
||||
self.ignore_sub_junk(level+1)
|
||||
elif matches[1] == "SOUR":
|
||||
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(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)
|
||||
attr.addSourceRef(self.handle_source(matches))
|
||||
elif matches[1] == "PLAC":
|
||||
val = matches[2]
|
||||
if attr.getValue() == "":
|
||||
@ -1323,20 +1253,7 @@ class GedcomParser:
|
||||
elif matches[1] in ["TIME","AGE","AGNC","ADDR","STAT","TEMP","HUSB","WIFE","OBJE","_CHUR"]:
|
||||
self.ignore_sub_junk(level+1)
|
||||
elif matches[1] == "SOUR":
|
||||
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)
|
||||
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)
|
||||
event.addSourceRef(self.handle_source(matches))
|
||||
elif matches[1] == "PLAC":
|
||||
val = matches[2]
|
||||
if self.placemap.has_key(val):
|
||||
@ -1717,6 +1634,22 @@ class GedcomParser:
|
||||
|
||||
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):
|
||||
prefix = self.db.iprefix
|
||||
renamed = []
|
||||
|
Loading…
Reference in New Issue
Block a user