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