2007-07-25 09:11:02 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2007-2008 Douglas S. Blank
|
2007-07-25 09:11:02 +05:30
|
|
|
# Copyright (C) 2004-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
2007-07-25 09:11:02 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
|
2008-01-17 03:12:05 +05:30
|
|
|
"Export to CSV Spreadsheet."
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python Modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import sgettext as _
|
2007-07-25 09:11:02 +05:30
|
|
|
import csv
|
|
|
|
import cStringIO
|
|
|
|
import codecs
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Set up logging
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import logging
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG = logging.getLogger(".ExportCSV")
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2009-04-17 00:59:40 +05:30
|
|
|
from Filters import GenericFilter, Rules, build_filter_model
|
2007-07-25 09:11:02 +05:30
|
|
|
import Utils
|
2008-11-04 09:42:51 +05:30
|
|
|
import gen.proxy
|
2007-07-25 09:11:02 +05:30
|
|
|
import DateHandler
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2009-04-17 00:59:40 +05:30
|
|
|
|
2007-07-25 09:11:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# The function that does the exporting
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-05-01 09:42:42 +05:30
|
|
|
def exportData(database, filename, msg_callback, option_box=None, callback=None):
|
|
|
|
gw = CSVWriter(database, filename, msg_callback, option_box, callback)
|
2008-01-15 14:46:45 +05:30
|
|
|
return gw.export_data()
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Support Functions
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def sortable_string_representation(text):
|
|
|
|
numeric = ""
|
|
|
|
alpha = ""
|
|
|
|
for s in text:
|
|
|
|
if s.isdigit():
|
|
|
|
numeric += s
|
|
|
|
else:
|
|
|
|
alpha += s
|
|
|
|
return alpha + (("0" * 10) + numeric)[-10:]
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Encoding support for CSV, from http://docs.python.org/lib/csv-examples.html
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class UTF8Recoder(object):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Iterator that reads an encoded stream and reencodes the input to UTF-8."""
|
2007-07-25 09:11:02 +05:30
|
|
|
def __init__(self, f, encoding):
|
|
|
|
self.reader = codecs.getreader(encoding)(f)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
return self.reader.next().encode("utf-8")
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class UnicodeReader(object):
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
2008-01-17 03:12:05 +05:30
|
|
|
A CSV reader which will iterate over lines in the CSV file "f", which is
|
|
|
|
encoded in the given encoding.
|
|
|
|
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, f, encoding="utf-8", **kwds):
|
|
|
|
f = UTF8Recoder(f, encoding)
|
|
|
|
self.reader = csv.reader(f, **kwds)
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
row = self.reader.next()
|
|
|
|
return [unicode(s, "utf-8") for s in row]
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class UnicodeWriter(object):
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
2008-01-17 03:12:05 +05:30
|
|
|
A CSV writer which will write rows to CSV file "f", which is encoded in
|
|
|
|
the given encoding.
|
|
|
|
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, f, encoding="utf-8", **kwds):
|
|
|
|
# Redirect output to a queue
|
|
|
|
self.queue = cStringIO.StringIO()
|
|
|
|
self.writer = csv.writer(self.queue, **kwds)
|
|
|
|
self.stream = f
|
|
|
|
self.encoder = codecs.getencoder(encoding)
|
|
|
|
|
|
|
|
def writerow(self, row):
|
|
|
|
self.writer.writerow([s.encode('utf-8') for s in row])
|
|
|
|
# Fetch UTF-8 output from the queue ...
|
|
|
|
data = self.queue.getvalue()
|
|
|
|
data = data.decode('utf-8')
|
|
|
|
# ... and reencode it into the target encoding
|
|
|
|
data, length = self.encoder(data)
|
|
|
|
# write to the target stream
|
|
|
|
self.stream.write(data)
|
|
|
|
# empty queue
|
|
|
|
self.queue.truncate(0)
|
|
|
|
|
|
|
|
def writerows(self, rows):
|
2010-01-25 23:15:21 +05:30
|
|
|
map(self.writerow, rows)
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.stream.close()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# CSVWriter Options
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class CSVWriterOptionBox(object):
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
|
|
|
Create a VBox with the option widgets and define methods to retrieve
|
|
|
|
the options.
|
2008-01-17 03:12:05 +05:30
|
|
|
|
2007-07-25 09:11:02 +05:30
|
|
|
"""
|
2010-05-30 09:37:50 +05:30
|
|
|
def __init__(self, person, dbstate, uistate):
|
2007-07-25 09:11:02 +05:30
|
|
|
self.person = person
|
|
|
|
self.include_individuals = 1
|
|
|
|
self.include_marriages = 1
|
|
|
|
self.include_children = 1
|
2008-12-07 07:37:57 +05:30
|
|
|
self.translate_headers = 1
|
2007-07-25 09:11:02 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
def get_option_box(self):
|
2009-05-15 01:45:59 +05:30
|
|
|
self.topDialog = Glade()
|
2009-04-17 00:59:40 +05:30
|
|
|
self.filters = self.topDialog.get_object("filter")
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
all = GenericFilter()
|
|
|
|
all.set_name(_("Entire Database"))
|
|
|
|
all.add_rule(Rules.Person.Everyone([]))
|
|
|
|
|
|
|
|
the_filters = [all]
|
|
|
|
|
|
|
|
if self.person:
|
|
|
|
des = GenericFilter()
|
|
|
|
des.set_name(_("Descendants of %s") %
|
|
|
|
self.person.get_primary_name().get_name())
|
|
|
|
des.add_rule(Rules.Person.IsDescendantOf(
|
|
|
|
[self.person.get_gramps_id(),1]))
|
|
|
|
|
|
|
|
ans = GenericFilter()
|
|
|
|
ans.set_name(_("Ancestors of %s") %
|
|
|
|
self.person.get_primary_name().get_name())
|
|
|
|
ans.add_rule(Rules.Person.IsAncestorOf(
|
|
|
|
[self.person.get_gramps_id(),1]))
|
|
|
|
|
|
|
|
com = GenericFilter()
|
|
|
|
com.set_name(_("People with common ancestor with %s") %
|
|
|
|
self.person.get_primary_name().get_name())
|
|
|
|
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
|
|
|
[self.person.get_gramps_id()]))
|
|
|
|
|
2008-02-03 08:20:09 +05:30
|
|
|
the_filters += [des,ans,com]
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
from Filters import CustomFilters
|
|
|
|
the_filters.extend(CustomFilters.get_filters('Person'))
|
2009-04-17 00:59:40 +05:30
|
|
|
self.filter_menu = build_filter_model(the_filters)
|
|
|
|
self.filters.set_model(self.filter_menu)
|
|
|
|
self.filters.set_active(0)
|
2007-07-25 09:11:02 +05:30
|
|
|
|
2009-04-17 00:59:40 +05:30
|
|
|
the_box = self.topDialog.get_object('vbox1')
|
|
|
|
the_parent = self.topDialog.get_object('dialog-vbox1')
|
2007-07-25 09:11:02 +05:30
|
|
|
the_parent.remove(the_box)
|
2009-05-15 01:45:59 +05:30
|
|
|
self.topDialog.toplevel.destroy()
|
2007-07-25 09:11:02 +05:30
|
|
|
return the_box
|
|
|
|
|
|
|
|
def parse_options(self):
|
2009-04-17 00:59:40 +05:30
|
|
|
self.include_individuals = self.topDialog.get_object("individuals").get_active()
|
|
|
|
self.include_marriages = self.topDialog.get_object("marriages").get_active()
|
|
|
|
self.include_children = self.topDialog.get_object("children").get_active()
|
|
|
|
self.translate_headers = self.topDialog.get_object("translate_headers").get_active()
|
|
|
|
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# CSVWriter class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 22:49:50 +05:30
|
|
|
class CSVWriter(object):
|
2010-05-01 09:42:42 +05:30
|
|
|
def __init__(self, database, filename, msg_callback, option_box=None, callback=None):
|
2007-07-25 09:11:02 +05:30
|
|
|
self.db = database
|
|
|
|
self.option_box = option_box
|
|
|
|
self.filename = filename
|
|
|
|
self.callback = callback
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback = msg_callback
|
2008-07-14 21:17:15 +05:30
|
|
|
if callable(self.callback): # callback is really callable
|
2007-07-25 09:11:02 +05:30
|
|
|
self.update = self.update_real
|
|
|
|
else:
|
|
|
|
self.update = self.update_empty
|
|
|
|
|
|
|
|
self.plist = {}
|
|
|
|
self.flist = {}
|
|
|
|
|
|
|
|
self.persons_details_done = []
|
|
|
|
self.persons_notes_done = []
|
|
|
|
self.person_ids = {}
|
|
|
|
|
|
|
|
if not option_box:
|
2008-11-04 09:42:51 +05:30
|
|
|
self.include_individuals = 1
|
|
|
|
self.include_marriages = 1
|
|
|
|
self.include_children = 1
|
2008-12-07 07:37:57 +05:30
|
|
|
self.translate_headers = 1
|
2007-07-25 09:11:02 +05:30
|
|
|
else:
|
|
|
|
self.option_box.parse_options()
|
|
|
|
|
|
|
|
self.include_individuals = self.option_box.include_individuals
|
|
|
|
self.include_marriages = self.option_box.include_marriages
|
|
|
|
self.include_children = self.option_box.include_children
|
2008-12-07 07:37:57 +05:30
|
|
|
self.translate_headers = self.option_box.translate_headers
|
2007-07-25 09:11:02 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
if not option_box.cfilter.is_empty():
|
|
|
|
self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter)
|
2007-07-25 09:11:02 +05:30
|
|
|
|
2010-01-25 23:15:21 +05:30
|
|
|
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
|
|
|
|
2007-07-25 09:11:02 +05:30
|
|
|
# get the families for which these people are spouses:
|
|
|
|
self.flist = {}
|
|
|
|
for key in self.plist:
|
|
|
|
p = self.db.get_person_from_handle(key)
|
|
|
|
for family_handle in p.get_family_handle_list():
|
|
|
|
self.flist[family_handle] = 1
|
|
|
|
# now add the families for which these people are a child:
|
2009-07-08 21:41:20 +05:30
|
|
|
family_handles = self.db.iter_family_handles()
|
2007-07-25 09:11:02 +05:30
|
|
|
for family_handle in family_handles:
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
2009-05-23 00:13:40 +05:30
|
|
|
if child_handle in self.plist:
|
2007-07-25 09:11:02 +05:30
|
|
|
self.flist[family_handle] = 1
|
2008-11-04 09:42:51 +05:30
|
|
|
|
|
|
|
def update_empty(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_real(self):
|
|
|
|
self.count += 1
|
|
|
|
newval = int(100*self.count/self.total)
|
|
|
|
if newval != self.oldval:
|
|
|
|
self.callback(newval)
|
|
|
|
self.oldval = newval
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
def writeln(self):
|
|
|
|
self.g.writerow([])
|
|
|
|
|
|
|
|
def write_csv(self, *items):
|
|
|
|
self.g.writerow(items)
|
|
|
|
|
|
|
|
def export_data(self):
|
|
|
|
self.dirname = os.path.dirname (self.filename)
|
|
|
|
try:
|
|
|
|
self.g = open(self.filename,"w")
|
|
|
|
self.fp = open(self.filename, "wb")
|
|
|
|
self.g = UnicodeWriter(self.fp)
|
|
|
|
except IOError,msg:
|
|
|
|
msg2 = _("Could not create %s") % self.filename
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback(msg2,str(msg))
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2007-07-25 09:11:02 +05:30
|
|
|
except:
|
2010-05-01 09:42:42 +05:30
|
|
|
self.msg_callback(_("Could not create %s") % self.filename)
|
2008-01-15 14:46:45 +05:30
|
|
|
return False
|
2007-07-25 09:11:02 +05:30
|
|
|
######################### initialize progress bar
|
|
|
|
self.count = 0
|
|
|
|
self.total = 0
|
|
|
|
self.oldval = 0
|
|
|
|
if self.include_individuals:
|
|
|
|
self.total += len(self.plist)
|
|
|
|
if self.include_marriages:
|
|
|
|
self.total += len(self.flist)
|
|
|
|
if self.include_children:
|
|
|
|
self.total += len(self.flist)
|
|
|
|
########################
|
2010-02-16 07:48:24 +05:30
|
|
|
LOG.debug("Possible people to export: %s", len(self.plist))
|
|
|
|
LOG.debug("Possible families to export: %s", len(self.flist))
|
2007-07-25 09:11:02 +05:30
|
|
|
########################### sort:
|
|
|
|
sortorder = []
|
|
|
|
for key in self.plist:
|
|
|
|
person = self.db.get_person_from_handle(key)
|
|
|
|
if person:
|
|
|
|
primary_name = person.get_primary_name()
|
|
|
|
first_name = primary_name.get_first_name()
|
|
|
|
surname = primary_name.get_surname()
|
|
|
|
sortorder.append( (surname, first_name, key) )
|
|
|
|
sortorder.sort() # will sort on tuples
|
|
|
|
plist = [data[2] for data in sortorder]
|
|
|
|
###########################
|
|
|
|
if self.include_individuals:
|
2008-12-07 07:37:57 +05:30
|
|
|
if self.translate_headers:
|
|
|
|
self.write_csv(_("Person"), _("Surname"), _("Given"),
|
|
|
|
_("Call"), _("Suffix"), _("Prefix"),
|
2009-02-12 13:01:08 +05:30
|
|
|
_("Person|Title"), _("Gender"), _("Birth date"),
|
2008-12-07 07:37:57 +05:30
|
|
|
_("Birth place"), _("Birth source"),
|
|
|
|
_("Death date"), _("Death place"),
|
|
|
|
_("Death source"), _("Note"))
|
|
|
|
else:
|
|
|
|
self.write_csv("Person", "Surname", "Given",
|
|
|
|
"Call", "Suffix", "Prefix",
|
|
|
|
"Title", "Gender", "Birth date",
|
|
|
|
"Birth place", "Birth source",
|
|
|
|
"Death date", "Death place",
|
|
|
|
"Death source", "Note")
|
2007-07-25 09:11:02 +05:30
|
|
|
for key in plist:
|
|
|
|
person = self.db.get_person_from_handle(key)
|
|
|
|
if person:
|
|
|
|
primary_name = person.get_primary_name()
|
|
|
|
first_name = primary_name.get_first_name()
|
|
|
|
surname = primary_name.get_surname()
|
|
|
|
prefix = primary_name.get_surname_prefix()
|
|
|
|
suffix = primary_name.get_suffix()
|
|
|
|
title = primary_name.get_title()
|
|
|
|
grampsid = person.get_gramps_id()
|
|
|
|
grampsid_ref = ""
|
|
|
|
if grampsid != "":
|
|
|
|
grampsid_ref = "[" + grampsid + "]"
|
|
|
|
note = '' # don't export notes or source
|
|
|
|
callname = primary_name.get_call_name()
|
|
|
|
gender = person.get_gender()
|
2007-10-08 22:11:39 +05:30
|
|
|
if gender == gen.lib.Person.MALE:
|
|
|
|
gender = Utils.gender[gen.lib.Person.MALE]
|
|
|
|
elif gender == gen.lib.Person.FEMALE:
|
|
|
|
gender = Utils.gender[gen.lib.Person.FEMALE]
|
2007-07-25 09:11:02 +05:30
|
|
|
else:
|
2007-10-08 22:11:39 +05:30
|
|
|
gender = Utils.gender[gen.lib.Person.UNKNOWN]
|
2007-07-25 09:11:02 +05:30
|
|
|
# Birth:
|
|
|
|
birthdate = ""
|
|
|
|
birthplace = ""
|
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
birth = self.db.get_event_from_handle(birth_ref.ref)
|
|
|
|
if birth:
|
|
|
|
birthdate = self.format_date( birth)
|
|
|
|
place_handle = birth.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
birthplace = place.get_title()
|
|
|
|
# Death:
|
|
|
|
deathdate = ""
|
|
|
|
deathplace = ""
|
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
death = self.db.get_event_from_handle(death_ref.ref)
|
|
|
|
if death:
|
|
|
|
deathdate = self.format_date( death)
|
|
|
|
place_handle = death.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
deathplace = place.get_title()
|
|
|
|
self.write_csv(grampsid_ref, surname, first_name, callname,
|
|
|
|
suffix, prefix, title, gender,
|
|
|
|
birthdate, birthplace, "",
|
|
|
|
deathdate, deathplace, "",
|
|
|
|
note)
|
|
|
|
self.update()
|
|
|
|
self.writeln()
|
|
|
|
########################### sort:
|
|
|
|
sortorder = []
|
|
|
|
for key in self.flist:
|
|
|
|
family = self.db.get_family_from_handle(key)
|
|
|
|
if family:
|
|
|
|
marriage_id = family.get_gramps_id()
|
2009-04-17 00:59:40 +05:30
|
|
|
sortorder.append(
|
|
|
|
(sortable_string_representation(marriage_id), key)
|
|
|
|
)
|
2007-07-25 09:11:02 +05:30
|
|
|
sortorder.sort() # will sort on tuples
|
|
|
|
flist = [data[1] for data in sortorder]
|
|
|
|
###########################
|
|
|
|
if self.include_marriages:
|
2008-12-07 07:37:57 +05:30
|
|
|
if self.translate_headers:
|
|
|
|
self.write_csv(_("Marriage"), _("Husband"), _("Wife"),
|
|
|
|
_("Date"), _("Place"), _("Source"), _("Note"))
|
|
|
|
else:
|
|
|
|
self.write_csv("Marriage", "Husband", "Wife",
|
|
|
|
"Date", "Place", "Source", "Note")
|
2007-07-25 09:11:02 +05:30
|
|
|
for key in flist:
|
|
|
|
family = self.db.get_family_from_handle(key)
|
|
|
|
if family:
|
|
|
|
marriage_id = family.get_gramps_id()
|
|
|
|
if marriage_id != "":
|
|
|
|
marriage_id = "[" + marriage_id + "]"
|
|
|
|
mother_id = ''
|
|
|
|
father_id = ''
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
if father_handle:
|
|
|
|
father = self.db.get_person_from_handle(father_handle)
|
|
|
|
father_id = father.get_gramps_id()
|
|
|
|
if father_id != "":
|
|
|
|
father_id = "[" + father_id + "]"
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if mother_handle:
|
|
|
|
mother = self.db.get_person_from_handle(mother_handle)
|
|
|
|
mother_id = mother.get_gramps_id()
|
|
|
|
if mother_id != "":
|
|
|
|
mother_id = "[" + mother_id + "]"
|
|
|
|
# get mdate, mplace
|
|
|
|
mdate, mplace = '', ''
|
|
|
|
event_ref_list = family.get_event_ref_list()
|
|
|
|
for event_ref in event_ref_list:
|
|
|
|
event = self.db.get_event_from_handle(event_ref.ref)
|
2007-10-08 22:11:39 +05:30
|
|
|
if event.get_type() == gen.lib.EventType.MARRIAGE:
|
2007-07-25 09:11:02 +05:30
|
|
|
mdate = self.format_date( event)
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
|
|
|
mplace = place.get_title()
|
|
|
|
# m_source = self.get_primary_source( event.get_source_references())
|
|
|
|
source, note = '', ''
|
|
|
|
self.write_csv(marriage_id, father_id, mother_id, mdate,
|
|
|
|
mplace, source, note)
|
|
|
|
self.update()
|
|
|
|
self.writeln()
|
|
|
|
if self.include_children:
|
2008-12-07 07:37:57 +05:30
|
|
|
if self.translate_headers:
|
|
|
|
self.write_csv(_("Family"), _("Child"))
|
|
|
|
else:
|
|
|
|
self.write_csv("Family", "Child")
|
2007-07-25 09:11:02 +05:30
|
|
|
for key in flist:
|
|
|
|
family = self.db.get_family_from_handle(key)
|
|
|
|
if family:
|
|
|
|
family_id = family.get_gramps_id()
|
|
|
|
if family_id != "":
|
|
|
|
family_id = "[" + family_id + "]"
|
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.ref
|
|
|
|
child = self.db.get_person_from_handle(child_handle)
|
|
|
|
grampsid = child.get_gramps_id()
|
|
|
|
grampsid_ref = ""
|
|
|
|
if grampsid != "":
|
|
|
|
grampsid_ref = "[" + grampsid + "]"
|
|
|
|
self.write_csv(family_id, grampsid_ref)
|
|
|
|
self.update()
|
|
|
|
self.writeln()
|
|
|
|
self.g.close()
|
2008-01-15 14:46:45 +05:30
|
|
|
return True
|
2007-07-25 09:11:02 +05:30
|
|
|
|
|
|
|
def format_date(self, date):
|
|
|
|
return DateHandler.get_date(date)
|