EditName fix

svn: r6290
This commit is contained in:
Don Allingham 2006-04-07 21:06:20 +00:00
parent 4b2c5d5136
commit 790de99bf9

View File

@ -25,6 +25,9 @@ Base class for the GRAMPS databases. All database interfaces should inherit
from this class.
"""
__author__ = "Donald N. Allingham"
__revision__ = "$Revision:$"
#-------------------------------------------------------------------------
#
# libraries
@ -34,10 +37,15 @@ import cPickle
import time
import random
import locale
import re
import os
from sys import maxint
import sets
from gettext import gettext as _
try:
set()
except NameError:
from sets import Set as set
import logging
log = logging.getLogger(".GrampsDb")
@ -210,11 +218,11 @@ class GrampsDbBase(GrampsDBCallback):
self.rmap_index = 0
self.db_is_open = False
self.family_event_names = sets.Set()
self.individual_event_names = sets.Set()
self.individual_attributes = sets.Set()
self.family_attributes = sets.Set()
self.marker_names = sets.Set()
self.family_event_names = set()
self.individual_event_names = set()
self.individual_attributes = set()
self.family_attributes = set()
self.marker_names = set()
self.set_person_id_prefix(Config.get_person_id_prefix())
self.set_object_id_prefix(Config.get_object_id_prefix())
@ -476,7 +484,8 @@ class GrampsDbBase(GrampsDBCallback):
"""
self._commit_base(repository, self.repository_map, REPOSITORY_KEY,
transaction.repository_update, transaction.repository_add,
transaction.repository_update,
transaction.repository_add,
transaction, change_time)
def find_next_person_gramps_id(self):
@ -622,7 +631,8 @@ class GrampsDbBase(GrampsDBCallback):
"""
return self._get_from_handle(handle, Repository, self.repository_map)
def _find_from_handle(self,handle,transaction,class_type,dmap,add_func):
def _find_from_handle(self, handle, transaction, class_type, dmap,
add_func):
obj = class_type()
handle = str(handle)
if dmap.has_key(handle):
@ -632,7 +642,8 @@ class GrampsDbBase(GrampsDBCallback):
add_func(obj, transaction)
return obj
def _check_from_handle(self,handle,transaction,class_type,dmap,add_func):
def _check_from_handle(self, handle, transaction, class_type, dmap,
add_func):
handle = str(handle)
if not dmap.has_key(handle):
obj = class_type()
@ -1180,7 +1191,8 @@ class GrampsDbBase(GrampsDBCallback):
"""
self.rprefix = self._validated_id_prefix(val, "R")
def transaction_begin(self,msg="",batch=False, match=False, no_magic=False):
def transaction_begin(self, msg="", batch=False, match=False,
no_magic=False):
"""
Creates a new Transaction tied to the current UNDO database. The
transaction has no effect until it is committed using the
@ -1477,7 +1489,7 @@ class GrampsDbBase(GrampsDBCallback):
instances in the database"""
return list(self.family_event_names)
def get_marker_types():
def get_marker_types(self):
"""return a list of all marker types available in the database"""
return list(self.marker_names)
@ -1632,24 +1644,24 @@ class GrampsDbBase(GrampsDBCallback):
"""
return self.repository_map.has_key(str(handle)) != False
def _sortbyname(self,f,s):
n1 = self.person_map.get(str(f))[3].sname
n2 = self.person_map.get(str(s))[3].sname
return locale.strcoll(n1,n2)
def _sortbyname(self, first, second):
name1 = self.person_map.get(str(first))[3].sname
name2 = self.person_map.get(str(second))[3].sname
return locale.strcoll(name1, name2)
def _sortbyplace(self,f,s):
return locale.strcoll(self.place_map.get(str(f))[2],
self.place_map.get(str(s))[2])
def _sortbyplace(self, first, second):
return locale.strcoll(self.place_map.get(str(first))[2],
self.place_map.get(str(second))[2])
def _sortbysource(self,f,s):
fp = unicode(self.source_map[str(f)][2])
sp = unicode(self.source_map[str(s)][2])
return locale.strcoll(fp,sp)
def _sortbysource(self, first, second):
source1 = unicode(self.source_map[str(first)][2])
source2 = unicode(self.source_map[str(second)][2])
return locale.strcoll(source1, source2)
def _sortbymedia(self,f,s):
fp = self.media_map[str(f)][4]
sp = self.media_map[str(s)][4]
return locale.strcoll(fp,sp)
def _sortbymedia(self, first, second):
media1 = self.media_map[str(first)][4]
media2 = self.media_map[str(second)][4]
return locale.strcoll(media1, media2)
def _set_column_order(self, col_list, name):
if self.metadata and not self.readonly:
@ -1726,8 +1738,9 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Person display common information stored in the
database's metadata.
"""
default = [(1,1,100),(1,2,100),(1,3,150),(0,4,150),(1,5,150),
(0,6,150),(0,7,100),(0,8,100),(0,9,100)]
default = [(1, 1, 100), (1, 2, 100), (1, 3, 150), (0, 4, 150),
(1, 5, 150), (0, 6, 150), (0, 7, 100), (0, 8, 100),
(0, 9, 100)]
return self._get_column_order(PERSON_COL_KEY, default)
def _get_columns(self, key, default):
@ -1748,7 +1761,8 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Person display common information stored in the
database's metadata.
"""
default = [(1,0,75), (1,1,200),(1,2,200),(1,3,100),(0,4,100)]
default = [(1, 0, 75), (1, 1, 200), (1, 2, 200), (1, 3, 100),
(0, 4, 100)]
return self._get_columns(FAMILY_COL_KEY, default)
def get_child_column_order(self):
@ -1756,7 +1770,8 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Person display common information stored in the
database's metadata.
"""
default = [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(0,6),(0,7)]
default = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(0, 6), (0, 7)]
return self._get_column_order(CHILD_COL_KEY, default)
def get_place_column_order(self):
@ -1764,7 +1779,9 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Place display common information stored in the
database's metadata.
"""
default = [(1,0,250), (1,1,75),(1,2,100),(0,3,100),(0,4,100,),(1,5,150),(0,6,150),(1,7,150),(0,8,150),(0,9,150),(0,10,150)]
default = [(1, 0, 250), (1, 1, 75), (1, 2, 100), (0, 3, 100),
(0, 4, 100, ), (1, 5, 150), (0, 6, 150), (1, 7, 150),
(0, 8, 150), (0, 9, 150), (0, 10, 150)]
return self._get_columns(PLACE_COL_KEY, default)
def get_source_column_order(self):
@ -1772,7 +1789,8 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Source display common information stored in the
database's metadata.
"""
default = [(1,0,200),(1,1,75),(1,2,150),(0,3,100),(1,4,150),(0,5,100)]
default = [(1, 0, 200), (1, 1, 75), (1, 2, 150), (0, 3, 100),
(1, 4, 150), (0, 5, 100)]
return self._get_columns(SOURCE_COL_KEY, default)
def get_media_column_order(self):
@ -1780,7 +1798,8 @@ class GrampsDbBase(GrampsDBCallback):
Returns the MediaObject display common information stored in the
database's metadata.
"""
default = [(1,0,200,),(1,1,75),(1,2,100),(1,3,200),(1,5,150),(0,4,150)]
default = [(1, 0, 200, ), (1, 1, 75), (1, 2, 100), (1, 3, 200),
(1, 5, 150), (0, 4, 150)]
return self._get_columns(MEDIA_COL_KEY, default)
def get_event_column_order(self):
@ -1788,7 +1807,8 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Event display common information stored in the
database's metadata.
"""
default = [(1,0,200),(1,1,75),(1,2,100),(1,3,150),(1,4,200),(1,5,100),(0,6,100)]
default = [(1, 0, 200), (1, 1, 75), (1, 2, 100), (1, 3, 150),
(1, 4, 200), (1, 5, 100), (0, 6, 100)]
return self._get_columns(EVENT_COL_KEY, default)
def get_repository_column_order(self):
@ -1796,7 +1816,9 @@ class GrampsDbBase(GrampsDBCallback):
Returns the Repository display common information stored in the
database's metadata.
"""
default = [(1,0,200),(1,1,75),(0,5,100),(0,6,100),(1,2,100),(1,3,250),(1,4,100),(0,7,100),(0,8,100),(0,9,100),(0,10,100)]
default = [(1, 0, 200), (1, 1, 75), (0, 5, 100), (0, 6, 100),
(1, 2, 100), (1, 3, 250), (1, 4, 100), (0, 7, 100),
(0, 8, 100), (0, 9, 100), (0, 10, 100)]
return self._get_columns(REPOSITORY_COL_KEY, default)
def _delete_primary_from_reference_map(self, handle, transaction):
@ -1835,7 +1857,8 @@ class GrampsDbBase(GrampsDBCallback):
# Make a dictionary of the functions and classes that we need for
# each of the primary object tables.
primary_tables = {'Person': {'cursor_func': self.get_person_cursor,
primary_tables = {
'Person': {'cursor_func': self.get_person_cursor,
'class_func': Person},
'Family': {'cursor_func': self.get_family_cursor,
'class_func': Family},
@ -1852,8 +1875,9 @@ class GrampsDbBase(GrampsDBCallback):
}
# Now we use the functions and classes defined above to loop through each of the
# primary object tables that have been requests in the include_classes list.
# Now we use the functions and classes defined above to loop through
# each of the primary object tables that have been requests in the
#include_classes list.
for primary_table_name in primary_tables.keys():
if include_classes == None or primary_table_name in include_classes:
@ -1957,14 +1981,14 @@ class Transaction:
"""
self.msg = msg
def add(self, type, handle, old_data, new_data):
def add(self, obj_type, handle, old_data, new_data):
"""
Adds a commit operation to the Transaction. The type is a constant
Adds a commit operation to the Transaction. The obj_type is a constant
that indicates what type of PrimaryObject is being added. The handle
is the object's database handle, and the data is the tuple returned
by the object's serialize method.
"""
self.last = self.db.append(cPickle.dumps((type,
self.last = self.db.append(cPickle.dumps((obj_type,
handle,
old_data,
new_data),
@ -2051,9 +2075,9 @@ class DbState(GrampsDBCallback):
self.active = self.db.get_person_from_handle(self.active.handle)
return self.active
def change_database(self,db):
def change_database(self, database):
self.db.close()
self.db = db
self.db = database
self.db.connect('place-add', self._place_add)
self.db.connect('place-update', self._place_update)
self.db.connect('place-delete', self._place_delete)