#3194: fix to write gedcom output in GRAMPS order, and fix to have children in GEDCOM FAM order

svn: r13304
This commit is contained in:
Doug Blank 2009-10-04 21:38:52 +00:00
parent 09497d5576
commit e8c72f766e
2 changed files with 15 additions and 7 deletions

View File

@ -880,6 +880,8 @@ class GedcomParser(UpdateCallback):
we create a new family, assign the handle and GRAMPS ID.
"""
family = gen.lib.Family()
# Add a counter for reordering the children later:
family.child_ref_count = 0
intid = self.fid2id.get(gramps_id)
if self.dbase.has_family_handle(intid):
family.unserialize(self.dbase.get_raw_family_data(intid))
@ -2426,12 +2428,14 @@ class GedcomParser(UpdateCallback):
reflist = [ ref for ref in state.family.get_child_ref_list() \
if ref.ref == child.handle ]
if reflist:
if reflist: # The child has been referenced already
ref = reflist[0]
if sub_state.frel:
ref.set_father_relation(sub_state.frel)
if sub_state.mrel:
ref.set_mother_relation(sub_state.mrel)
# then we will set the order now:
self.set_child_ref_order(state.family, ref)
else:
ref = gen.lib.ChildRef()
ref.ref = child.handle
@ -2441,6 +2445,16 @@ class GedcomParser(UpdateCallback):
ref.set_mother_relation(sub_state.mrel)
state.family.add_child_ref(ref)
def set_child_ref_order(self, family, child_ref):
"""
Sets the child_ref in family.child_ref_list to be in the position
family.child_ref_count. This reorders the children to be in the
order given in the FAM section.
"""
family.child_ref_list.remove(child_ref)
family.child_ref_list.insert(family.child_ref_count, child_ref)
family.child_ref_count += 1
def __family_slgs(self, line, state):
"""
n SLGS {1:1}

View File

@ -846,16 +846,10 @@ class GedcomWriter(BasicUtils.UpdateCallback):
def __family_child_list(self, child_ref_list):
"""
Write the child XREF values to the GEDCOM file.
Sorts the child list by ID value before writing.
"""
# sort the childlist by GRAMPS ID
child_list = [
self.dbase.get_person_from_handle(cref.ref).get_gramps_id()
for cref in child_ref_list ]
child_list.sort()
for gid in child_list:
self.__writeln(1, 'CHIL', '@%s@' % gid)