* src/GrampsDb/_GrampsBSDDB.py: refactor remove and id function
svn: r5613
This commit is contained in:
parent
40b158c997
commit
60ac61c36a
@ -1,6 +1,7 @@
|
|||||||
2005-12-21 Don Allingham <don@gramps-project.org>
|
2005-12-21 Don Allingham <don@gramps-project.org>
|
||||||
* src/DisplayState.py: remove print statements
|
* src/DisplayState.py: remove print statements
|
||||||
* src/ViewManger.py: Fix const.app_*
|
* src/ViewManger.py: Fix const.app_*
|
||||||
|
* src/GrampsDb/_GrampsBSDDB.py: refactor remove and id function
|
||||||
|
|
||||||
2005-12-21 Alex Roitman <shura@gramps-project.org>
|
2005-12-21 Alex Roitman <shura@gramps-project.org>
|
||||||
* src/DisplayState.py (remove_item): Add code to adjust other
|
* src/DisplayState.py (remove_item): Add code to adjust other
|
||||||
|
@ -621,7 +621,6 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def abort_changes(self):
|
def abort_changes(self):
|
||||||
while self.undo():
|
while self.undo():
|
||||||
@ -718,31 +717,18 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.emit('person-rebuild')
|
self.emit('person-rebuild')
|
||||||
|
|
||||||
def get_surname_list(self):
|
def get_surname_list(self):
|
||||||
names = self.surnames.keys()
|
vals = [ unicode(val) for val in set(self.surname.keys()) ]
|
||||||
a = {}
|
|
||||||
for name in names:
|
|
||||||
a[unicode(name)] = 1
|
|
||||||
vals = a.keys()
|
|
||||||
vals.sort(locale.strcoll)
|
vals.sort(locale.strcoll)
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
def get_person_event_type_list(self):
|
def get_person_event_type_list(self):
|
||||||
names = self.eventnames.keys()
|
vals = [ unicode(val) for val in set(self.eventnames.keys()) ]
|
||||||
a = {}
|
vals.sort(locale.strcoll)
|
||||||
for name in names:
|
|
||||||
a[unicode(name)] = 1
|
|
||||||
vals = a.keys()
|
|
||||||
vals.sort()
|
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
def get_repository_type_list(self):
|
def get_repository_type_list(self):
|
||||||
repos_types = self.repository_types.keys()
|
vals = list(set(self.repository_types.keys()))
|
||||||
a = {}
|
vals.sort(locale.strcoll)
|
||||||
for repos_type in repos_types:
|
|
||||||
|
|
||||||
a[unicode(repos_type)] = 1
|
|
||||||
vals = a.keys()
|
|
||||||
vals.sort()
|
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
def remove_person(self,handle,transaction):
|
def remove_person(self,handle,transaction):
|
||||||
@ -755,143 +741,72 @@ class GrampsBSDDB(GrampsDbBase):
|
|||||||
self.person_map.delete(str(handle))
|
self.person_map.delete(str(handle))
|
||||||
self._delete_primary_from_reference_map(handle)
|
self._delete_primary_from_reference_map(handle)
|
||||||
|
|
||||||
def remove_source(self,handle,transaction):
|
def _remove_obj(self, handle, transaction, data_map, key, signal):
|
||||||
if not self.readonly and handle and str(handle) in self.source_map:
|
if not self.readonly and handle and str(handle) in data_map:
|
||||||
if transaction != None:
|
if transaction != None:
|
||||||
old_data = self.source_map.get(str(handle))
|
old_data = data_map.get(str(handle))
|
||||||
transaction.add(SOURCE_KEY,handle,old_data)
|
transaction.add(key,handle,old_data)
|
||||||
self.emit('source-delete',([handle],))
|
self.emit(signal,([handle],))
|
||||||
self.source_map.delete(str(handle))
|
data_map.delete(str(handle))
|
||||||
self._delete_primary_from_reference_map(handle)
|
self._delete_primary_from_reference_map(handle)
|
||||||
|
|
||||||
|
def remove_source(self,handle,transaction):
|
||||||
|
self._remove_obj(handle,transaction,self.source_map, SOURCE_KEY, 'source-delete')
|
||||||
|
|
||||||
def remove_repository(self,handle,transaction):
|
def remove_repository(self,handle,transaction):
|
||||||
if not self.readonly and handle and str(handle) in self.repository_map:
|
self._remove_obj(handle,transaction,self.repository_map, REPOSITORY_KEY,
|
||||||
if transaction != None:
|
'repository-delete')
|
||||||
old_data = self.repository_map.get(str(handle))
|
|
||||||
transaction.add(REPOSITORY_KEY,handle,old_data)
|
|
||||||
self.emit('repository-delete',([handle],))
|
|
||||||
self.repository_map.delete(str(handle))
|
|
||||||
self._delete_primary_from_reference_map(handle)
|
|
||||||
|
|
||||||
def remove_family(self,handle,transaction):
|
def remove_family(self,handle,transaction):
|
||||||
if not self.readonly and handle and str(handle) in self.family_map:
|
self._remove_obj(handle,transaction,self.family_map, FAMILY_KEY, 'family-delete')
|
||||||
if transaction != None:
|
|
||||||
old_data = self.family_map.get(str(handle))
|
|
||||||
transaction.add(FAMILY_KEY,handle,old_data)
|
|
||||||
self.emit('family-delete',([str(handle)],))
|
|
||||||
self.family_map.delete(str(handle))
|
|
||||||
self._delete_primary_from_reference_map(handle)
|
|
||||||
|
|
||||||
def remove_event(self,handle,transaction):
|
def remove_event(self,handle,transaction):
|
||||||
if not self.readonly and handle and str(handle) in self.event_map:
|
self._remove_obj(handle,transaction,self.event_map, EVENT_KEY, 'event-delete')
|
||||||
if transaction != None:
|
|
||||||
old_data = self.event_map.get(str(handle))
|
|
||||||
transaction.add(EVENT_KEY,handle,old_data)
|
|
||||||
self.emit('event-delete',([str(handle)],))
|
|
||||||
self.event_map.delete(str(handle))
|
|
||||||
self._delete_primary_from_reference_map(handle)
|
|
||||||
|
|
||||||
def remove_place(self,handle,transaction):
|
def remove_place(self,handle,transaction):
|
||||||
if not self.readonly and handle and str(handle) in self.place_map:
|
self._remove_obj(handle,transaction,self.place_map, PLACE_KEY, 'place-delete')
|
||||||
if transaction != None:
|
|
||||||
old_data = self.place_map.get(str(handle))
|
|
||||||
transaction.add(PLACE_KEY,handle,old_data)
|
|
||||||
self.emit('place-delete',([handle],))
|
|
||||||
self.place_map.delete(str(handle))
|
|
||||||
self._delete_primary_from_reference_map(handle)
|
|
||||||
|
|
||||||
def remove_object(self,handle,transaction):
|
def remove_object(self,handle,transaction):
|
||||||
if not self.readonly and handle and str(handle) in self.media_map:
|
self._remove_obj(handle,transaction,self.media_map, MEDIA_KEY, 'media-delete')
|
||||||
if transaction != None:
|
|
||||||
old_data = self.media_map.get(str(handle))
|
|
||||||
transaction.add(MEDIA_KEY,handle,old_data)
|
|
||||||
self.emit('media-delete',([handle],))
|
|
||||||
self.media_map.delete(str(handle))
|
|
||||||
self._delete_primary_from_reference_map(handle)
|
|
||||||
|
|
||||||
def get_person_from_gramps_id(self,val):
|
def _get_obj_from_gramps_id(self,val,tbl,class_init):
|
||||||
"""finds a Person in the database from the passed gramps' ID.
|
data = tbl.get(str(val))
|
||||||
If no such Person exists, None is returned."""
|
|
||||||
|
|
||||||
data = self.id_trans.get(str(val))
|
|
||||||
if data:
|
if data:
|
||||||
person = Person()
|
obj = class_init()
|
||||||
person.unserialize(cPickle.loads(data))
|
obj.unserialize(cPickle.loads(data))
|
||||||
return person
|
return person
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_person_from_gramps_id(self,val):
|
||||||
|
"""finds a Person in the database from the passed gramps' ID.
|
||||||
|
If no such Person exists, a new Person is added to the database."""
|
||||||
|
return self._get_obj_from_gramps_id(val,self.id_trans,Person)
|
||||||
|
|
||||||
def get_family_from_gramps_id(self,val):
|
def get_family_from_gramps_id(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, None is returned."""
|
If no such Family exists, a new Person is added to the database."""
|
||||||
|
return self._get_obj_from_gramps_id(val,self.fid_trans,Family)
|
||||||
data = self.fid_trans.get(str(val))
|
|
||||||
if data:
|
|
||||||
family = Family()
|
|
||||||
family.unserialize(cPickle.loads(data))
|
|
||||||
return family
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_event_from_gramps_id(self,val):
|
|
||||||
"""finds an Event in the database from the passed gramps' ID.
|
|
||||||
If no such Event exists, None is returned."""
|
|
||||||
|
|
||||||
data = self.eid_trans.get(str(val))
|
|
||||||
if data:
|
|
||||||
event = Event()
|
|
||||||
event.unserialize(cPickle.loads(data))
|
|
||||||
return event
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_place_from_gramps_id(self,val):
|
def get_place_from_gramps_id(self,val):
|
||||||
"""finds a Place in the database from the passed gramps' ID.
|
"""finds a Place in the database from the passed gramps' ID.
|
||||||
If no such Place exists, None is returned."""
|
If no such Place exists, a new Person is added to the database."""
|
||||||
|
return self._get_obj_from_gramps_id(val,self.pid_trans,Place)
|
||||||
data = self.pid_trans.get(str(val))
|
|
||||||
if data:
|
|
||||||
place = Place()
|
|
||||||
place.unserialize(cPickle.loads(data))
|
|
||||||
return place
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_source_from_gramps_id(self,val):
|
def get_source_from_gramps_id(self,val):
|
||||||
"""finds a Source in the database from the passed gramps' ID.
|
"""finds a Source in the database from the passed gramps' ID.
|
||||||
If no such Source exists, None is returned."""
|
If no such Source exists, a new Person is added to the database."""
|
||||||
|
return self._get_obj_from_gramps_id(val,self.sid_trans,Source)
|
||||||
data = self.sid_trans.get(str(val))
|
|
||||||
if data:
|
|
||||||
source = Source()
|
|
||||||
source.unserialize(cPickle.loads(data))
|
|
||||||
return source
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_repository_from_gramps_id(self,val):
|
|
||||||
"""finds a Repository in the database from the passed gramps' ID.
|
|
||||||
If no such Repository exists, None is returned."""
|
|
||||||
|
|
||||||
data = self.rid_trans.get(str(val))
|
|
||||||
if data:
|
|
||||||
repository = Repository()
|
|
||||||
repository.unserialize(cPickle.loads(data))
|
|
||||||
return repository
|
|
||||||
else:
|
|
||||||
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.
|
||||||
If no such MediaObject exists, None is returned."""
|
If no such MediaObject exists, a new Person is added to the database."""
|
||||||
|
return self._get_obj_from_gramps_id(val,self.oid_trans,MediaObject)
|
||||||
|
|
||||||
data = self.oid_trans.get(str(val))
|
def get_repository_from_gramps_id(self,val):
|
||||||
if data:
|
"""finds a MediaObject in the database from the passed gramps' ID.
|
||||||
obj = MediaObject()
|
If no such MediaObject exists, a new Person is added to the database."""
|
||||||
obj.unserialize(cPickle.loads(data))
|
return self._get_obj_from_gramps_id(val,self.rid_trans,Repository)
|
||||||
return obj
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def transaction_commit(self,transaction,msg):
|
def transaction_commit(self,transaction,msg):
|
||||||
GrampsDbBase.transaction_commit(self,transaction,msg)
|
GrampsDbBase.transaction_commit(self,transaction,msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user