2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>

* src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping
	* src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping
	* src/gen/lib/name.py: allow grouping equal to surname
	* src/Editors/_EditName.py: correct handling of name grouping, issue #647


svn: r9116
This commit is contained in:
Benny Malengier 2007-10-09 13:05:56 +00:00
parent 83864a84c7
commit f01ae999c3
5 changed files with 163 additions and 39 deletions

View File

@ -1,3 +1,9 @@
2007-10-09 Benny Malengier <benny.malengier@gramps-project.org>
* src/GrampsDb/_GrampsInMemDB.py: correctly store global name grouping
* src/GrampsDb/_GrampsBSDDB.py: correctly store global name grouping
* src/RelLib/_Name.py: allow grouping equal to surname
* src/Editors/_EditName.py: correct handling of name grouping, issue #647
2007-10-08 Don Allingham <don@gramps-project.org> 2007-10-08 Don Allingham <don@gramps-project.org>
* various: cleanup * various: cleanup

View File

@ -72,17 +72,24 @@ class EditName(EditSecondary):
_("Name Editor")) _("Name Editor"))
self.original_group_as = self.obj.get_group_as() self.original_group_as = self.obj.get_group_as()
self.original_group_set = not (self.original_group_as == '')
srn = self.obj.get_surname()
self._get_global_grouping(srn)
self.general_label = self.top.get_widget("general_tab") self.general_label = self.top.get_widget("general_tab")
self.group_over = self.top.get_widget('group_over') self.group_over = self.top.get_widget('group_over')
self.group_over.connect('toggled',self.on_group_over_toggled) self.group_over.connect('toggled',self.on_group_over_toggled)
self.group_over.set_sensitive(not self.db.readonly) self.group_over.set_sensitive(not self.db.readonly)
self.toggle_dirty = False
Utils.bold_label(self.general_label) Utils.bold_label(self.general_label)
def _post_init(self): def _post_init(self):
if self.original_group_as and \ """if there is override, set the override toggle active
(self.original_group_as != self.obj.get_surname()): """
if self.original_group_set or self.global_group_set :
self.group_over.set_active(True) self.group_over.set_active(True)
def _connect_signals(self): def _connect_signals(self):
@ -97,8 +104,11 @@ class EditName(EditSecondary):
self.obj.get_group_as, self.obj.get_group_as,
self.db.readonly) self.db.readonly)
if not self.original_group_as: if not self.original_group_set:
self.group_as.force_value(self.obj.get_surname()) if self.global_group_set :
self.group_as.force_value(self.global_group_as)
else :
self.group_as.force_value(self.obj.get_surname())
format_list = [(name,number) for (number,name,fmt_str,act) format_list = [(name,number) for (number,name,fmt_str,act)
in name_displayer.get_name_format(also_default=True)] in name_displayer.get_name_format(also_default=True)]
@ -196,6 +206,18 @@ class EditName(EditSecondary):
notetype=NoteType.PERSONNAME)) notetype=NoteType.PERSONNAME))
self._setup_notebook_tabs( notebook) self._setup_notebook_tabs( notebook)
def _get_global_grouping(self, srn):
""" we need info on the global grouping of the surname on init,
and on change of surname
"""
self.global_group_as = self.db.get_name_group_mapping(srn)
if srn == self.global_group_as:
self.global_group_as = None
self.global_group_set = False
else:
self.global_group_set = True
def build_menu_names(self,name): def build_menu_names(self,name):
if name: if name:
@ -207,48 +229,141 @@ class EditName(EditSecondary):
return (menu_label,submenu_label) return (menu_label,submenu_label)
def update_group_as(self,obj): def update_group_as(self,obj):
"""Callback if surname changes on GUI
If overwrite is not set, we change the group name too
"""
name = self.obj.get_surname()
if not self.group_over.get_active(): if not self.group_over.get_active():
if self.obj.get_group_as() != self.obj.get_surname(): self.group_as.force_value(name)
val = self.obj.get_group_as() #new surname, so perhaps now a different grouping?
self._get_global_grouping(name)
if not self.group_over.get_active() and self.global_group_set :
self.group_over.set_active(True)
self.group_as.enable(True)
self.toggle_dirty = True
self.group_as.force_value(self.global_group_as)
elif self.group_over.get_active() and self.toggle_dirty:
#changing surname caused active group_over in past, change
# group_over as we type
if self.global_group_set :
self.group_as.force_value(self.global_group_as)
else: else:
name = self.obj.get_surname() self.toggle_dirty = False
val = self.db.get_name_group_mapping(name) self.group_as.force_value(name)
self.group_as.force_value(val) self.group_over.set_active(False)
self.group_as.enable(False)
def on_group_over_toggled(self,obj): def on_group_over_toggled(self,obj):
""" group over changes, if activated, enable edit,
if unactivated, go back to surname.
"""
self.toggle_dirty = False
#enable group as box
self.group_as.enable(obj.get_active()) self.group_as.enable(obj.get_active())
if not obj.get_active(): if not obj.get_active():
field_value = self.obj.get_surname() surname = self.obj.get_surname()
mapping = self.db.get_name_group_mapping(field_value) self.group_as.set_text(surname)
self.group_as.set_text(mapping)
def save(self,*obj): def save(self,*obj):
"""Save the name setting. All is ok, except grouping. We need to
if not self.group_over.get_active(): consider:
self.obj.set_group_as("") 1/ global set, not local set --> unset (ask if global unset)
elif self.obj.get_group_as() == self.obj.get_surname(): 2/ global set, local set --> unset (only local unset!)
self.obj.set_group_as("") 3/ not global set, local set
elif self.obj.get_group_as() != self.original_group_as: or not global set, not local set --> unset
grp_as = self.obj.get_group_as() 4/ not local set, not global set
srn = self.obj.get_surname() or not local set, global set --> set val (ask global or local)
if grp_as not in self.db.get_name_group_keys(): 5/ local set, not global set --> set (change local)
6/ local set, global set --> set (set to global if possible)
"""
closeit = True
surname = self.obj.get_surname()
group_as= self.obj.get_group_as()
grouping_active = self.group_over.get_active()
if not grouping_active :
#user wants to group with surname
if self.global_group_set and not self.original_group_set :
#warn that group will revert to surname
from QuestionDialog import QuestionDialog2 from QuestionDialog import QuestionDialog2
q = QuestionDialog2( q = QuestionDialog2(
_("Break global name grouping?"),
_("All people with the name of %(surname)s will no longer "
"be grouped with the name of %(group_name)s."
) % { 'surname' : surname,
'group_name':group_as},
_("Continue"),
_("Return to Name Editor"))
val = q.run()
if val:
#delete the grouping link on database
self.db.set_name_group_mapping(surname, None)
self.obj.set_group_as("")
else :
closeit = False
elif self.global_group_set and self.original_group_set:
#we change it only back to surname locally, so store group_as
# Note: if all surnames are locally changed to surname, we
# should actually unsed the global group here ....
pass
else :
#global group not set, don't set local group too:
self.obj.set_group_as("")
else:
#user wants to override surname, see what he wants
if not self.original_group_set :
#if changed, ask if this has to happen for the entire group,
#this might be creation of group link, or change of group link
if self.global_group_as != group_as:
from QuestionDialog import QuestionDialog2
q = QuestionDialog2(
_("Group all people with the same name?"), _("Group all people with the same name?"),
_("You have the choice of grouping all people with the " _("You have the choice of grouping all people with the "
"name of %(surname)s with the name of %(group_name)s, or " "name of %(surname)s with the name of %(group_name)s, or "
"just mapping this particular name.") % { 'surname' : srn, "just mapping this particular name."
'group_name':grp_as}, ) % { 'surname' : surname,
'group_name':group_as},
_("Group all"), _("Group all"),
_("Group this name only")) _("Group this name only"))
val = q.run() val = q.run()
if val: if val:
self.obj.set_group_as("") if group_as == surname :
self.db.set_name_group_mapping(srn,grp_as) self.db.set_name_group_mapping(surname, None)
else:
self.db.set_name_group_mapping(surname, group_as)
self.obj.set_group_as("")
else:
if self.global_group_set :
#allow smith to Dummy, but one person still Smith
self.obj.set_group_as(group_as)
elif group_as == surname :
self.obj.set_group_as("")
else:
self.obj.set_group_as(group_as)
else: else:
self.obj.set_group_as(grp_as) #keep original value, no original group
self.obj.set_group_as("")
elif not self.global_group_set :
#don't ask user, group was set locally before,
#change it locally only
if group_as == surname :
#remove grouping
self.obj.set_group_as("")
else:
pass
else:
#locally set group and global group set
if group_as == self.global_group_as :
#unset local group, go with global one
self.obj.set_group_as("")
else :
#local set is different from global, keep it like that
pass
if self.callback: if closeit:
self.callback(self.obj) if self.callback:
self.close() self.callback(self.obj)
self.close()

View File

@ -1257,6 +1257,9 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
self.event_map.sync() self.event_map.sync()
def set_name_group_mapping(self, name, group): def set_name_group_mapping(self, name, group):
"""Make name group under the value of group.
If group =None, the old grouping is deleted
"""
if not self.readonly: if not self.readonly:
if self.UseTXN: if self.UseTXN:
# Start transaction if needed # Start transaction if needed
@ -1265,10 +1268,10 @@ class GrampsBSDDB(GrampsDbBase, UpdateCallback):
the_txn = None the_txn = None
name = str(name) name = str(name)
data = self.name_group.get(name, txn=the_txn) data = self.name_group.get(name, txn=the_txn)
if not group and data: if data is not None:
self.name_group.delete(name, txn=the_txn) self.name_group.delete(name, txn=the_txn)
else: if group is not None:
self.name_group.put(name, group, txn=the_txn) self.name_group.put(name,group,txn=the_txn)
if self.UseTXN: if self.UseTXN:
the_txn.commit() the_txn.commit()
else: else:

View File

@ -130,7 +130,7 @@ class GrampsInMemDB(GrampsDbBase):
def set_name_group_mapping(self,name,group): def set_name_group_mapping(self,name,group):
if group == None and self.name_group.has_key(name): if group == None and self.name_group.has_key(name):
del self.name_group[name] del self.name_group[name]
else: if group is not None :
self.name_group[name] = group self.name_group[name] = group
def build_surname_list(self): def build_surname_list(self):

View File

@ -176,11 +176,11 @@ class Name(SecondaryObject, PrivacyBase, SourceBase, NoteBase, DateBase):
Sets the grouping name for a person. Normally, this is the person's Sets the grouping name for a person. Normally, this is the person's
surname. However, some locales group equivalent names (e.g. Ivanova surname. However, some locales group equivalent names (e.g. Ivanova
and Ivanov in Russian are usually considered equivalent. and Ivanov in Russian are usually considered equivalent.
Note that there is also a database wide grouping set_name_group_mapping
So one might map a name Smith to SmithNew, and have one person still
grouped with name Smith. Hence, group_as can be equal to surname!
""" """
if name == self.surname: self.group_as = name
self.group_as = ""
else:
self.group_as = name
def get_group_as(self): def get_group_as(self):
""" """