2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-02-20 07:42:39 +05:30
|
|
|
# Copyright (C) 2000-2004 Donald N. Allingham
|
2002-10-20 19:55:16 +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
|
|
|
|
#
|
|
|
|
|
2003-12-03 09:19:39 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""The core library of the GRAMPS database"""
|
|
|
|
|
|
|
|
__author__ = "Donald N. Allingham"
|
|
|
|
__version__ = "$Revision$"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
from re import compile
|
|
|
|
import os
|
2004-02-29 00:16:40 +05:30
|
|
|
import os.path
|
2004-02-14 11:10:30 +05:30
|
|
|
import types
|
2004-05-19 11:43:36 +05:30
|
|
|
from gettext import gettext as _
|
2004-05-20 05:42:14 +05:30
|
|
|
import cPickle
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-07-21 16:50:31 +05:30
|
|
|
from Date import Date, SingleDate, compare_dates, not_too_old
|
2003-10-12 09:56:00 +05:30
|
|
|
import GrampsCfg
|
2002-10-20 19:55:16 +05:30
|
|
|
import const
|
2004-06-27 08:40:06 +05:30
|
|
|
import Utils
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Confidence levels
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
CONF_VERY_HIGH = 4
|
|
|
|
CONF_HIGH = 3
|
|
|
|
CONF_NORMAL = 2
|
|
|
|
CONF_LOW = 1
|
|
|
|
CONF_VERY_LOW = 0
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
PERSON_KEY = 0
|
|
|
|
FAMILY_KEY = 1
|
|
|
|
SOURCE_KEY = 2
|
|
|
|
EVENT_KEY = 3
|
|
|
|
MEDIA_KEY = 4
|
|
|
|
PLACE_KEY = 5
|
|
|
|
|
2004-05-20 05:42:14 +05:30
|
|
|
UNDO_SIZE = 1000
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ID regular expression
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
_id_reg = compile("%\d+d")
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SourceNote
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class SourceNote:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Base class for storing source references and notes"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""Create a new SourceNote, copying from source if not None"""
|
|
|
|
|
|
|
|
self.source_list = []
|
|
|
|
|
|
|
|
if source:
|
|
|
|
if len(source.source_list) > 0:
|
|
|
|
for sref in source.source_list:
|
|
|
|
self.source_list.append(SourceRef(sref))
|
|
|
|
if source.note:
|
|
|
|
self.note = Note(source.note.get())
|
|
|
|
else:
|
|
|
|
self.note = None
|
|
|
|
else:
|
|
|
|
self.note = None
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def add_source_reference(self,gid) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Set the source reference"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.source_list.append(gid)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_source_references(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Return the source reference"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.source_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_source_reference_list(self,list) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Replaces the source reference"""
|
|
|
|
self.source_list = list
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Set the note to the given text"""
|
|
|
|
if self.note == None:
|
|
|
|
self.note = Note()
|
|
|
|
self.note.set(text)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Return the current note"""
|
|
|
|
if self.note == None:
|
|
|
|
return ""
|
|
|
|
else:
|
|
|
|
return self.note.get()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note_format(self,val):
|
2003-12-10 19:51:48 +05:30
|
|
|
"""Set the note's format to the given value"""
|
|
|
|
if self.note:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.note.set_format(val)
|
2003-12-10 19:51:48 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note_format(self):
|
2003-12-10 19:51:48 +05:30
|
|
|
"""Return the current note's format"""
|
|
|
|
if self.note == None:
|
|
|
|
return 0
|
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.note.get_format()
|
2003-12-10 19:51:48 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note_object(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Change the note object instance to obj"""
|
|
|
|
self.note = obj
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note_object(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Return in note instance, not just the text"""
|
|
|
|
return self.note
|
|
|
|
|
|
|
|
def unique_note(self):
|
|
|
|
"""Creates a unique instance of the current note"""
|
|
|
|
self.note = Note(self.note.get())
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# LdsOrd
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class LdsOrd(SourceNote):
|
|
|
|
"""LDS Ordinance support"""
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""Creates a LDS Ordinance instance"""
|
|
|
|
SourceNote.__init__(self,source)
|
|
|
|
if source:
|
|
|
|
self.famc = source.famc
|
|
|
|
self.date = Date(source.date)
|
|
|
|
self.temple = source.temple
|
|
|
|
self.status = source.status
|
|
|
|
self.place = source.place
|
|
|
|
else:
|
|
|
|
self.famc = None
|
|
|
|
self.date = None
|
|
|
|
self.temple = ""
|
|
|
|
self.status = 0
|
|
|
|
self.place = None
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the title of the Place associated with the Ordinance"""
|
|
|
|
if self.place:
|
|
|
|
return self.place.get_title()
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_place_id(self,place):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Place instance of the Event"""
|
|
|
|
self.place = place
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Place instance of the Event"""
|
|
|
|
return self.place
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_family_id(self,family):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the family associated with the LDS ordinance"""
|
|
|
|
self.famc = family
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_family_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Gets the family associated with the LDS ordinance"""
|
|
|
|
return self.famc
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_status(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the status of the LDS ordinance"""
|
|
|
|
self.status = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_status(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Gets the status of the LDS ordinance"""
|
|
|
|
return self.status
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date(self, date) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""attempts to sets the date of the LdsOrd instance"""
|
|
|
|
if not self.date:
|
|
|
|
self.date = Date()
|
|
|
|
self.date.set(date)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date of the LdsOrd instance"""
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date_object(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Date object associated with the LdsOrd"""
|
|
|
|
if not self.date:
|
|
|
|
self.date = Date()
|
|
|
|
return self.date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date_object(self,date):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Date object associated with the LdsOrd"""
|
|
|
|
self.date = date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_temple(self,temple):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the temple assocated with the LDS ordinance"""
|
|
|
|
self.temple = temple
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_temple(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Gets the temple assocated with the LDS ordinance"""
|
|
|
|
return self.temple
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def is_empty(self):
|
2003-08-01 07:28:51 +05:30
|
|
|
"""Returns 1 if the LDS ordidance is actually empty"""
|
|
|
|
if (self.famc or
|
2004-02-14 11:10:30 +05:30
|
|
|
(self.date and not self.date.is_empty()) or
|
2003-08-01 07:28:51 +05:30
|
|
|
self.temple or
|
|
|
|
self.status or
|
|
|
|
self.place):
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def are_equal(self,other):
|
2003-08-01 07:28:51 +05:30
|
|
|
"""returns 1 if the specified ordinance is the same as the instance"""
|
2002-10-20 19:55:16 +05:30
|
|
|
if other == None:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.is_empty():
|
2003-08-01 07:28:51 +05:30
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
if (self.famc != other.famc or
|
|
|
|
self.place != other.place or
|
2003-11-17 06:11:32 +05:30
|
|
|
self.status != other.status or
|
2002-10-20 19:55:16 +05:30
|
|
|
self.temple != other.temple or
|
2004-02-14 11:10:30 +05:30
|
|
|
compare_dates(self.get_date_object(),other.get_date_object()) or
|
|
|
|
len(self.get_source_references()) != len(other.get_source_references())):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
index = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
olist = other.get_source_references()
|
|
|
|
for a in self.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
if not a.are_equal(olist[index]):
|
|
|
|
return 0
|
|
|
|
index = index + 1
|
|
|
|
return 1
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DataObj
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class DataObj(SourceNote):
|
|
|
|
"""Base class for data elements, providing source, note, and privacy data"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""Create a new DataObj, copying data from a source object if provided"""
|
|
|
|
SourceNote.__init__(self,source)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
self.private = source.private
|
|
|
|
else:
|
|
|
|
self.private = 0
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_privacy(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets or clears the privacy flag of the data"""
|
|
|
|
self.private = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_privacy(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the privacy level of the data"""
|
|
|
|
return self.private
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Place
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class Place(SourceNote):
|
|
|
|
"""Contains information related to a place, including multiple address
|
|
|
|
information (since place names can change with time), longitude, latitude,
|
|
|
|
a collection of images and URLs, a note and a source"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""Creates a new Place object.
|
|
|
|
|
|
|
|
source - Object to copy. If none supplied, create an empty place object"""
|
|
|
|
|
|
|
|
SourceNote.__init__(self,source)
|
|
|
|
if source:
|
2004-02-22 10:27:06 +05:30
|
|
|
self.long = source.long
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lat = source.lat
|
|
|
|
self.title = source.title
|
|
|
|
self.main_loc = Location(source.main_loc)
|
|
|
|
self.alt_loc = []
|
|
|
|
for loc in source.alt_loc:
|
|
|
|
self.alt_loc = Location(loc)
|
|
|
|
self.id = source.id
|
|
|
|
self.urls = []
|
|
|
|
for u in source.urls:
|
|
|
|
self.urls.append(Url(u))
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = []
|
2004-02-22 10:27:06 +05:30
|
|
|
for media_id in source.media_list:
|
|
|
|
self.media_list.append(MediaRef(media_id))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.long = ""
|
|
|
|
self.lat = ""
|
|
|
|
self.title = ""
|
|
|
|
self.main_loc = None
|
|
|
|
self.alt_loc = []
|
|
|
|
self.id = ""
|
|
|
|
self.urls = []
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = []
|
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return (self.id, self.title, self.long, self.lat, self.main_loc,
|
|
|
|
self.alt_loc, self.urls, self.media_list, self.source_list, self.note)
|
|
|
|
|
|
|
|
def unserialize(self,data):
|
2004-06-10 05:29:03 +05:30
|
|
|
(self.id, self.title, self.long, self.lat, self.main_loc,
|
|
|
|
self.alt_loc, self.urls, self.media_list, self.source_list,
|
|
|
|
self.note) = data
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_url_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Return the list of URLs"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.urls
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_url_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Replace the current URL list with the new one"""
|
|
|
|
self.urls = list
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_url(self,url):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Add a URL to the URL list"""
|
|
|
|
self.urls.append(url)
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_id(self,gid):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the gramps ID for the place object"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = gid
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the gramps ID for the place object"""
|
|
|
|
return self.id
|
2004-06-27 08:40:06 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_title(self,name):
|
|
|
|
"""Sets the title of the place object"""
|
|
|
|
self.title = name
|
|
|
|
|
|
|
|
def get_title(self):
|
|
|
|
"""Returns the title of the place object"""
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def set_longitude(self,long):
|
|
|
|
"""Sets the longitude of the place"""
|
|
|
|
self.long = long
|
|
|
|
|
|
|
|
def get_longitude(self):
|
|
|
|
"""Returns the longitude of the place"""
|
|
|
|
return self.long
|
|
|
|
|
|
|
|
def set_latitude(self,long):
|
|
|
|
"""Sets the latitude of the place"""
|
|
|
|
self.lat = long
|
|
|
|
|
|
|
|
def get_latitude(self):
|
|
|
|
"""Returns the latitude of the place"""
|
|
|
|
return self.lat
|
|
|
|
|
|
|
|
def get_main_location(self):
|
|
|
|
"""Returns the Location object representing the primary information"""
|
|
|
|
if not self.main_loc:
|
|
|
|
self.main_loc = Location()
|
|
|
|
return self.main_loc
|
|
|
|
|
|
|
|
def set_main_location(self,loc):
|
|
|
|
"""Assigns the main location to the Location object passed"""
|
|
|
|
self.main_loc = loc
|
|
|
|
|
|
|
|
def get_alternate_locations(self):
|
|
|
|
"""Returns a list of alternate location information objects"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.alt_loc
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_alternate_locations(self,list):
|
|
|
|
"""Replaces the current alternate location list with the new one"""
|
|
|
|
self.alt_loc = list
|
|
|
|
|
|
|
|
def add_alternate_locations(self,loc):
|
|
|
|
"""Adds a Location to the alternate location list"""
|
|
|
|
if loc not in self.alt_loc:
|
|
|
|
self.alt_loc.append(loc)
|
|
|
|
|
2004-02-22 10:27:06 +05:30
|
|
|
def add_media_reference(self,media_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Adds a Photo object to the place object's image list"""
|
2004-02-22 10:27:06 +05:30
|
|
|
self.media_list.append(media_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def get_media_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the list of Photo objects"""
|
2004-02-21 11:41:59 +05:30
|
|
|
return self.media_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def set_media_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the list of Photo objects"""
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_display_info(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Gets the display information associated with the object. This includes
|
|
|
|
the information that is used for display and for sorting. Returns a list
|
|
|
|
consisting of 13 strings. These are: Place Title, Place ID, Main Location
|
|
|
|
Parish, Main Location County, Main Location City, Main Location State/Province,
|
|
|
|
Main Location Country, upper case Place Title, upper case Parish, upper
|
|
|
|
case city, upper case county, upper case state, upper case country"""
|
|
|
|
|
|
|
|
if self.main_loc:
|
|
|
|
return [self.title,self.id,self.main_loc.parish,self.main_loc.city,
|
|
|
|
self.main_loc.county,self.main_loc.state,self.main_loc.country,
|
2003-01-19 11:55:20 +05:30
|
|
|
self.title.upper(), self.main_loc.parish.upper(),
|
|
|
|
self.main_loc.city.upper(), self.main_loc.county.upper(),
|
|
|
|
self.main_loc.state.upper(), self.main_loc.country.upper()]
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-01-19 11:55:20 +05:30
|
|
|
return [self.title,self.id,'','','','','',self.title.upper(), '','','','','']
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Researcher
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class Researcher:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Contains the information about the owner of the database"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initializes the Researcher object"""
|
|
|
|
self.name = ""
|
|
|
|
self.addr = ""
|
|
|
|
self.city = ""
|
|
|
|
self.state = ""
|
|
|
|
self.country = ""
|
|
|
|
self.postal = ""
|
|
|
|
self.phone = ""
|
|
|
|
self.email = ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's name"""
|
|
|
|
return self.name
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_address(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's address"""
|
|
|
|
return self.addr
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_city(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's city"""
|
|
|
|
return self.city
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_state(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's state"""
|
|
|
|
return self.state
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_country(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's country"""
|
|
|
|
return self.country
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_postal_code(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's postal code"""
|
|
|
|
return self.postal
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_phone(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's phone number"""
|
|
|
|
return self.phone
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_email(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the database owner's email"""
|
|
|
|
return self.email
|
|
|
|
|
|
|
|
def set(self,name,addr,city,state,country,postal,phone,email):
|
|
|
|
"""sets the information about the database owner"""
|
|
|
|
if name:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.name = name.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if addr:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.addr = addr.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if city:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.city = city.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if state:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.state = state.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if country:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.country = country.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if postal:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.postal = postal.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if phone:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.phone = phone.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
if email:
|
2003-12-30 00:07:44 +05:30
|
|
|
self.email = email.strip()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Location
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class Location:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Provides information about a place, including city, county, state,
|
|
|
|
and country. Multiple Location objects can represent the same place,
|
|
|
|
since names of citys, countys, states, and even countries can change
|
|
|
|
with time"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a Location object, copying from the source object if it exists"""
|
|
|
|
if source:
|
|
|
|
self.city = source.city
|
|
|
|
self.parish = source.parish
|
|
|
|
self.county = source.county
|
|
|
|
self.state = source.state
|
|
|
|
self.country = source.country
|
2003-12-09 11:30:51 +05:30
|
|
|
self.postal = source.postal
|
|
|
|
self.phone = source.phone
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.city = ""
|
|
|
|
self.parish = ""
|
|
|
|
self.county = ""
|
|
|
|
self.state = ""
|
|
|
|
self.country = ""
|
2003-12-09 11:30:51 +05:30
|
|
|
self.postal = ""
|
|
|
|
self.phone = ""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def is_empty(self):
|
2004-05-20 05:42:14 +05:30
|
|
|
return not self.city and not self.county and not self.state and not self.country and not self.postal and not self.phone
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_city(self,data):
|
|
|
|
"""sets the city name of the Location object"""
|
|
|
|
self.city = data
|
|
|
|
|
2003-12-09 11:30:51 +05:30
|
|
|
def get_postal_code(self):
|
|
|
|
"""returns the postal code of the Location object"""
|
|
|
|
return self.postal
|
|
|
|
|
|
|
|
def set_postal_code(self,data):
|
|
|
|
"""sets the postal code of the Location object"""
|
|
|
|
self.postal = data
|
|
|
|
|
|
|
|
def get_phone(self):
|
|
|
|
"""returns the phone number of the Location object"""
|
|
|
|
return self.phone
|
|
|
|
|
|
|
|
def set_phone(self,data):
|
|
|
|
"""sets the phone number of the Location object"""
|
|
|
|
self.phone = data
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def get_city(self):
|
|
|
|
"""returns the city name of the Location object"""
|
|
|
|
return self.city
|
|
|
|
|
|
|
|
def set_parish(self,data):
|
|
|
|
"""sets the religious parish name"""
|
|
|
|
self.parish = data
|
|
|
|
|
|
|
|
def get_parish(self):
|
|
|
|
"""gets the religious parish name"""
|
|
|
|
return self.parish
|
|
|
|
|
|
|
|
def set_county(self,data):
|
|
|
|
"""sets the county name of the Location object"""
|
|
|
|
self.county = data
|
|
|
|
|
|
|
|
def get_county(self):
|
|
|
|
"""returns the county name of the Location object"""
|
|
|
|
return self.county
|
|
|
|
|
|
|
|
def set_state(self,data):
|
|
|
|
"""sets the state name of the Location object"""
|
|
|
|
self.state = data
|
|
|
|
|
|
|
|
def get_state(self):
|
|
|
|
"""returns the state name of the Location object"""
|
|
|
|
return self.state
|
|
|
|
|
|
|
|
def set_country(self,data):
|
|
|
|
"""sets the country name of the Location object"""
|
|
|
|
self.country = data
|
|
|
|
|
|
|
|
def get_country(self):
|
|
|
|
"""returns the country name of the Location object"""
|
|
|
|
return self.country
|
|
|
|
|
2003-11-02 01:25:30 +05:30
|
|
|
class Note:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Provides general text information"""
|
|
|
|
|
|
|
|
def __init__(self,text = ""):
|
|
|
|
"""create a new Note object from the passed string"""
|
|
|
|
self.text = text
|
2003-12-10 09:19:53 +05:30
|
|
|
self.format = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set(self,text):
|
|
|
|
"""set the note contents to the passed string"""
|
|
|
|
self.text = text
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
"""return the note contents"""
|
|
|
|
return self.text
|
|
|
|
|
|
|
|
def append(self,text):
|
|
|
|
"""adds the text to the note's contents"""
|
|
|
|
self.text = self.text + text
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_format(self,format):
|
2003-12-10 09:19:53 +05:30
|
|
|
"""set the format to the passed value"""
|
|
|
|
self.format = format
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_format(self):
|
2003-12-10 09:19:53 +05:30
|
|
|
"""return the note's format"""
|
|
|
|
return self.format
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# MediaObject
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-02-21 11:41:59 +05:30
|
|
|
class MediaObject(SourceNote):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Containter for information about an image file, including location,
|
|
|
|
description and privacy"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""Create a new MediaObject object, copying from the source if provided"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
SourceNote.__init__(self,source)
|
|
|
|
|
|
|
|
self.attrlist = []
|
|
|
|
if source:
|
|
|
|
self.path = source.path
|
|
|
|
self.mime = source.mime
|
|
|
|
self.desc = source.desc
|
|
|
|
self.id = source.id
|
2004-03-01 10:03:36 +05:30
|
|
|
self.thumb = source.thumb
|
2002-10-20 19:55:16 +05:30
|
|
|
for attr in source.attrlist:
|
|
|
|
self.attrlist.append(Attribute(attr))
|
|
|
|
else:
|
|
|
|
self.id = ""
|
|
|
|
self.path = ""
|
|
|
|
self.mime = ""
|
|
|
|
self.desc = ""
|
2004-03-01 10:03:36 +05:30
|
|
|
self.thumb = None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def serialize(self):
|
2004-03-01 10:03:36 +05:30
|
|
|
return (self.id, self.path, self.mime, self.desc, self.attrlist,
|
2004-02-21 11:41:59 +05:30
|
|
|
self.source_list, self.note)
|
|
|
|
|
|
|
|
def unserialize(self,data):
|
2004-03-01 10:26:50 +05:30
|
|
|
try:
|
|
|
|
(self.id, self.path, self.mime, self.desc, self.attrlist,
|
|
|
|
self.source_list, self.note) = data
|
|
|
|
except:
|
|
|
|
(self.id, junk, self.path, self.mime, self.desc, self.attrlist,
|
|
|
|
self.source_list, self.note) = data
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_id(self,gid):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the gramps ID for the place object"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = gid
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the gramps ID for the place object"""
|
|
|
|
return self.id
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_mime_type(self,type):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.mime = type
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_mime_type(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.mime
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_path(self,path):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""set the file path to the passed path"""
|
|
|
|
self.path = os.path.normpath(path)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_path(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""return the file path"""
|
|
|
|
return self.path
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_description(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the description of the image"""
|
|
|
|
self.desc = text
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_description(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the description of the image"""
|
|
|
|
return self.desc
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_attribute(self,attr):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""Adds a propery to the MediaObject object. This is not used by gramps,
|
2002-10-20 19:55:16 +05:30
|
|
|
but provides a means for XML users to attach other properties to
|
|
|
|
the image"""
|
|
|
|
self.attrlist.append(attr)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_attribute_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the property list associated with the image"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.attrlist
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_attribute_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attrlist = list
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# MediaRef
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-06-03 11:05:30 +05:30
|
|
|
class MediaRef(SourceNote):
|
|
|
|
"""Media reference class"""
|
2002-10-20 19:55:16 +05:30
|
|
|
def __init__(self,source=None):
|
2004-06-03 11:05:30 +05:30
|
|
|
|
|
|
|
SourceNote.__init__(self,source)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.attrlist = []
|
|
|
|
if source:
|
|
|
|
self.private = source.private
|
|
|
|
self.ref = source.ref
|
|
|
|
self.note = Note(source.note)
|
|
|
|
for attr in source.attrlist:
|
|
|
|
self.attrlist.append(Attribute(attr))
|
|
|
|
else:
|
|
|
|
self.private = 0
|
|
|
|
self.ref = None
|
|
|
|
self.note = None
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_privacy(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets or clears the privacy flag of the data"""
|
|
|
|
self.private = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_privacy(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the privacy level of the data"""
|
|
|
|
return self.private
|
|
|
|
|
2004-02-25 08:55:57 +05:30
|
|
|
def set_reference_id(self,obj_id):
|
|
|
|
self.ref = obj_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-25 08:55:57 +05:30
|
|
|
def get_reference_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.ref
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_attribute(self,attr):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""Adds a propery to the MediaObject object. This is not used by gramps,
|
2002-10-20 19:55:16 +05:30
|
|
|
but provides a means for XML users to attach other properties to
|
|
|
|
the image"""
|
|
|
|
self.attrlist.append(attr)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_attribute_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the property list associated with the image"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.attrlist
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_attribute_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the property list associated with the image"""
|
|
|
|
self.attrlist = list
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Attribute
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class Attribute(DataObj):
|
|
|
|
"""Provides a simple key/value pair for describing properties. Used
|
|
|
|
by the Person and Family objects to store descriptive information."""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a new Attribute object, copying from the source if provided"""
|
|
|
|
DataObj.__init__(self,source)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
self.type = source.type
|
|
|
|
self.value = source.value
|
|
|
|
else:
|
|
|
|
self.type = ""
|
|
|
|
self.value = ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_type(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the type (or key) of the Attribute instance"""
|
|
|
|
self.type = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_type(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the type (or key) or the Attribute instance"""
|
|
|
|
return self.type
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_value(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the value of the Attribute instance"""
|
|
|
|
self.value = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_value(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the value of the Attribute instance"""
|
|
|
|
return self.value
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Address
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class Address(DataObj):
|
|
|
|
"""Provides address information for a person"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""Creates a new Address instance, copying from the source
|
|
|
|
if provided"""
|
|
|
|
DataObj.__init__(self,source)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
self.street = source.street
|
|
|
|
self.city = source.city
|
|
|
|
self.state = source.state
|
|
|
|
self.country = source.country
|
|
|
|
self.postal = source.postal
|
|
|
|
self.date = Date(source.date)
|
2003-12-09 11:30:51 +05:30
|
|
|
self.phone = source.phone
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.street = ""
|
|
|
|
self.city = ""
|
|
|
|
self.state = ""
|
|
|
|
self.country = ""
|
|
|
|
self.postal = ""
|
|
|
|
self.date = Date()
|
2003-12-09 11:30:51 +05:30
|
|
|
self.phone = ""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""attempts to sets the date that the person lived at the address
|
|
|
|
from the passed string"""
|
|
|
|
self.date.set(text)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date that the person
|
|
|
|
lived at the address"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_preferred_date(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date that the person
|
|
|
|
lived at the address"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_preferred_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date_object(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Date object associated with the Address"""
|
|
|
|
return self.date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date_object(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Date object associated with the Address"""
|
|
|
|
self.date = obj
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_street(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the street portion of the Address"""
|
|
|
|
self.street = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_street(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the street portion of the Address"""
|
|
|
|
return self.street
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_phone(self,val):
|
2003-12-09 11:30:51 +05:30
|
|
|
"""sets the phone number portion of the Address"""
|
|
|
|
self.phone = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_phone(self):
|
2003-12-09 11:30:51 +05:30
|
|
|
"""returns the phone number portion of the Address"""
|
|
|
|
return self.phone
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_city(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the city portion of the Address"""
|
|
|
|
self.city = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_city(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the city portion of the Address"""
|
|
|
|
return self.city
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_state(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the state portion of the Address"""
|
|
|
|
self.state = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_state(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the state portion of the Address"""
|
|
|
|
return self.state
|
|
|
|
|
|
|
|
def setCountry(self,val):
|
|
|
|
"""sets the country portion of the Address"""
|
|
|
|
self.country = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_country(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the country portion of the Address"""
|
|
|
|
return self.country
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_postal_code(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the postal code of the Address"""
|
|
|
|
self.postal = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_postal_code(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the postal code of the Address"""
|
|
|
|
return self.postal
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Name
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class Name(DataObj):
|
|
|
|
"""Provides name information about a person. A person may have more
|
|
|
|
that one name throughout his or her life."""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a new Name instance, copying from the source if provided"""
|
|
|
|
DataObj.__init__(self,source)
|
|
|
|
|
|
|
|
if source:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.first_name = source.first_name
|
|
|
|
self.surname = source.surname
|
|
|
|
self.suffix = source.suffix
|
|
|
|
self.title = source.title
|
2002-10-20 19:55:16 +05:30
|
|
|
self.type = source.type
|
2004-02-14 11:10:30 +05:30
|
|
|
self.prefix = source.prefix
|
2004-01-07 10:35:42 +05:30
|
|
|
self.sname = source.sname
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.first_name = ""
|
|
|
|
self.surname = ""
|
|
|
|
self.suffix = ""
|
|
|
|
self.title = ""
|
2003-03-14 11:16:02 +05:30
|
|
|
self.type = "Birth Name"
|
2004-02-14 11:10:30 +05:30
|
|
|
self.prefix = ""
|
2004-01-07 10:35:42 +05:30
|
|
|
self.sname = '@'
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_surname_prefix(self):
|
|
|
|
return self.prefix
|
2002-12-04 10:28:07 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_surname_prefix(self,val):
|
|
|
|
self.prefix = val
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_type(self,type):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the type of the Name instance"""
|
|
|
|
self.type = type
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_type(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the type of the Name instance"""
|
|
|
|
return self.type
|
|
|
|
|
2004-01-07 10:35:42 +05:30
|
|
|
def build_sort_name(self):
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.surname:
|
|
|
|
self.sname = "%-25s%-30s%s" % (self.surname.upper(),self.first_name.upper(),self.suffix.upper())
|
2004-01-07 10:35:42 +05:30
|
|
|
else:
|
|
|
|
self.sname = "@"
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_first_name(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the given name for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.first_name = name
|
2004-01-07 10:35:42 +05:30
|
|
|
self.build_sort_name()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_surname(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the surname (or last name) for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.surname = name
|
2004-01-07 10:35:42 +05:30
|
|
|
self.build_sort_name()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_suffix(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the suffix (such as Jr., III, etc.) for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.suffix = name
|
2004-01-07 10:35:42 +05:30
|
|
|
self.build_sort_name()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_sort_name(self):
|
2004-01-07 10:35:42 +05:30
|
|
|
return self.sname
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_first_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the given name for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.first_name
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_surname(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the surname (or last name) for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.surname
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_upper_surname(self):
|
2003-10-12 09:56:00 +05:30
|
|
|
"""returns the surname (or last name) for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.surname.upper()
|
2003-10-12 09:56:00 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_suffix(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the suffix for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.suffix
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_title(self,title):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the title (Dr., Reverand, Captain) for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.title = title
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_title(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the title for the Name instance"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.title
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
2004-02-14 11:10:30 +05:30
|
|
|
instance, in the form of surname, Firstname"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.suffix:
|
|
|
|
if self.prefix:
|
|
|
|
return "%s %s, %s %s" % (self.prefix, self.surname, self.first_name, self.suffix)
|
2002-12-04 10:28:07 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s, %s %s" % (self.surname, self.first_name, self.suffix)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.prefix:
|
|
|
|
return "%s %s, %s" % (self.prefix,self.surname, self.first_name)
|
2002-12-04 10:28:07 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s, %s" % (self.surname, self.first_name)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_upper_name(self):
|
2003-10-12 09:56:00 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
2004-02-14 11:10:30 +05:30
|
|
|
instance, in the form of surname, Firstname"""
|
2003-10-12 09:56:00 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.suffix:
|
|
|
|
if self.prefix:
|
|
|
|
return "%s %s, %s %s" % (self.prefix.upper(), self.surname.upper(), self.first_name, self.suffix)
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s, %s %s" % (self.surname.upper(), self.first_name, self.suffix)
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.prefix:
|
|
|
|
return "%s %s, %s" % (self.prefix.upper(), self.surname.upper(), self.first_name)
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s, %s" % (self.surname.upper(), self.first_name)
|
2003-10-12 09:56:00 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_regular_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
2004-02-14 11:10:30 +05:30
|
|
|
instance, in the form of Firstname surname"""
|
|
|
|
if (self.suffix == ""):
|
|
|
|
if self.prefix:
|
|
|
|
return "%s %s %s" % (self.first_name, self.prefix, self.surname)
|
2003-03-16 00:21:30 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s %s" % (self.first_name, self.surname)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.prefix:
|
|
|
|
return "%s %s %s, %s" % (self.first_name, self.prefix, self.surname, self.suffix)
|
2003-03-16 00:21:30 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s %s, %s" % (self.first_name, self.surname, self.suffix)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_regular_upper_name(self):
|
2003-10-12 09:56:00 +05:30
|
|
|
"""returns a name string built from the components of the Name
|
2004-02-14 11:10:30 +05:30
|
|
|
instance, in the form of Firstname surname"""
|
|
|
|
if (self.suffix == ""):
|
|
|
|
if self.prefix:
|
|
|
|
return "%s %s %s" % (self.first_name, self.prefix.upper(), self.surname.upper())
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s %s" % (self.first_name, self.surname.upper())
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.prefix:
|
|
|
|
return "%s %s %s, %s" % (self.first_name, self.prefix.upper(), self.surname.upper(), self.suffix)
|
2003-10-12 09:56:00 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return "%s %s, %s" % (self.first_name, self.surname.upper(), self.suffix)
|
2003-10-12 09:56:00 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def are_equal(self,other):
|
|
|
|
"""compares to names to see if they are equal, return 0 if they
|
|
|
|
are not"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.first_name != other.first_name:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.surname != other.surname:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.prefix != other.prefix:
|
2003-04-20 09:22:54 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.suffix != other.suffix:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.title != other.title:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
if self.type != other.type:
|
|
|
|
return 0
|
|
|
|
if self.private != other.private:
|
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.get_note() != other.get_note():
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if len(self.get_source_references()) != len(other.get_source_references()):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
index = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
olist = other.get_source_references()
|
|
|
|
for a in self.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
if not a.are_equal(olist[index]):
|
|
|
|
return 0
|
|
|
|
index = index + 1
|
|
|
|
return 1
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Url
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class Url:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Contains information related to internet Uniform Resource Locators,
|
|
|
|
allowing gramps to store information about internet resources"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a new URL instance, copying from the source if present"""
|
|
|
|
if source:
|
|
|
|
self.path = source.path
|
|
|
|
self.desc = source.desc
|
|
|
|
self.private = source.private
|
|
|
|
else:
|
|
|
|
self.path = ""
|
|
|
|
self.desc = ""
|
|
|
|
self.private = 0
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_privacy(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the privacy flag for the URL instance"""
|
|
|
|
self.private = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_privacy(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the privacy flag for the URL instance"""
|
|
|
|
return self.private
|
|
|
|
|
|
|
|
def set_path(self,path):
|
|
|
|
"""sets the URL path"""
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
def get_path(self):
|
|
|
|
"""returns the URL path"""
|
|
|
|
return self.path
|
|
|
|
|
|
|
|
def set_description(self,description):
|
|
|
|
"""sets the description of the URL"""
|
|
|
|
self.desc = description
|
|
|
|
|
|
|
|
def get_description(self):
|
|
|
|
"""returns the description of the URL"""
|
|
|
|
return self.desc
|
|
|
|
|
|
|
|
def are_equal(self,other):
|
|
|
|
"""returns 1 if the specified URL is the same as the instance"""
|
|
|
|
if other == None:
|
|
|
|
return 0
|
|
|
|
if self.path != other.path:
|
|
|
|
return 0
|
|
|
|
if self.desc != other.desc:
|
|
|
|
return 0
|
|
|
|
return 1
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Person
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-10-29 10:34:43 +05:30
|
|
|
class Person(SourceNote):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Represents an individual person in the gramps database"""
|
|
|
|
|
|
|
|
unknown = 2
|
|
|
|
male = 1
|
|
|
|
female = 0
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def __init__(self,gid=""):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""creates a new Person instance"""
|
2003-10-29 10:34:43 +05:30
|
|
|
SourceNote.__init__(self)
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = gid
|
2004-06-27 08:40:06 +05:30
|
|
|
self.gid = ""
|
2004-02-21 11:41:59 +05:30
|
|
|
self.primary_name = Name()
|
2004-02-14 11:10:30 +05:30
|
|
|
self.event_list = []
|
|
|
|
self.family_list = []
|
|
|
|
self.parent_family_list = []
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.nickname = ""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.alternate_names = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.gender = 2
|
2004-02-19 10:35:43 +05:30
|
|
|
self.death_id = None
|
|
|
|
self.birth_id = None
|
2004-02-14 11:10:30 +05:30
|
|
|
self.address_list = []
|
|
|
|
self.attribute_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.urls = []
|
|
|
|
self.ancestor = None
|
|
|
|
self.lds_bapt = None
|
|
|
|
self.lds_endow = None
|
|
|
|
self.lds_seal = None
|
2003-12-03 09:19:39 +05:30
|
|
|
self.complete = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-24 19:46:47 +05:30
|
|
|
# We hold a reference to the GrampsDB so that we can maintain
|
|
|
|
# its genderStats. It doesn't get set here, but from
|
|
|
|
# GenderStats.count_person.
|
|
|
|
self.db = None
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def serialize(self):
|
2004-06-27 08:40:06 +05:30
|
|
|
return (self.id, self.gid, self.gender,
|
2004-02-14 11:10:30 +05:30
|
|
|
self.primary_name, self.alternate_names, self.nickname,
|
2004-02-19 10:35:43 +05:30
|
|
|
self.death_id, self.birth_id, self.event_list,
|
2004-02-14 11:10:30 +05:30
|
|
|
self.family_list, self.parent_family_list,
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list,
|
2004-02-14 11:10:30 +05:30
|
|
|
self.address_list,
|
|
|
|
self.attribute_list,
|
|
|
|
self.urls,
|
|
|
|
self.lds_bapt, self.lds_endow, self.lds_seal,
|
2004-02-21 11:41:59 +05:30
|
|
|
self.complete,
|
|
|
|
self.source_list,
|
|
|
|
self.note)
|
|
|
|
|
|
|
|
def unserialize(self,data):
|
2004-07-12 05:23:02 +05:30
|
|
|
try:
|
|
|
|
(self.id, self.gid, self.gender,
|
|
|
|
self.primary_name, self.alternate_names, self.nickname,
|
|
|
|
self.death_id, self.birth_id, self.event_list,
|
|
|
|
self.family_list, self.parent_family_list,
|
|
|
|
self.media_list,
|
|
|
|
self.address_list,
|
|
|
|
self.attribute_list,
|
|
|
|
self.urls,
|
|
|
|
self.lds_bapt, self.lds_endow, self.lds_seal,
|
|
|
|
self.complete, self.source_list, self.note) = data
|
|
|
|
except:
|
|
|
|
print data
|
2004-07-09 10:01:43 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_complete(self,val):
|
2003-12-03 09:19:39 +05:30
|
|
|
self.complete = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_complete(self):
|
2003-12-03 09:19:39 +05:30
|
|
|
return self.complete
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_display_info(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.gender == Person.male:
|
|
|
|
gender = const.male
|
|
|
|
elif self.gender == Person.female:
|
|
|
|
gender = const.female
|
|
|
|
else:
|
|
|
|
gender = const.unknown
|
2004-02-19 10:35:43 +05:30
|
|
|
bday = self.birth_id
|
|
|
|
dday = self.death_id
|
2004-07-15 08:24:04 +05:30
|
|
|
return [ GrampsCfg.get_display_name()(self),
|
2004-06-27 08:40:06 +05:30
|
|
|
self.gid,
|
2004-02-19 10:35:43 +05:30
|
|
|
gender,
|
|
|
|
bday,
|
|
|
|
dday,
|
2004-02-14 11:10:30 +05:30
|
|
|
self.get_primary_name().get_sort_name(),
|
2004-02-19 10:35:43 +05:30
|
|
|
bday, dday,
|
2004-07-15 08:24:04 +05:30
|
|
|
GrampsCfg.get_display_surname()(self.primary_name)]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_primary_name(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the primary name of the Person to the specified
|
|
|
|
Name instance"""
|
2003-06-24 19:46:47 +05:30
|
|
|
db = self.db
|
|
|
|
if db:
|
|
|
|
db.genderStats.uncount_person (self)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
self.primary_name = name
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-06-24 19:46:47 +05:30
|
|
|
if db:
|
|
|
|
db.genderStats.count_person (self, db)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_primary_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Name instance marked as the Person's primary name"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if not self.primary_name:
|
|
|
|
self.primary_name = Name()
|
|
|
|
return self.primary_name
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_alternate_names(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of alternate Names"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.alternate_names
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_alternate_names(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""changes the list of alternate names to the passed list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.alternate_names = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_alternate_name(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an alternate Name instance to the list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.alternate_names.append(name)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_url_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of URL instances"""
|
2003-11-02 01:25:30 +05:30
|
|
|
return self.urls
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_url_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the list of URL instances to list"""
|
|
|
|
self.urls = list
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_url(self,url):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a URL instance to the list"""
|
|
|
|
self.urls.append(url)
|
|
|
|
|
2004-06-27 08:40:06 +05:30
|
|
|
def set_gramps_id(self,gid):
|
|
|
|
"""sets the gramps ID for the Person"""
|
|
|
|
self.gid = str(gid)
|
|
|
|
|
|
|
|
def get_gramps_id(self):
|
|
|
|
"""returns the gramps ID for the Person"""
|
|
|
|
return self.gid
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_id(self,gid):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the gramps ID for the Person"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = str(gid)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the gramps ID for the Person"""
|
|
|
|
return self.id
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_nick_name(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the nickname for the Person"""
|
|
|
|
self.nickname = name
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_nick_name(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the nickname for the Person"""
|
|
|
|
return self.nickname
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_gender(self,val) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the gender of the Person"""
|
2003-06-24 19:46:47 +05:30
|
|
|
db = self.db
|
|
|
|
if db:
|
|
|
|
db.genderStats.uncount_person (self)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.gender = val
|
|
|
|
|
2003-06-24 19:46:47 +05:30
|
|
|
if db:
|
|
|
|
db.genderStats.count_person (self, db)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_gender(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the gender of the Person"""
|
|
|
|
return self.gender
|
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def set_birth_id(self,event_id) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the birth event to the passed event"""
|
2004-02-19 10:35:43 +05:30
|
|
|
self.birth_id = event_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def set_death_id(self,event_id) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the death event to the passed event"""
|
2004-02-19 10:35:43 +05:30
|
|
|
self.death_id = event_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def get_birth_id(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the birth event"""
|
2004-02-19 10:35:43 +05:30
|
|
|
return self.birth_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def get_death_id(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the death event"""
|
2004-02-19 10:35:43 +05:30
|
|
|
return self.death_id
|
|
|
|
|
|
|
|
# def get_valid_death(self):
|
|
|
|
# e = self.death
|
|
|
|
# if e == None:
|
|
|
|
# return None
|
|
|
|
# if e.place == None and (e.date == None or not e.date.getValid()) and \
|
|
|
|
# e.description == "" and e.cause == "" and e.witness == None:
|
|
|
|
# return None
|
|
|
|
# else:
|
|
|
|
# return e
|
|
|
|
|
|
|
|
# def get_valid_birth(self):
|
|
|
|
# e = self.birth
|
|
|
|
# if e == None:
|
|
|
|
# return None
|
|
|
|
# if e.place == None and (e.date == None or not e.date.getValid()) and \
|
|
|
|
# e.description == "" and e.cause == "" and e.witness == None:
|
|
|
|
# return None
|
|
|
|
# else:
|
|
|
|
# return e
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2004-02-22 10:27:06 +05:30
|
|
|
def add_media_reference(self,media_id):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""adds a MediaObject instance to the image list"""
|
2004-02-22 10:27:06 +05:30
|
|
|
self.media_list.append(media_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def get_media_list(self):
|
|
|
|
"""returns the list of MediaObjects"""
|
|
|
|
return self.media_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def set_media_list(self,list):
|
|
|
|
"""Sets the list of MediaObject objects"""
|
|
|
|
self.media_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def add_event_id(self,event_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Event to the event list"""
|
2004-02-19 10:35:43 +05:30
|
|
|
self.event_list.append(event_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_event_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of Event instances"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.event_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def set_event_list(self,elist):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the event list to the passed list"""
|
2004-05-14 04:15:51 +05:30
|
|
|
self.event_list = elist
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_family_id(self,family_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds the specified Family instance to the list of
|
|
|
|
families/marriages/partnerships in which the person is a
|
|
|
|
parent or spouse"""
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
self.family_list.append(family_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_preferred_family_id(self,family):
|
|
|
|
if family in self.family_list:
|
|
|
|
self.family_list.remove(family)
|
|
|
|
self.family_list = [family] + self.family_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_family_id_list(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of Family instances in which the
|
|
|
|
person is a parent or spouse"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.family_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def clear_family_id_list(self) :
|
|
|
|
self.family_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def remove_family_id(self,family):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes the specified Family instance from the list
|
|
|
|
of marriages/partnerships"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
if family in self.family_list:
|
|
|
|
self.family_list.remove(family)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_address(self,address):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds the Address instance to the list of addresses"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.address_list.append(address)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def remove_address(self,address):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes the Address instance from the list of addresses"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if address in self.address_list:
|
|
|
|
self.address_list.remove(address)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_address_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of addresses"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.address_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-14 04:15:51 +05:30
|
|
|
def set_address_list(self,alist):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the address list to the specified list"""
|
2004-05-14 04:15:51 +05:30
|
|
|
self.address_list = alist
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_attribute(self,attribute):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Attribute instance to the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.attribute_list.append(attribute)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def remove_attribute(self,attribute):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes the specified Attribute instance from the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if attribute in self.attribute_list:
|
|
|
|
self.attribute_list.remove(attribute)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_attribute_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.attribute_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_attribute_list(self,list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the attribute list to the specified list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.attribute_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_parent_family_id_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of alternate Family instances, in which the Person
|
|
|
|
is a child of the family, but not a natural child of both parents"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.parent_family_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_parent_family_id(self,family,mrel,frel):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Family to the alternate family list, indicating the
|
|
|
|
relationship to the mother (mrel) and the father (frel)"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
self.parent_family_list.append((family,mrel,frel))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def clear_parent_family_id_list(self):
|
|
|
|
self.parent_family_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def remove_parent_family_id(self,family):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes a Family instance from the alternate family list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
for f in self.parent_family_list[:]:
|
|
|
|
assert(type(f[0]) == types.StringType or type(f[0]) == types.UnicodeType)
|
2002-10-20 19:55:16 +05:30
|
|
|
if f[0] == family:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.parent_family_list.remove(f)
|
2002-10-20 19:55:16 +05:30
|
|
|
return f
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def change_parent_family_id(self,family,mrel,frel):
|
2003-06-17 09:45:58 +05:30
|
|
|
"""removes a Family instance from the alternate family list"""
|
|
|
|
index = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
for f in self.parent_family_list[:]:
|
2003-06-17 09:45:58 +05:30
|
|
|
if f[0] == family:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.parent_family_list[index] = (family,mrel,frel)
|
2003-06-17 09:45:58 +05:30
|
|
|
index += 1
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def has_family(self,family):
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
for f in self.parent_family_list:
|
|
|
|
assert(type(f[0]) == types.StringType or type(f[0]) == types.UnicodeType)
|
2002-10-20 19:55:16 +05:30
|
|
|
if f[0] == family:
|
|
|
|
return f
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_main_parent_family_id(self,family):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the main Family of the Person, the Family in which the
|
|
|
|
Person is a natural born child"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(family) == types.StringType or type(family) == types.UnicodeType)
|
|
|
|
f = self.remove_parent_family_id(family)
|
2002-10-20 19:55:16 +05:30
|
|
|
if f:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.parent_family_list = [f] + self.parent_family_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_main_parents_family_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the main Family of the Person, the Family in which the
|
|
|
|
Person is a natural born child"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if len(self.parent_family_list) == 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
return None
|
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.parent_family_list[0][0]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_main_parents_family_idRel(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the main Family of the Person, the Family in which the
|
|
|
|
Person is a natural born child"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if len(self.parent_family_list) == 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
return (None,None,None)
|
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.parent_family_list[0]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_ancestor(self, value):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""set ancestor flag and recurse"""
|
|
|
|
self.ancestor = value
|
2004-02-14 11:10:30 +05:30
|
|
|
# for (fam,m,f) in self.parent_family_list:
|
|
|
|
# family
|
|
|
|
# if family.Father:
|
|
|
|
# # Don't waste time if the ancestor is already flagged.
|
|
|
|
# # This will happen when cousins marry.
|
|
|
|
# if not family.Father.get_ancestor():
|
|
|
|
# family.Father.set_ancestor(value)
|
|
|
|
# if family.get_mother_id():
|
|
|
|
# if not family.Mother.get_ancestor():
|
|
|
|
# family.Mother.set_ancestor(value)
|
|
|
|
|
|
|
|
def get_ancestor(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.ancestor
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_lds_baptism(self,ord):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lds_bapt = ord
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_lds_baptism(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.lds_bapt
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_lds_endowment(self,ord):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lds_endow = ord
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_lds_endowment(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.lds_endow
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_lds_sealing(self,ord):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lds_seal = ord
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_lds_sealing(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.lds_seal
|
|
|
|
|
2004-03-11 09:54:03 +05:30
|
|
|
def probably_alive(self,db):
|
2003-07-21 16:50:31 +05:30
|
|
|
"""Returns true if the person may be alive."""
|
2004-03-11 09:54:03 +05:30
|
|
|
if self.death_id:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-03-11 09:54:03 +05:30
|
|
|
if self.birth_id:
|
|
|
|
birth = db.find_event_from_id(self.birth_id)
|
|
|
|
if birth.get_date() != "":
|
|
|
|
return not_too_old(birth.get_date_object().get_start_date())
|
2003-07-21 16:50:31 +05:30
|
|
|
|
|
|
|
# Neither birth nor death events are available. Try looking
|
|
|
|
# for descendants that were born more than a lifespan ago.
|
|
|
|
|
|
|
|
min_generation = 13
|
2003-07-22 16:22:55 +05:30
|
|
|
max_generation = 60
|
|
|
|
max_age_difference = 60
|
2003-07-21 16:50:31 +05:30
|
|
|
def descendants_too_old (person, years):
|
2004-03-11 09:54:03 +05:30
|
|
|
for family_id in person.get_family_id_list():
|
|
|
|
family = db.find_family_from_id(family_id)
|
|
|
|
for child_id in family.get_child_id_list():
|
|
|
|
child = db.find_person_from_id(child_id)
|
|
|
|
if child.birth_id:
|
|
|
|
child_birth = db.find_event_from_id(child.birth_id)
|
|
|
|
if child_birth.get_date () != "":
|
|
|
|
d = SingleDate (child_birth.get_date_object ().
|
2003-07-21 16:50:31 +05:30
|
|
|
get_start_date ())
|
2004-05-13 23:42:37 +05:30
|
|
|
d.set_year (d.get_year () - years)
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
if child.death_id:
|
|
|
|
child_death = db.find_event_from_id(child.death_id)
|
|
|
|
if child_death.get_date () != "":
|
|
|
|
d = SingleDate (child_death.get_date_object ().
|
2003-07-21 16:50:31 +05:30
|
|
|
get_start_date ())
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 1
|
2003-07-21 16:50:31 +05:30
|
|
|
|
|
|
|
if descendants_too_old (child, years + min_generation):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
if descendants_too_old (self, min_generation):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# What about their parents?
|
2003-07-22 16:22:55 +05:30
|
|
|
def parents_too_old (person, age_difference):
|
2004-03-11 09:54:03 +05:30
|
|
|
family_id = person.get_main_parents_family_id ()
|
|
|
|
if family_id:
|
|
|
|
family = db.find_family_from_id(family_id)
|
|
|
|
for parent_id in [family.get_father_id (), family.get_mother_id ()]:
|
|
|
|
if not parent_id:
|
2003-07-22 16:22:55 +05:30
|
|
|
continue
|
|
|
|
|
2004-03-11 09:54:03 +05:30
|
|
|
parent = db.find_person_from_id(parent_id)
|
|
|
|
if parent.birth_id:
|
|
|
|
parent_birth = db.find_event_from_id(parent.birth_id)
|
2004-05-13 23:42:37 +05:30
|
|
|
if parent_birth.get_date ():
|
|
|
|
d = SingleDate (parent_birth.get_date_object ().
|
2003-07-22 16:22:55 +05:30
|
|
|
get_start_date ())
|
2004-05-13 23:42:37 +05:30
|
|
|
d.set_year (d.get_year () + max_generation +
|
2003-07-22 16:22:55 +05:30
|
|
|
age_difference)
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 1
|
2003-07-21 16:50:31 +05:30
|
|
|
|
2004-03-11 09:54:03 +05:30
|
|
|
if parent.death_id:
|
|
|
|
parent_death = db.find_event_from_id(parent.death_id)
|
|
|
|
if parent_death.get_date () != "":
|
2004-05-13 23:42:37 +05:30
|
|
|
d = SingleDate (parent_death.get_date_object ().
|
2003-07-22 16:22:55 +05:30
|
|
|
get_start_date ())
|
2004-05-13 23:42:37 +05:30
|
|
|
d.set_year (d.get_year () + age_difference)
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 1
|
2003-07-22 16:22:55 +05:30
|
|
|
|
|
|
|
if parents_too_old (self, 0):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# As a last resort, trying seeing if their spouse's age gives
|
|
|
|
# any clue.
|
2004-03-11 09:54:03 +05:30
|
|
|
for family_id in self.get_family_id_list ():
|
|
|
|
family = db.find_family_from_id(family_id)
|
|
|
|
for spouse_id in [family.get_father_id (), family.get_mother_id ()]:
|
|
|
|
if not spouse_id:
|
2003-07-22 16:22:55 +05:30
|
|
|
continue
|
2004-03-11 09:54:03 +05:30
|
|
|
if spouse_id == self.id:
|
2003-07-22 16:22:55 +05:30
|
|
|
continue
|
2004-03-11 09:54:03 +05:30
|
|
|
spouse = db.find_person_from_id(spouse_id)
|
|
|
|
if spouse.birth_id:
|
|
|
|
spouse_birth = db.find_event_from_id(spouse.birth_id)
|
|
|
|
if spouse_birth.get_date () != "":
|
2004-05-13 23:42:37 +05:30
|
|
|
d = SingleDate (spouse_birth.get_date_object().
|
2003-07-21 16:50:31 +05:30
|
|
|
get_start_date ())
|
2004-05-13 23:42:37 +05:30
|
|
|
d.set_year (d.get_year () + max_age_difference)
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 0
|
2003-07-21 16:50:31 +05:30
|
|
|
|
2004-03-11 09:54:03 +05:30
|
|
|
if spouse.death_id:
|
|
|
|
spouse_death = db.find_event_from_id(spouse.death_id)
|
|
|
|
if spouse_death.get_date () != "":
|
2004-05-13 23:42:37 +05:30
|
|
|
d = SingleDate (spouse_birth.get_date_object().
|
2003-07-21 16:50:31 +05:30
|
|
|
get_start_date ())
|
2004-05-13 23:42:37 +05:30
|
|
|
d.set_year (d.get_year () - min_generation)
|
2004-03-11 09:54:03 +05:30
|
|
|
if not not_too_old (d):
|
|
|
|
return 0
|
2003-07-21 16:50:31 +05:30
|
|
|
|
2003-07-22 16:22:55 +05:30
|
|
|
if parents_too_old (spouse, max_age_difference):
|
|
|
|
return 0
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Event
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class Event(DataObj):
|
|
|
|
"""Event record, recording the event type, description, place, and date
|
|
|
|
of a particular event"""
|
2003-02-24 10:21:57 +05:30
|
|
|
|
|
|
|
NAME = 0
|
|
|
|
ID = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a new Event instance, copying from the source if present"""
|
|
|
|
|
|
|
|
DataObj.__init__(self,source)
|
|
|
|
|
|
|
|
if source:
|
|
|
|
self.place = source.place
|
|
|
|
self.date = Date(source.date)
|
|
|
|
self.description = source.description
|
|
|
|
self.name = source.name
|
|
|
|
self.cause = source.cause
|
2004-02-19 10:35:43 +05:30
|
|
|
self.id = source.id
|
2004-06-03 11:05:30 +05:30
|
|
|
self.media_list = [MediaRef(media_id) for media_id in source.media_list]
|
2003-06-09 23:34:04 +05:30
|
|
|
try:
|
|
|
|
if source.witness:
|
2003-06-07 19:41:52 +05:30
|
|
|
self.witness = source.witness[:]
|
2003-06-09 23:34:04 +05:30
|
|
|
else:
|
2003-06-07 19:41:52 +05:30
|
|
|
self.witness = None
|
2003-06-09 23:34:04 +05:30
|
|
|
except:
|
2003-02-24 10:21:57 +05:30
|
|
|
self.witness = None
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.place = u''
|
2002-10-20 19:55:16 +05:30
|
|
|
self.date = None
|
|
|
|
self.description = ""
|
|
|
|
self.name = ""
|
|
|
|
self.cause = ""
|
2003-02-24 10:21:57 +05:30
|
|
|
self.witness = None
|
2004-02-19 10:35:43 +05:30
|
|
|
self.id = None
|
2004-06-03 11:05:30 +05:30
|
|
|
self.media_list = []
|
2004-02-19 10:35:43 +05:30
|
|
|
|
|
|
|
def clone(self,source):
|
|
|
|
self.place = source.place
|
|
|
|
self.date = Date(source.date)
|
|
|
|
self.description = source.description
|
|
|
|
self.name = source.name
|
|
|
|
self.cause = source.cause
|
|
|
|
self.id = source.id
|
2004-02-21 11:41:59 +05:30
|
|
|
self.private = source.private
|
|
|
|
self.source_list = source.source_list[:]
|
|
|
|
self.note = source.note
|
2004-06-03 11:05:30 +05:30
|
|
|
self.media_list = [MediaRef(media_id) for media_id in source.media_list]
|
2004-02-19 10:35:43 +05:30
|
|
|
try:
|
|
|
|
if source.witness:
|
|
|
|
self.witness = source.witness[:]
|
|
|
|
else:
|
|
|
|
self.witness = None
|
|
|
|
except:
|
|
|
|
self.witness = None
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def serialize(self):
|
|
|
|
return (self.id, self.name, self.date, self.description,
|
|
|
|
self.place, self.cause, self.private, self.source_list,
|
2004-06-13 11:48:20 +05:30
|
|
|
self.note, self.witness, self.media_list)
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
def unserialize(self,data):
|
|
|
|
(self.id, self.name, self.date, self.description,
|
|
|
|
self.place, self.cause, self.private, self.source_list,
|
2004-06-13 11:48:20 +05:30
|
|
|
self.note, self.witness, self.media_list) = data
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-06-03 11:05:30 +05:30
|
|
|
def add_media_reference(self,media_id):
|
|
|
|
"""Adds a Photo object to the Event object's image list"""
|
|
|
|
self.media_list.append(media_id)
|
|
|
|
|
|
|
|
def get_media_list(self):
|
|
|
|
"""Returns the list of Photo objects"""
|
|
|
|
return self.media_list
|
|
|
|
|
|
|
|
def set_media_list(self,mlist):
|
|
|
|
"""Sets the list of Photo objects"""
|
|
|
|
self.media_list = mlist
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_id(self,gid):
|
2004-02-19 10:35:43 +05:30
|
|
|
"""Sets the gramps ID for the place object"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = gid
|
2004-02-19 10:35:43 +05:30
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
"""Returns the gramps ID for the place object"""
|
|
|
|
return self.id
|
2003-02-24 10:21:57 +05:30
|
|
|
|
|
|
|
def get_witness_list(self):
|
|
|
|
return self.witness
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-02-24 10:21:57 +05:30
|
|
|
def set_witness_list(self,list):
|
|
|
|
if list:
|
|
|
|
self.witness = list[:]
|
|
|
|
else:
|
|
|
|
self.witness = None
|
|
|
|
|
|
|
|
def add_witness(self,value):
|
|
|
|
if self.witness:
|
|
|
|
self.witness.append(value)
|
|
|
|
else:
|
|
|
|
self.witness = [value]
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def is_empty(self):
|
2004-02-14 11:10:30 +05:30
|
|
|
date = self.get_date_object()
|
|
|
|
place = self.get_place_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
description = self.description
|
2003-07-10 16:56:48 +05:30
|
|
|
cause = self.cause
|
2002-10-20 19:55:16 +05:30
|
|
|
name = self.name
|
|
|
|
if (not name or name == "Birth" or name == "Death") and \
|
2004-02-14 11:10:30 +05:30
|
|
|
date.is_empty() and not place and not description and not cause:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def set(self,name,date,place,description):
|
|
|
|
"""sets the name, date, place, and description of an Event instance"""
|
|
|
|
self.name = name
|
|
|
|
self.place = place
|
|
|
|
self.description = description
|
2004-02-14 11:10:30 +05:30
|
|
|
self.set_date(date)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def are_equal(self,other):
|
|
|
|
"""returns 1 if the specified event is the same as the instance"""
|
|
|
|
if other == None:
|
|
|
|
return 0
|
|
|
|
if (self.name != other.name or self.place != other.place or
|
|
|
|
self.description != other.description or self.cause != other.cause or
|
|
|
|
self.private != other.private or
|
2004-02-14 11:10:30 +05:30
|
|
|
compare_dates(self.get_date_object(),other.get_date_object()) or
|
|
|
|
len(self.get_source_references()) != len(other.get_source_references())):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
index = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
olist = other.get_source_references()
|
|
|
|
for a in self.get_source_references():
|
2002-10-20 19:55:16 +05:30
|
|
|
if not a.are_equal(olist[index]):
|
|
|
|
return 0
|
|
|
|
index = index + 1
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
witness_list = self.get_witness_list()
|
|
|
|
other_list = other.get_witness_list()
|
|
|
|
if (not witness_list) and (not other_list):
|
|
|
|
return 1
|
|
|
|
elif not (witness_list and other_list):
|
|
|
|
return 0
|
|
|
|
for a in witness_list:
|
|
|
|
if a in other_list:
|
|
|
|
other_list.remove(a)
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
if other_list:
|
|
|
|
return 0
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_name(self,name):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the name of the Event"""
|
|
|
|
self.name = name
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_name(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the name of the Event"""
|
|
|
|
return self.name
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_place_id(self,place):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Place instance of the Event"""
|
|
|
|
self.place = place
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Place instance of the Event"""
|
|
|
|
return self.place
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_cause(self,cause):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the cause of the Event"""
|
|
|
|
self.cause = cause
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_cause(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the cause of the Event"""
|
|
|
|
return self.cause
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_description(self,description):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the description of the Event instance"""
|
|
|
|
self.description = description
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_description(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the description of the Event instance"""
|
|
|
|
return self.description
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date(self, date) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""attempts to sets the date of the Event instance"""
|
|
|
|
if not self.date:
|
|
|
|
self.date = Date()
|
|
|
|
self.date.set(date)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date of the Event instance"""
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_preferred_date(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date of the Event instance"""
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_quote_date(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string representation of the date of the Event instance,
|
|
|
|
enclosing the results in quotes if it is not a valid date"""
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.date.get_quote_date()
|
2002-10-20 19:55:16 +05:30
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date_object(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Date object associated with the Event"""
|
|
|
|
if not self.date:
|
|
|
|
self.date = Date()
|
|
|
|
return self.date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date_object(self,date):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Date object associated with the Event"""
|
|
|
|
self.date = date
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Witness
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class Witness:
|
2003-02-24 10:21:57 +05:30
|
|
|
def __init__(self,type=Event.NAME,val="",comment=""):
|
|
|
|
self.set_type(type)
|
|
|
|
self.set_value(val)
|
|
|
|
self.set_comment(comment)
|
|
|
|
|
|
|
|
def set_type(self,type):
|
|
|
|
self.type = type
|
|
|
|
|
|
|
|
def get_type(self):
|
|
|
|
return self.type
|
|
|
|
|
|
|
|
def set_value(self,val):
|
|
|
|
self.val = val
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
return self.val
|
|
|
|
|
|
|
|
def set_comment(self,comment):
|
|
|
|
self.comment = comment
|
|
|
|
|
|
|
|
def get_comment(self):
|
|
|
|
return self.comment
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Family
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-10-29 10:34:43 +05:30
|
|
|
class Family(SourceNote):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Represents a family unit in the gramps database"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""creates a new Family instance"""
|
2003-10-29 10:34:43 +05:30
|
|
|
SourceNote.__init__(self)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.father_id = None
|
2004-02-14 11:10:30 +05:30
|
|
|
self.mother_id = None
|
|
|
|
self.child_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.type = "Married"
|
2004-02-14 11:10:30 +05:30
|
|
|
self.event_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.id = ""
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = []
|
2004-02-14 11:10:30 +05:30
|
|
|
self.attribute_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lds_seal = None
|
2003-10-29 10:34:43 +05:30
|
|
|
self.complete = 0
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return (self.id, self.father_id, self.mother_id,
|
|
|
|
self.child_list, self.type, self.event_list,
|
|
|
|
self.media_list, self.attribute_list, self.lds_seal,
|
|
|
|
self.complete,
|
|
|
|
self.source_list,
|
|
|
|
self.note)
|
|
|
|
|
|
|
|
def unserialize(self, data):
|
|
|
|
(self.id, self.father_id, self.mother_id,
|
|
|
|
self.child_list, self.type, self.event_list,
|
|
|
|
self.media_list, self.attribute_list, self.lds_seal,
|
|
|
|
self.complete,
|
|
|
|
self.source_list,
|
|
|
|
self.note) = data
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_complete(self,val):
|
2003-10-29 10:34:43 +05:30
|
|
|
self.complete = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_complete(self):
|
2003-10-29 10:34:43 +05:30
|
|
|
return self.complete
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_lds_sealing(self,ord):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.lds_seal = ord
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_lds_sealing(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
return self.lds_seal
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_attribute(self,attribute) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Attribute instance to the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.attribute_list.append(attribute)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def remove_attribute(self,attribute):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes the specified Attribute instance from the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if attribute in self.attribute_list:
|
|
|
|
self.attribute_list.remove(attribute)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_attribute_list(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the attribute list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.attribute_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_attribute_list(self,list) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the attribute list to the specified list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.attribute_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_id(self,gid) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the gramps ID for the Family"""
|
2004-03-30 10:20:24 +05:30
|
|
|
self.id = str(gid)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_id(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the gramps ID for the Family"""
|
2004-04-17 00:45:02 +05:30
|
|
|
return unicode(self.id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_relationship(self,type):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""assigns a string indicating the relationship between the
|
|
|
|
father and the mother"""
|
|
|
|
self.type = type
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_relationship(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a string indicating the relationship between the
|
|
|
|
father and the mother"""
|
|
|
|
return self.type
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_father_id(self,person_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the father of the Family to the specfied Person"""
|
2004-02-16 02:19:34 +05:30
|
|
|
# update = self.some_child_is_ancestor()
|
2004-02-14 11:10:30 +05:30
|
|
|
# if update and father_id:
|
|
|
|
# father_id.set_ancestor(0)
|
|
|
|
self.father_id = person_id
|
|
|
|
# if update and father_id:
|
|
|
|
# father_id.set_ancestor(1)
|
|
|
|
|
|
|
|
def get_father_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the father of the Family"""
|
2004-02-15 07:27:07 +05:30
|
|
|
return self.father_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_mother_id(self,person):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the mother of the Family to the specfied Person"""
|
2004-02-16 02:19:34 +05:30
|
|
|
# update = self.some_child_is_ancestor()
|
2004-02-14 11:10:30 +05:30
|
|
|
# if self.mother_id and update:
|
|
|
|
# self.mother_id.set_ancestor(0)
|
|
|
|
self.mother_id = person
|
|
|
|
# if update and self.mother_id:
|
|
|
|
# self.mother_id.set_ancestor(1)
|
|
|
|
|
|
|
|
def get_mother_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the mother of the Family"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.mother_id
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def add_child_id(self,person):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds the specfied Person as a child of the Family, adding it
|
|
|
|
to the child list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(person) == types.StringType or type(person) == types.UnicodeType)
|
|
|
|
|
|
|
|
if person not in self.child_list:
|
|
|
|
self.child_list.append(person)
|
|
|
|
# if person.get_ancestor():
|
|
|
|
# if father_id:
|
|
|
|
# father_id.set_ancestor(1)
|
|
|
|
# if self.mother_id:
|
|
|
|
# self.mother_id.set_ancestor(1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def remove_child_id(self,person):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""removes the specified Person from the child list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(person) == types.StringType or type(person) == types.UnicodeType)
|
|
|
|
|
|
|
|
if person in self.child_list:
|
|
|
|
self.child_list.remove(person)
|
|
|
|
# if person.get_ancestor():
|
|
|
|
# if father_id:
|
|
|
|
# father_id.set_ancestor(0)
|
|
|
|
# if self.mother_id:
|
|
|
|
# self.mother_id.set_ancestor(0)
|
|
|
|
|
|
|
|
def get_child_id_list(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of children"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.child_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_child_id_list(self, list):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the list of children"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.child_list = list[:]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
# def get_marriage(self):
|
|
|
|
# """returns the marriage event of the Family. Obsolete"""
|
|
|
|
# for e in self.event_list:
|
|
|
|
# if e.get_name() == "Marriage":
|
|
|
|
# return e
|
|
|
|
# return None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_divorce(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the divorce event of the Family. Obsolete"""
|
2004-02-14 11:10:30 +05:30
|
|
|
for e in self.event_list:
|
|
|
|
if e.get_name() == "Divorce":
|
2002-10-20 19:55:16 +05:30
|
|
|
return e
|
|
|
|
return None
|
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def add_event_id(self,event_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Event to the event list"""
|
2004-02-29 07:59:48 +05:30
|
|
|
assert(event_id != None)
|
2004-02-19 10:35:43 +05:30
|
|
|
self.event_list.append(event_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_event_list(self) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of Event instances"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.event_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_event_list(self,list) :
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the event list to the passed list"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.event_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-22 10:27:06 +05:30
|
|
|
def add_media_reference(self,media_id):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""Adds a MediaObject object to the Family instance's image list"""
|
2004-02-22 10:27:06 +05:30
|
|
|
self.media_list.append(media_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def get_media_list(self):
|
|
|
|
"""Returns the list of MediaObject objects"""
|
|
|
|
return self.media_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def set_media_list(self,list):
|
|
|
|
"""Sets the list of MediaObject objects"""
|
|
|
|
self.media_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def some_child_is_ancestor(self):
|
|
|
|
for child in self.child_list:
|
|
|
|
if (child.get_ancestor()):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
return None
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Source
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class Source:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""A record of a source of information"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""creates a new Source instance"""
|
|
|
|
self.title = ""
|
|
|
|
self.author = ""
|
|
|
|
self.pubinfo = ""
|
|
|
|
self.note = Note()
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_list = []
|
2002-10-20 19:55:16 +05:30
|
|
|
self.id = ""
|
2003-12-08 07:53:53 +05:30
|
|
|
self.abbrev = ""
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return (self.id,self.title,self.author,self.pubinfo,self.note,self.media_list,self.abbrev)
|
|
|
|
|
|
|
|
def unserialize(self,data):
|
|
|
|
(self.id,self.title,self.author,self.pubinfo,self.note,self.media_list,self.abbrev) = data
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_display_info(self):
|
2003-12-30 00:07:44 +05:30
|
|
|
return [self.title,self.id,self.author,self.title.upper(),self.author.upper()]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_id(self,newId):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the gramps' ID for the Source instance"""
|
|
|
|
self.id = str(newId)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the gramps' ID of the Source instance"""
|
|
|
|
return self.id
|
|
|
|
|
2004-02-22 10:27:06 +05:30
|
|
|
#EARNEY, this should eventually be a list of ids not objects, right?
|
|
|
|
def add_media_reference(self,media_id):
|
2004-02-21 11:41:59 +05:30
|
|
|
"""Adds a MediaObject object to the Source instance's image list"""
|
2004-02-22 10:27:06 +05:30
|
|
|
self.media_list.append(media_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def get_media_list(self):
|
|
|
|
"""Returns the list of MediaObject objects"""
|
|
|
|
return self.media_list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
def set_media_list(self,list):
|
|
|
|
"""Sets the list of MediaObject objects"""
|
|
|
|
self.media_list = list
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_title(self,title):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the title of the Source"""
|
|
|
|
self.title = title
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_title(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the title of the Source"""
|
|
|
|
return self.title
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the text of the note attached to the Source"""
|
|
|
|
self.note.set(text)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the text of the note attached to the Source"""
|
|
|
|
return self.note.get()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note_format(self,val):
|
2003-12-10 19:51:48 +05:30
|
|
|
"""Set the note's format to the given value"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.note.set_format(val)
|
2003-12-10 19:51:48 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note_format(self):
|
2003-12-10 19:51:48 +05:30
|
|
|
"""Return the current note's format"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.note.get_format()
|
2003-12-10 19:51:48 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note_object(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Note instance attached to the Source"""
|
|
|
|
self.note = obj
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_note_object(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Note instance attached to the Source"""
|
|
|
|
return self.note
|
|
|
|
|
|
|
|
def unique_note(self):
|
|
|
|
"""Creates a unique instance of the current note"""
|
|
|
|
self.note = Note(self.note.get())
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_author(self,author):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the author of the Source"""
|
|
|
|
self.author = author
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_author(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the author of the Source"""
|
|
|
|
return self.author
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_publication_info(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the publication information of the Source"""
|
|
|
|
self.pubinfo = text
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_publication_info(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the publication information of the Source"""
|
|
|
|
return self.pubinfo
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_abbreviation(self,abbrev):
|
2003-12-08 07:53:53 +05:30
|
|
|
"""sets the title abbreviation of the Source"""
|
|
|
|
self.abbrev = abbrev
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_abbreviation(self):
|
2003-12-08 07:53:53 +05:30
|
|
|
"""returns the title abbreviation of the Source"""
|
|
|
|
return self.abbrev
|
|
|
|
|
2003-11-02 01:25:30 +05:30
|
|
|
class SourceRef:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Source reference, containing detailed information about how a
|
|
|
|
referenced source relates to it"""
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
"""creates a new SourceRef, copying from the source if present"""
|
|
|
|
if source:
|
|
|
|
self.confidence = source.confidence
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(source.ref) == types.StringType or type(source.ref) == types.UnicodeType)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.ref = source.ref
|
|
|
|
self.page = source.page
|
|
|
|
self.date = Date(source.date)
|
|
|
|
self.comments = Note(source.comments.get())
|
|
|
|
self.text = source.text
|
|
|
|
else:
|
|
|
|
self.confidence = CONF_NORMAL
|
|
|
|
self.ref = None
|
|
|
|
self.page = ""
|
|
|
|
self.date = Date()
|
|
|
|
self.comments = Note()
|
|
|
|
self.text = ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_confidence_level(self,val):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Sets the confidence level"""
|
|
|
|
self.confidence = val
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_confidence_level(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Returns the confidence level"""
|
|
|
|
return self.confidence
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_base_id(self,ref):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Source instance to which the SourceRef refers"""
|
2004-02-14 11:10:30 +05:30
|
|
|
assert(type(ref) == types.StringType or type(ref) == types.UnicodeType)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.ref = ref
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_base_id(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Source instance to which the SourceRef refers"""
|
|
|
|
return self.ref
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_date(self,date):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the Date instance of the SourceRef"""
|
|
|
|
self.date = date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_date(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Date instance of the SourceRef"""
|
|
|
|
return self.date
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_page(self,page):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the page indicator of the SourceRef"""
|
|
|
|
self.page = page
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_page(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""gets the page indicator of the SourceRef"""
|
|
|
|
return self.page
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_text(self,text):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the text related to the SourceRef"""
|
|
|
|
self.text = text
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_text(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the text related to the SourceRef"""
|
|
|
|
return self.text
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_note_object(self,note):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Change the Note instance to obj"""
|
|
|
|
self.comments = note
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_comments(self,comments):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the comments about the SourceRef"""
|
|
|
|
self.comments.set(comments)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_comments(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the comments about the SourceRef"""
|
|
|
|
return self.comments.get()
|
|
|
|
|
|
|
|
def are_equal(self,other):
|
|
|
|
"""returns 1 if the passed SourceRef is equal to the current"""
|
|
|
|
if self.ref and other.ref:
|
|
|
|
if self.page != other.page:
|
|
|
|
return 0
|
|
|
|
if compare_dates(self.date,other.date) != 0:
|
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.get_text() != other.get_text():
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.get_comments() != other.get_comments():
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
if self.confidence != other.confidence:
|
|
|
|
return 0
|
|
|
|
return 1
|
|
|
|
elif not self.ref and not other.ref:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def unique_note(self):
|
|
|
|
"""Creates a unique instance of the current note"""
|
|
|
|
self.comments = Note(self.comments.get())
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GenderStats
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-06-24 19:46:47 +05:30
|
|
|
class GenderStats:
|
|
|
|
def __init__ (self):
|
|
|
|
self.stats = {}
|
|
|
|
|
|
|
|
def _get_key (self, person):
|
2004-02-14 11:10:30 +05:30
|
|
|
name = person.get_primary_name ().get_first_name ()
|
2003-06-24 19:46:47 +05:30
|
|
|
return self._get_key_from_name (name)
|
|
|
|
|
|
|
|
def _get_key_from_name (self, name):
|
|
|
|
return name.split (' ')[0].replace ('?', '')
|
|
|
|
|
|
|
|
def name_stats (self, name):
|
|
|
|
if self.stats.has_key (name):
|
|
|
|
return self.stats[name]
|
|
|
|
return (0, 0, 0)
|
|
|
|
|
|
|
|
def count_person (self, person, db, undo = 0):
|
|
|
|
# Let the Person do their own counting later
|
|
|
|
person.db = db
|
|
|
|
|
|
|
|
name = self._get_key (person)
|
|
|
|
if not name:
|
|
|
|
return
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
gender = person.get_gender ()
|
2003-06-24 19:46:47 +05:30
|
|
|
(male, female, unknown) = self.name_stats (name)
|
|
|
|
if not undo:
|
|
|
|
increment = 1
|
|
|
|
else:
|
|
|
|
increment = -1
|
|
|
|
|
|
|
|
if gender == Person.male:
|
|
|
|
male += increment
|
|
|
|
elif gender == Person.female:
|
|
|
|
female += increment
|
|
|
|
elif gender == Person.unknown:
|
|
|
|
unknown += increment
|
|
|
|
|
|
|
|
self.stats[name] = (male, female, unknown)
|
|
|
|
return
|
|
|
|
|
|
|
|
def uncount_person (self, person):
|
|
|
|
return self.count_person (person, None, undo = 1)
|
|
|
|
|
|
|
|
def guess_gender (self, name):
|
|
|
|
name = self._get_key_from_name (name)
|
|
|
|
if not name or not self.stats.has_key (name):
|
|
|
|
return Person.unknown
|
|
|
|
|
|
|
|
(male, female, unknown) = self.stats[name]
|
|
|
|
if unknown == 0:
|
|
|
|
if male and not female:
|
|
|
|
return Person.male
|
|
|
|
if female and not male:
|
|
|
|
return Person.female
|
|
|
|
|
|
|
|
if male > (2 * female):
|
|
|
|
return Person.male
|
|
|
|
|
|
|
|
if female > (2 * male):
|
|
|
|
return Person.female
|
|
|
|
|
|
|
|
return Person.unknown
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
try: # First try python2.3 and later: this is the future
|
|
|
|
from bsddb import dbshelve, db
|
|
|
|
except ImportError: # try python2.2
|
|
|
|
from bsddb3 import dbshelve, db
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-02-25 08:55:57 +05:30
|
|
|
|
|
|
|
def find_surname(key,data):
|
2004-06-27 08:40:06 +05:30
|
|
|
return str(data[3].get_surname())
|
|
|
|
|
|
|
|
def find_idmap(key,data):
|
|
|
|
return str(data[1])
|
2004-02-25 08:55:57 +05:30
|
|
|
|
2004-05-12 09:28:14 +05:30
|
|
|
def find_eventname(key,data):
|
|
|
|
return str(data[1])
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GrampsDB
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-11-02 01:25:30 +05:30
|
|
|
class GrampsDB:
|
2002-10-20 19:55:16 +05:30
|
|
|
"""GRAMPS database object. This object is a base class for other
|
|
|
|
objects."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""creates a new GrampsDB"""
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
self.iprefix = "I%04d"
|
|
|
|
self.sprefix = "S%04d"
|
|
|
|
self.oprefix = "O%04d"
|
|
|
|
self.pprefix = "P%04d"
|
|
|
|
self.fprefix = "F%04d"
|
|
|
|
self.eprefix = "E%04d"
|
2004-03-08 03:20:41 +05:30
|
|
|
self.open = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
self.new()
|
2003-05-08 22:42:10 +05:30
|
|
|
self.added_files = []
|
2003-06-24 19:46:47 +05:30
|
|
|
self.genderStats = GenderStats ()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-29 00:16:40 +05:30
|
|
|
self.env = None
|
|
|
|
self.person_map = None
|
|
|
|
self.family_map = None
|
|
|
|
self.place_map = None
|
|
|
|
self.source_map = None
|
|
|
|
self.media_map = None
|
|
|
|
self.event_map = None
|
|
|
|
self.surnames = None
|
2004-05-12 09:28:14 +05:30
|
|
|
self.eventnames = None
|
2004-03-10 10:45:06 +05:30
|
|
|
self.metadata = None
|
2004-05-19 11:43:36 +05:30
|
|
|
self.undolabel = None
|
2004-05-20 10:11:55 +05:30
|
|
|
self.redolabel = None
|
2004-06-20 08:36:21 +05:30
|
|
|
self.undodb = None
|
2004-05-19 11:43:36 +05:30
|
|
|
|
|
|
|
def set_undo_label(self,label):
|
|
|
|
self.undolabel = label
|
|
|
|
self.undolabel.set_sensitive(0)
|
2004-02-29 00:16:40 +05:30
|
|
|
|
2004-05-20 10:11:55 +05:30
|
|
|
def set_redo_label(self,label):
|
|
|
|
self.redolabel = label
|
|
|
|
self.redolabel.set_sensitive(0)
|
|
|
|
|
2004-02-29 00:16:40 +05:30
|
|
|
def load(self,name,callback):
|
|
|
|
if self.person_map:
|
|
|
|
self.close()
|
2004-04-10 09:08:48 +05:30
|
|
|
|
2004-02-29 00:16:40 +05:30
|
|
|
self.env = db.DBEnv()
|
2004-06-20 08:36:21 +05:30
|
|
|
self.env.set_cachesize(0,4*1024*1024) # 2MB
|
2004-02-29 00:16:40 +05:30
|
|
|
flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE
|
2004-05-17 08:29:44 +05:30
|
|
|
|
|
|
|
self.undolog = "%s.log" % name
|
2004-02-29 00:16:40 +05:30
|
|
|
self.env.open(os.path.dirname(name), flags)
|
2004-04-10 09:08:48 +05:30
|
|
|
|
2004-02-29 00:16:40 +05:30
|
|
|
name = os.path.basename(name)
|
|
|
|
self.person_map = dbshelve.open(name, dbname="person", dbenv=self.env)
|
|
|
|
self.family_map = dbshelve.open(name, dbname="family", dbenv=self.env)
|
|
|
|
self.place_map = dbshelve.open(name, dbname="places", dbenv=self.env)
|
|
|
|
self.source_map = dbshelve.open(name, dbname="sources",dbenv=self.env)
|
|
|
|
self.media_map = dbshelve.open(name, dbname="media", dbenv=self.env)
|
|
|
|
self.event_map = dbshelve.open(name, dbname="events", dbenv=self.env)
|
2004-03-08 03:20:41 +05:30
|
|
|
self.metadata = dbshelve.open(name, dbname="meta", dbenv=self.env)
|
2004-02-29 00:16:40 +05:30
|
|
|
|
|
|
|
self.surnames = db.DB(self.env)
|
|
|
|
self.surnames.set_flags(db.DB_DUP)
|
|
|
|
self.surnames.open(name, "surnames", db.DB_HASH, flags=db.DB_CREATE)
|
|
|
|
|
2004-06-27 08:40:06 +05:30
|
|
|
self.idtrans = db.DB(self.env)
|
|
|
|
self.idtrans.set_flags(db.DB_DUP)
|
|
|
|
self.idtrans.open(name, "idtrans", db.DB_HASH, flags=db.DB_CREATE)
|
|
|
|
|
2004-05-12 09:28:14 +05:30
|
|
|
self.eventnames = db.DB(self.env)
|
|
|
|
self.eventnames.set_flags(db.DB_DUP)
|
|
|
|
self.eventnames.open(name, "eventnames", db.DB_HASH, flags=db.DB_CREATE)
|
2004-02-29 00:16:40 +05:30
|
|
|
self.person_map.associate(self.surnames, find_surname, db.DB_CREATE)
|
2004-06-27 08:40:06 +05:30
|
|
|
self.person_map.associate(self.idtrans, find_idmap, db.DB_CREATE)
|
2004-05-12 09:28:14 +05:30
|
|
|
self.event_map.associate(self.eventnames, find_eventname, db.DB_CREATE)
|
|
|
|
|
2004-05-17 08:29:44 +05:30
|
|
|
self.undodb = db.DB()
|
|
|
|
self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE)
|
|
|
|
|
2004-04-11 08:07:13 +05:30
|
|
|
self.bookmarks = self.metadata.get('bookmarks')
|
|
|
|
if self.bookmarks == None:
|
|
|
|
self.bookmarks = []
|
2004-04-10 09:08:48 +05:30
|
|
|
return 1
|
2004-02-29 00:16:40 +05:30
|
|
|
|
2004-06-27 08:40:06 +05:30
|
|
|
def find_next_gid(self):
|
|
|
|
index = self.iprefix % self.pmap_index
|
|
|
|
while self.idtrans.get(str(index)):
|
|
|
|
self.pmap_index += 1
|
|
|
|
index = self.iprefix % self.pmap_index
|
|
|
|
self.pmap_index += 1
|
|
|
|
return index
|
|
|
|
|
2004-04-28 09:36:25 +05:30
|
|
|
def get_people_view_maps(self):
|
|
|
|
if self.metadata:
|
|
|
|
return (self.metadata.get('tp_iter'),
|
|
|
|
self.metadata.get('tp_path'),
|
|
|
|
self.metadata.get('p_iter'),
|
|
|
|
self.metadata.get('p_path'),
|
|
|
|
self.metadata.get('sname'))
|
|
|
|
else:
|
|
|
|
return (None,None,None,None,None)
|
|
|
|
|
|
|
|
def set_people_view_maps(self,maps):
|
|
|
|
if self.metadata:
|
|
|
|
self.metadata['tp_iter'] = maps[0]
|
|
|
|
self.metadata['tp_path'] = maps[1]
|
|
|
|
self.metadata['p_iter'] = maps[2]
|
|
|
|
self.metadata['p_path'] = maps[3]
|
|
|
|
self.metadata['sname'] = maps[4]
|
|
|
|
|
2004-02-25 08:55:57 +05:30
|
|
|
def close(self):
|
|
|
|
self.person_map.close()
|
|
|
|
self.family_map.close()
|
|
|
|
self.place_map.close()
|
|
|
|
self.source_map.close()
|
|
|
|
self.media_map.close()
|
|
|
|
self.event_map.close()
|
2004-04-11 08:07:13 +05:30
|
|
|
self.metadata['bookmarks'] = self.bookmarks
|
2004-03-08 03:20:41 +05:30
|
|
|
self.metadata.close()
|
2004-02-25 08:55:57 +05:30
|
|
|
self.surnames.close()
|
2004-05-12 09:28:14 +05:30
|
|
|
self.eventnames.close()
|
2004-06-27 08:40:06 +05:30
|
|
|
self.idtrans.close()
|
2004-02-29 00:16:40 +05:30
|
|
|
self.env.close()
|
2004-05-17 08:29:44 +05:30
|
|
|
self.undodb.close()
|
2004-02-25 08:55:57 +05:30
|
|
|
|
2004-05-17 08:29:44 +05:30
|
|
|
try:
|
|
|
|
os.remove(self.undolog)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2004-03-08 03:20:41 +05:30
|
|
|
self.person_map = None
|
|
|
|
self.family_map = None
|
|
|
|
self.place_map = None
|
|
|
|
self.source_map = None
|
|
|
|
self.media_map = None
|
|
|
|
self.event_map = None
|
|
|
|
self.surnames = None
|
|
|
|
self.env = None
|
|
|
|
self.metadata = None
|
|
|
|
|
|
|
|
def is_open(self):
|
|
|
|
return self.person_map != None
|
|
|
|
|
2003-05-08 22:42:10 +05:30
|
|
|
def get_added_media_objects(self):
|
|
|
|
return self.added_files
|
|
|
|
|
|
|
|
def clear_added_media_objects(self):
|
|
|
|
self.added_files = []
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def get_type(self):
|
|
|
|
return 'GrampsDB'
|
|
|
|
|
|
|
|
def get_base(self):
|
|
|
|
return ""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_number_of_people(self):
|
|
|
|
return len(self.person_map)
|
2003-04-04 11:18:25 +05:30
|
|
|
|
2004-02-15 07:27:07 +05:30
|
|
|
def get_person_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.person_map:
|
|
|
|
return self.person_map.keys()
|
|
|
|
else:
|
|
|
|
return []
|
2003-10-18 08:09:55 +05:30
|
|
|
|
2004-02-22 10:27:06 +05:30
|
|
|
def get_family_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.family_map:
|
|
|
|
return self.family_map.keys()
|
|
|
|
else:
|
|
|
|
return []
|
2004-02-22 10:27:06 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def sort_by_name(self,f,s):
|
2004-02-21 11:41:59 +05:30
|
|
|
n1 = self.person_map.get(str(f))[2].sname
|
|
|
|
n2 = self.person_map.get(str(s))[2].sname
|
2004-01-07 10:35:42 +05:30
|
|
|
return cmp(n1,n2)
|
2003-10-18 08:09:55 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def sort_person_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.person_map:
|
2004-02-29 10:39:23 +05:30
|
|
|
keys = self.person_map.keys()
|
|
|
|
keys.sort(self.sort_by_name)
|
|
|
|
return keys
|
2004-02-29 00:16:40 +05:30
|
|
|
else:
|
|
|
|
return []
|
2003-10-18 08:09:55 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_person_display(self,key):
|
2004-02-21 11:41:59 +05:30
|
|
|
data = self.person_map.get(str(key))
|
|
|
|
|
2004-06-27 08:40:06 +05:30
|
|
|
if data[2] == Person.male:
|
2004-02-21 11:41:59 +05:30
|
|
|
gender = const.male
|
2004-06-27 08:40:06 +05:30
|
|
|
elif data[2] == Person.female:
|
2004-02-21 11:41:59 +05:30
|
|
|
gender = const.female
|
|
|
|
else:
|
|
|
|
gender = const.unknown
|
2004-06-27 08:40:06 +05:30
|
|
|
|
|
|
|
return [ data[3].get_name(),
|
|
|
|
data[1],
|
2004-02-21 11:41:59 +05:30
|
|
|
gender,
|
2004-06-27 08:40:06 +05:30
|
|
|
data[7],
|
2004-02-21 11:41:59 +05:30
|
|
|
data[6],
|
2004-06-27 08:40:06 +05:30
|
|
|
data[3].get_sort_name(),
|
|
|
|
data[7],
|
2004-02-21 11:41:59 +05:30
|
|
|
data[6],
|
2004-07-15 08:24:04 +05:30
|
|
|
GrampsCfg.get_display_surname()(data[3])]
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_person(self,person,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(person.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.person_map.get(gid)
|
|
|
|
transaction.add(PERSON_KEY,gid,old_data)
|
|
|
|
self.person_map.put(gid,person.serialize())
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_media_object(self,object,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(object.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.media_map.get(gid)
|
|
|
|
transaction.add(MEDIA_KEY,gid,old_data)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_map.put(str(object.get_id()),object.serialize())
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_source(self,source,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(source.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.source_map.get(gid)
|
|
|
|
transaction.add(SOURCE_KEY,gid,old_data)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.source_map.put(str(source.get_id()),source.serialize())
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_place(self,place,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(place.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.place_map.get(gid)
|
|
|
|
transaction.add(PLACE_KEY,gid,old_data)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.place_map.put(str(place.get_id()),place.serialize())
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_event(self,event,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(event.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.event_map.get(gid)
|
|
|
|
transaction.add(EVENT_KEY,gid,old_data)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.event_map.put(str(event.get_id()),event.serialize())
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def commit_family(self,family,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(family.get_id())
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.family_map.get(gid)
|
|
|
|
transaction.add(FAMILY_KEY,gid,old_data)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.family_map.put(str(family.get_id()),family.serialize())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_iprefix(self,val):
|
2002-10-21 06:48:07 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.iprefix = val
|
|
|
|
else:
|
|
|
|
self.iprefix = val + "%d"
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-19 10:35:43 +05:30
|
|
|
self.iprefix = "I%04d"
|
2002-10-21 06:48:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_sprefix(self,val):
|
2002-10-21 06:48:07 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.sprefix = val
|
|
|
|
else:
|
|
|
|
self.sprefix = val + "%d"
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-19 10:35:43 +05:30
|
|
|
self.sprefix = "S%04d"
|
2002-10-21 06:48:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_oprefix(self,val):
|
2002-10-21 06:48:07 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.oprefix = val
|
|
|
|
else:
|
|
|
|
self.oprefix = val + "%d"
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-19 10:35:43 +05:30
|
|
|
self.oprefix = "O%04d"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_pprefix(self,val):
|
2002-10-21 06:48:07 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.pprefix = val
|
|
|
|
else:
|
|
|
|
self.pprefix = val + "%d"
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-19 10:35:43 +05:30
|
|
|
self.pprefix = "P%04d"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def set_fprefix(self,val):
|
2002-10-21 06:48:07 +05:30
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.fprefix = val
|
|
|
|
else:
|
|
|
|
self.fprefix = val + "%d"
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-19 10:35:43 +05:30
|
|
|
self.fprefix = "F%04d"
|
|
|
|
|
|
|
|
def set_eprefix(self,val):
|
|
|
|
if val:
|
|
|
|
if _id_reg.search(val):
|
|
|
|
self.eprefix = val
|
|
|
|
else:
|
|
|
|
self.eprefix = val + "%d"
|
|
|
|
else:
|
|
|
|
self.eprefix = "E%04d"
|
2002-10-21 06:48:07 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def new(self):
|
|
|
|
"""initializes the GrampsDB to empty values"""
|
|
|
|
|
2004-05-20 05:42:14 +05:30
|
|
|
self.undoindex = -1
|
|
|
|
self.translist = [None] * UNDO_SIZE
|
2004-02-14 11:10:30 +05:30
|
|
|
self.smap_index = 0
|
2004-02-19 10:35:43 +05:30
|
|
|
self.emap_index = 0
|
2004-02-14 11:10:30 +05:30
|
|
|
self.pmap_index = 0
|
|
|
|
self.fmap_index = 0
|
|
|
|
self.lmap_index = 0
|
|
|
|
self.omap_index = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
self.default = None
|
|
|
|
self.owner = Researcher()
|
|
|
|
self.bookmarks = []
|
|
|
|
self.path = ""
|
|
|
|
self.place2title = {}
|
2003-06-24 19:46:47 +05:30
|
|
|
self.genderStats = GenderStats ()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-04-04 10:09:52 +05:30
|
|
|
def start_transaction(self,msg=""):
|
2004-05-20 05:42:14 +05:30
|
|
|
return Transaction(msg,self.undodb)
|
2004-03-25 20:35:56 +05:30
|
|
|
|
2004-05-19 11:43:36 +05:30
|
|
|
def add_transaction(self,transaction,msg):
|
2004-05-26 08:59:00 +05:30
|
|
|
if not len(transaction):
|
|
|
|
return
|
2004-05-19 11:43:36 +05:30
|
|
|
transaction.set_description(msg)
|
2004-05-20 05:42:14 +05:30
|
|
|
self.undoindex += 1
|
|
|
|
if self.undoindex == UNDO_SIZE:
|
|
|
|
self.translist = transaction[0:-1] + [ transaction ]
|
|
|
|
else:
|
|
|
|
self.translist[self.undoindex] = transaction
|
|
|
|
|
2004-05-19 11:43:36 +05:30
|
|
|
if self.undolabel:
|
|
|
|
self.undolabel.set_sensitive(1)
|
|
|
|
label = self.undolabel.get_children()[0]
|
|
|
|
label.set_text(_("_Undo %s") % transaction.get_description())
|
|
|
|
label.set_use_underline(1)
|
2004-03-25 20:35:56 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def undo(self):
|
2004-05-20 05:42:14 +05:30
|
|
|
if self.undoindex == -1:
|
2004-03-30 10:20:24 +05:30
|
|
|
return
|
2004-05-20 05:42:14 +05:30
|
|
|
transaction = self.translist[self.undoindex]
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-05-20 05:42:14 +05:30
|
|
|
self.undoindex -= 1
|
|
|
|
subitems = transaction.get_recnos()
|
2004-03-30 10:20:24 +05:30
|
|
|
subitems.reverse()
|
2004-05-20 05:42:14 +05:30
|
|
|
for record_id in subitems:
|
|
|
|
(key, gid, data) = transaction.get_record(record_id)
|
2004-03-30 10:20:24 +05:30
|
|
|
if key == PERSON_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.person_map[gid]
|
|
|
|
else:
|
|
|
|
self.person_map.put(gid,data)
|
|
|
|
elif key == FAMILY_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.family_map[gid]
|
|
|
|
else:
|
|
|
|
self.family_map.put(gid,data)
|
|
|
|
elif key == SOURCE_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.source_map[gid]
|
|
|
|
else:
|
|
|
|
self.source_map.put(gid,data)
|
|
|
|
elif key == EVENT_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.event_map[gid]
|
|
|
|
else:
|
|
|
|
self.event_map.put(gid,data)
|
|
|
|
elif key == PLACE_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.place_map[gid]
|
|
|
|
else:
|
|
|
|
self.place_map.put(gid,data)
|
|
|
|
elif key == MEDIA_KEY:
|
|
|
|
if data == None:
|
|
|
|
del self.media_map[gid]
|
|
|
|
else:
|
|
|
|
self.media_map.put(gid,data)
|
2004-03-25 20:35:56 +05:30
|
|
|
|
2004-05-19 11:43:36 +05:30
|
|
|
if self.undolabel:
|
|
|
|
label = self.undolabel.get_children()[0]
|
2004-05-20 05:42:14 +05:30
|
|
|
if self.undoindex == -1:
|
2004-05-19 11:43:36 +05:30
|
|
|
label.set_text(_("_Undo"))
|
|
|
|
self.undolabel.set_sensitive(0)
|
|
|
|
else:
|
2004-05-20 05:42:14 +05:30
|
|
|
transaction = self.translist[self.undoindex]
|
2004-05-19 11:43:36 +05:30
|
|
|
label.set_text(_("_Undo %s") % transaction.get_description())
|
|
|
|
self.undolabel.set_sensitive(1)
|
|
|
|
label.set_use_underline(1)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_surnames(self):
|
2004-03-06 10:16:07 +05:30
|
|
|
names = self.surnames.keys()
|
|
|
|
a = {}
|
|
|
|
for name in names:
|
2004-05-12 09:28:14 +05:30
|
|
|
a[unicode(name)] = 1
|
|
|
|
vals = a.keys()
|
|
|
|
vals.sort()
|
|
|
|
return vals
|
|
|
|
|
|
|
|
def get_eventnames(self):
|
|
|
|
names = self.eventnames.keys()
|
|
|
|
a = {}
|
|
|
|
for name in names:
|
|
|
|
a[unicode(name)] = 1
|
2004-03-06 10:16:07 +05:30
|
|
|
vals = a.keys()
|
|
|
|
vals.sort()
|
|
|
|
return vals
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_bookmarks(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the list of Person instances in the bookmarks"""
|
2002-11-19 10:34:30 +05:30
|
|
|
return self.bookmarks
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def clean_bookmarks(self):
|
|
|
|
"""cleans up the bookmark list, removing empty slots"""
|
|
|
|
new_bookmarks = []
|
2004-02-22 10:27:06 +05:30
|
|
|
for person_id in self.bookmarks:
|
|
|
|
new_bookmarks.append(person_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.bookmarks = new_bookmarks
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_researcher(self,owner):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the information about the owner of the database"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.owner.set(owner.get_name(),owner.get_address(),owner.get_city(),\
|
|
|
|
owner.get_state(),owner.get_country(),\
|
|
|
|
owner.get_postal_code(),owner.get_phone(),owner.get_email())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_researcher(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the Researcher instance, providing information about
|
|
|
|
the owner of the database"""
|
|
|
|
return self.owner
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_default_person(self,person):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the default Person to the passed instance"""
|
2004-02-21 11:41:59 +05:30
|
|
|
# if (self.default):
|
|
|
|
# self.default.set_ancestor(0)
|
2004-03-08 03:20:41 +05:30
|
|
|
self.metadata['default'] = str(person.get_id())
|
2004-02-21 11:41:59 +05:30
|
|
|
# if person:
|
|
|
|
# self.default.set_ancestor(1)
|
2004-03-23 10:31:19 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def set_default_person_id(self,gid):
|
2004-03-23 10:31:19 +05:30
|
|
|
"""sets the default Person to the passed instance"""
|
2004-03-30 10:20:24 +05:30
|
|
|
assert(type(gid) == types.StringType or type(gid) == types.UnicodeType)
|
|
|
|
self.metadata['default'] = gid
|
2004-03-23 10:31:19 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_default_person(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the default Person of the database"""
|
2004-03-23 10:31:19 +05:30
|
|
|
if self.metadata and self.metadata.has_key('default'):
|
|
|
|
person = Person()
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = self.metadata['default']
|
|
|
|
data = self.person_map.get(str(gid))
|
2004-03-23 10:31:19 +05:30
|
|
|
person.unserialize(data)
|
|
|
|
return person
|
2004-03-22 10:11:35 +05:30
|
|
|
return None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def get_person(self,gid):
|
2004-02-22 10:27:06 +05:30
|
|
|
"""returns a Person from a GRAMPS's ID"""
|
2004-02-21 11:41:59 +05:30
|
|
|
p = Person()
|
2004-03-30 10:20:24 +05:30
|
|
|
data = self.person_map.get(str(gid))
|
2004-02-21 11:41:59 +05:30
|
|
|
p.unserialize(data)
|
|
|
|
return p
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_id_map(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a map of gramps's IDs to Place instances"""
|
2004-02-14 11:10:30 +05:30
|
|
|
return self.place_map
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_place_id_map(self,map):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the map of gramps's IDs to Place instances"""
|
2004-02-14 11:10:30 +05:30
|
|
|
self.place_map = map
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def get_family_id(self,gid):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a map of gramps's IDs to Family instances"""
|
2004-03-30 10:20:24 +05:30
|
|
|
return self.family_map.get(str(gid))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_save_path(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns the save path of the file, or "" if one does not exist"""
|
|
|
|
return self.path
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_save_path(self,path):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""sets the save path for the database"""
|
|
|
|
self.path = path
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_person_event_types(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of all Event types assocated with Person
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
2004-02-21 11:41:59 +05:30
|
|
|
# for person in self.person_map.values():
|
|
|
|
# for event_id in person.get_event_list():
|
|
|
|
# event = self.event_map[event_id]
|
|
|
|
# map[event.get_name()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return map.keys()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_person_attribute_types(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of all Attribute types assocated with Person
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
2004-02-21 11:41:59 +05:30
|
|
|
# for key in self.person_map.keys():
|
|
|
|
# person = self.person_map[key]
|
|
|
|
# for attr in person.get_attribute_list():
|
|
|
|
# map[attr.get_type()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return map.keys()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_family_attribute_types(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of all Attribute types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
2004-02-21 11:41:59 +05:30
|
|
|
# for family in self.family_map.values():
|
|
|
|
# for attr in family.get_attribute_list():
|
|
|
|
# map[attr.get_type()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return map.keys()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_family_event_types(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of all Event types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
2004-02-21 11:41:59 +05:30
|
|
|
# for family in self.family_map.values():
|
|
|
|
# for event_id in family.get_event_list():
|
|
|
|
# event = self.event_map[event_id]
|
|
|
|
# map[event.get_name()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return map.keys()
|
|
|
|
|
2004-06-03 11:05:30 +05:30
|
|
|
def get_media_attribute_types(self):
|
|
|
|
"""returns a list of all Attribute types assocated with Media
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
|
|
|
# for media_id in self.media_map.keys():
|
|
|
|
# mobject = self.find_object_from_id(media_id)
|
|
|
|
# for attr in mobject.get_attribute_list():
|
|
|
|
# map[attr.get_type()] = 1
|
|
|
|
return map.keys()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_ids(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of Place instances"""
|
2004-02-22 10:27:06 +05:30
|
|
|
return self.place_map.keys()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_family_relation_types(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""returns a list of all relationship types assocated with Family
|
|
|
|
instances in the database"""
|
|
|
|
map = {}
|
2004-02-21 11:41:59 +05:30
|
|
|
# for family in self.family_map.values():
|
|
|
|
# map[family.get_relationship()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return map.keys()
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def remove_person_id(self,gid,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
# self.genderStats.uncount_person (self.person_map[gid])
|
|
|
|
if transaction != None:
|
|
|
|
old_data = self.person_map.get(str(gid))
|
|
|
|
transaction.add(PERSON_KEY,gid,old_data)
|
|
|
|
self.person_map.delete(str(gid))
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def remove_source_id(self,gid,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
if transaction != None:
|
|
|
|
old_data = self.source_map.get(str(gid))
|
|
|
|
transaction.add(SOURCE_KEY,gid,old_data)
|
|
|
|
self.source_map.delete(str(gid))
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def remove_event_id(self,gid,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
if transaction != None:
|
|
|
|
old_data = self.event_map.get(str(gid))
|
|
|
|
transaction.add(EVENT_KEY,gid,old_data)
|
|
|
|
self.event_map.delete(str(gid))
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_person_as(self,person,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(PERSON_KEY, person.get_id(),None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.person_map.put(str(person.get_id()),person.serialize())
|
|
|
|
# self.genderStats.count_person (person, self)
|
2004-02-14 11:10:30 +05:30
|
|
|
return person.get_id()
|
2003-05-05 07:06:21 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_person(self,person,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Person to the database, assigning a gramps' ID"""
|
2004-06-27 08:40:06 +05:30
|
|
|
person.set_gramps_id(self.find_next_gid())
|
|
|
|
person.set_id(Utils.create_id())
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(PERSON_KEY, person.get_id(),None)
|
2004-06-27 08:40:06 +05:30
|
|
|
self.person_map.put(str(person.get_id()),person.serialize())
|
2003-06-24 19:46:47 +05:30
|
|
|
self.genderStats.count_person (person, self)
|
2004-06-27 08:40:06 +05:30
|
|
|
return person.get_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_person(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Person in the database using the gid and map
|
2002-10-20 19:55:16 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Person exists, a new Person instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2002-10-20 19:55:16 +05:30
|
|
|
map - map build by findPerson of external to gramp's IDs"""
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(gid)
|
2004-02-21 11:41:59 +05:30
|
|
|
person = Person()
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
person.unserialize(self.person_map.get(str(map[gid])))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
person = Person()
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_person(person,trans)
|
2003-06-24 19:46:47 +05:30
|
|
|
self.genderStats.count_person (person, self)
|
2002-10-20 19:55:16 +05:30
|
|
|
return person
|
|
|
|
|
2004-04-04 10:09:52 +05:30
|
|
|
def has_person_id(self,val):
|
|
|
|
return self.person_map.get(str(val))
|
2004-02-21 11:41:59 +05:30
|
|
|
|
2004-04-04 10:09:52 +05:30
|
|
|
def has_family_id(self,val):
|
|
|
|
return self.family_map.get(str(val))
|
2004-03-30 10:20:24 +05:30
|
|
|
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
def try_to_find_person_from_id(self,val):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, a new Person is added to the database."""
|
|
|
|
|
|
|
|
data = self.person_map.get(str(val))
|
|
|
|
if data:
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
person = Person()
|
2004-03-30 10:20:24 +05:30
|
|
|
person.unserialize(data)
|
|
|
|
return person
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-07-09 10:01:43 +05:30
|
|
|
def try_to_find_person_from_gramps_id(self,val):
|
|
|
|
"""finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, a new Person is added to the database."""
|
|
|
|
|
|
|
|
data = self.idtrans.get(str(val))
|
|
|
|
if data:
|
|
|
|
person = Person()
|
|
|
|
person.unserialize(cPickle.loads(data))
|
|
|
|
return person
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-06-29 08:03:25 +05:30
|
|
|
def find_person_from_gramps_id(self,val,trans):
|
2004-06-27 08:40:06 +05:30
|
|
|
"""finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, a new Person is added to the database."""
|
|
|
|
|
2004-06-29 08:03:25 +05:30
|
|
|
person = Person()
|
2004-06-27 08:40:06 +05:30
|
|
|
data = self.idtrans.get(str(val))
|
|
|
|
if data:
|
|
|
|
person.unserialize(cPickle.loads(data))
|
|
|
|
else:
|
2004-06-29 08:03:25 +05:30
|
|
|
intid = Utils.create_id()
|
|
|
|
person.set_id(intid)
|
|
|
|
person.set_gramps_id(val)
|
|
|
|
self.add_person_as(person,trans)
|
|
|
|
return person
|
2004-06-27 08:40:06 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_person_from_id(self,val,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds a Person in the database from the passed gramps' ID.
|
|
|
|
If no such Person exists, a new Person is added to the database."""
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
person = Person()
|
|
|
|
data = self.person_map.get(str(val))
|
|
|
|
if data:
|
|
|
|
person.unserialize(data)
|
|
|
|
else:
|
|
|
|
person.set_id(val)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(PERSON_KEY, val, None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.person_map.put(str(val), person.serialize())
|
|
|
|
# self.genderStats.count_person (person, self)
|
2002-10-20 19:55:16 +05:30
|
|
|
return person
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_person_no_map(self,person,gid,trans):
|
2003-05-05 07:06:21 +05:30
|
|
|
"""adds a Person to the database if the gramps' ID is known"""
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(gid)
|
|
|
|
person.set_id(gid)
|
|
|
|
if trans != None:
|
|
|
|
trans.add(PERSON_KEY, gid, None)
|
|
|
|
self.person_map.set(str(gid),person.serialize())
|
2004-02-21 11:41:59 +05:30
|
|
|
# self.genderStats.count_person (person, self)
|
2004-03-30 10:20:24 +05:30
|
|
|
return gid
|
2003-05-05 07:06:21 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_source(self,source,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Source instance to the database, assigning it a gramps'
|
|
|
|
ID number"""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
index = self.sprefix % self.smap_index
|
2004-02-21 11:41:59 +05:30
|
|
|
while self.source_map.get(str(index)):
|
2004-02-14 11:10:30 +05:30
|
|
|
self.smap_index = self.smap_index + 1
|
|
|
|
index = self.sprefix % self.smap_index
|
|
|
|
source.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(SOURCE_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.source_map.put(str(index),source.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.smap_index = self.smap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_event(self,event,trans):
|
2004-02-19 10:35:43 +05:30
|
|
|
"""adds a Event instance to the database, assigning it a gramps'
|
|
|
|
ID number"""
|
|
|
|
index = self.eprefix % self.emap_index
|
2004-02-21 11:41:59 +05:30
|
|
|
while self.event_map.get(str(index)):
|
2004-02-19 10:35:43 +05:30
|
|
|
self.emap_index += 1
|
|
|
|
index = self.eprefix % self.emap_index
|
|
|
|
event.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(EVENT_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.event_map.put(str(index),event.serialize())
|
2004-02-19 10:35:43 +05:30
|
|
|
self.emap_index += 1
|
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_source_no_map(self,source,index,trans):
|
2003-05-05 07:06:21 +05:30
|
|
|
"""adds a Source to the database if the gramps' ID is known"""
|
2004-02-14 11:10:30 +05:30
|
|
|
source.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(SOURCE_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.source_map.put(str(index),source.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.smap_index = self.smap_index + 1
|
2003-05-05 07:06:21 +05:30
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_event_no_map(self,event,index,trans):
|
2004-02-19 10:35:43 +05:30
|
|
|
"""adds a Source to the database if the gramps' ID is known"""
|
|
|
|
event.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(EVENT_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.event_map.put(str(index),event.serialize())
|
2004-02-19 10:35:43 +05:30
|
|
|
self.emap_index += 1
|
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_source(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Source in the database using the gid and map
|
2002-10-20 19:55:16 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Source exists, a new Source instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2004-02-14 11:10:30 +05:30
|
|
|
map - map build by find_source of external to gramp's IDs"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
data = self.source_map.get(str(map[gid]))
|
2004-02-21 11:41:59 +05:30
|
|
|
source = Source()
|
|
|
|
source.unserialize(data)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
source = Source()
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_source(source,trans)
|
2002-10-20 19:55:16 +05:30
|
|
|
return source
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_event(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Event in the database using the gid and map
|
2004-02-19 10:35:43 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Event exists, a new Event instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2004-02-19 10:35:43 +05:30
|
|
|
map - map build by find_source of external to gramp's IDs"""
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
event = Event()
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
data = self.event_map.get(str(map[gid]))
|
|
|
|
event.serialize(data)
|
2004-02-19 10:35:43 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_event(event,trans)
|
2004-02-19 10:35:43 +05:30
|
|
|
return event
|
|
|
|
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
def try_to_find_source_from_id(self,val):
|
|
|
|
"""finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, None is returned."""
|
|
|
|
|
|
|
|
data = self.source_map.get(str(val))
|
|
|
|
if data:
|
|
|
|
source = Source()
|
|
|
|
source.unserialize(data)
|
|
|
|
return source
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_source_from_id(self,val,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds a Source in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, a new Source is added to the database."""
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
source = Source()
|
|
|
|
if self.source_map.get(str(val)):
|
|
|
|
source.unserialize(self.source_map.get(str(val)))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
self.add_source_no_map(source,val,trans)
|
2002-10-20 19:55:16 +05:30
|
|
|
return source
|
|
|
|
|
2004-02-19 10:35:43 +05:30
|
|
|
def find_event_from_id(self,val):
|
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, a new Family is added to the database."""
|
2004-02-22 00:29:45 +05:30
|
|
|
data = self.event_map.get(str(val))
|
2004-02-21 11:41:59 +05:30
|
|
|
if data:
|
|
|
|
event = Event()
|
|
|
|
event.unserialize(data)
|
|
|
|
return event
|
|
|
|
else:
|
|
|
|
return None
|
2004-02-19 10:35:43 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_object(self,object,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Object instance to the database, assigning it a gramps'
|
|
|
|
ID number"""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
index = self.oprefix % self.omap_index
|
2004-02-21 11:41:59 +05:30
|
|
|
while self.media_map.get(str(index)):
|
2004-02-14 11:10:30 +05:30
|
|
|
self.omap_index = self.omap_index + 1
|
|
|
|
index = self.oprefix % self.omap_index
|
|
|
|
object.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(MEDIA_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_map.put(str(index),object.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.omap_index = self.omap_index + 1
|
2003-05-08 22:42:10 +05:30
|
|
|
self.added_files.append(object)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_object(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds an Object in the database using the gid and map
|
2002-10-20 19:55:16 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Object exists, a new Object instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2004-02-14 11:10:30 +05:30
|
|
|
map - map build by find_object of external to gramp's IDs"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(gid)
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
object = MediaObject()
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
object.unserialize(self.media_map.get(str(map[gid])))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_object(object,trans)
|
2002-10-20 19:55:16 +05:30
|
|
|
return object
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_object_no_conflicts(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds an Object in the database using the gid and map
|
2003-05-05 07:06:21 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Object exists, a new Object instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2004-02-14 11:10:30 +05:30
|
|
|
map - map build by find_object of external to gramp's IDs"""
|
2003-05-05 07:06:21 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid = str(gid)
|
2004-02-21 11:41:59 +05:30
|
|
|
object = MediaObject()
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
object.unserialize(self.media_map.get(str(map[gid])))
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
if self.media_map.get(str(gid)):
|
|
|
|
map[gid] = self.add_object(object,trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_object_no_map(object,gid,trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
return object
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_object_no_map(self,object,index,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds an Object to the database if the gramps' ID is known"""
|
|
|
|
index = str(index)
|
2004-02-14 11:10:30 +05:30
|
|
|
object.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(MEDIA_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.media_map.put(str(index),object.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.omap_index = self.omap_index + 1
|
2003-05-08 22:42:10 +05:30
|
|
|
self.added_files.append(object)
|
2002-10-20 19:55:16 +05:30
|
|
|
return index
|
|
|
|
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
def try_to_find_object_from_id(self,gid):
|
|
|
|
"""finds an Object in the database from the passed gramps' ID.
|
|
|
|
If no such Object exists, None is returned."""
|
|
|
|
|
|
|
|
data = self.media_map.get(str(gid))
|
|
|
|
if data:
|
|
|
|
mobject = MediaObject()
|
|
|
|
mobject.unserialize(data)
|
|
|
|
return mobject
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_object_from_id(self,gid,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds an Object in the database from the passed gramps' ID.
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
If no such Object exists, a new Object is added to the database."""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
object = MediaObject()
|
2004-03-30 10:20:24 +05:30
|
|
|
if self.media_map.get(str(gid)):
|
|
|
|
object.unserialize(self.media_map.get(str(gid)))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
self.add_object_no_map(object,gid,trans)
|
2002-10-20 19:55:16 +05:30
|
|
|
return object
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def has_object_id(self,gid):
|
|
|
|
"""finds an Object in the database from the passed gramps' ID.
|
|
|
|
If no such Source exists, a new Source is added to the database."""
|
|
|
|
|
|
|
|
return self.media_map.get(str(gid)) != None
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_place(self,place,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Place instance to the database, assigning it a gramps'
|
|
|
|
ID number"""
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
index = self.pprefix % self.lmap_index
|
2004-02-21 11:41:59 +05:30
|
|
|
while self.place_map.get(str(index)):
|
2004-02-14 11:10:30 +05:30
|
|
|
self.lmap_index = self.lmap_index + 1
|
|
|
|
index = self.pprefix % self.lmap_index
|
|
|
|
place.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(PLACE_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.place_map.put(str(index),place.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.lmap_index = self.lmap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def remove_object(self,gid,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
if transaction != None:
|
|
|
|
old_data = self.media_map.get(str(gid))
|
|
|
|
transaction.add(MEDIA_KEY,gid,old_data)
|
|
|
|
self.media_map.delete(str(gid))
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def remove_place(self,gid,transaction):
|
2004-03-30 10:20:24 +05:30
|
|
|
if transaction != None:
|
|
|
|
old_data = self.place_map.get(str(gid))
|
|
|
|
transaction.add(PLACE_KEY,gid,old_data)
|
|
|
|
self.place_map.delete(str(gid))
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_place_as(self,place,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
2004-04-28 09:36:25 +05:30
|
|
|
trans.add(PLACE_KEY,place.get_id(),None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.place_map.put(str(place.get_id()),place.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
return place.get_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_place_no_conflicts(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Place in the database using the gid and map
|
2002-10-20 19:55:16 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Place exists, a new Place instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2002-10-20 19:55:16 +05:30
|
|
|
map - map build by findPlace of external to gramp's IDs"""
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(str(gid)):
|
2004-02-21 11:41:59 +05:30
|
|
|
place = Place()
|
2004-03-30 10:20:24 +05:30
|
|
|
data = self.place_map[str(map[gid])]
|
2004-02-21 11:41:59 +05:30
|
|
|
place.unserialize(data)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
place = Place()
|
2004-03-30 10:20:24 +05:30
|
|
|
if self.place_map.has_key(str(gid)):
|
|
|
|
map[gid] = self.add_place(place,trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
place.set_id(str(gid))
|
|
|
|
map[str(gid)] = self.add_place_as(place,trans)
|
|
|
|
self.place_map.put(str(gid),place.serialize())
|
2003-05-05 07:06:21 +05:30
|
|
|
return place
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def add_place_no_map(self,place,index,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Place to the database if the gramps' ID is known"""
|
|
|
|
|
|
|
|
index = str(index)
|
2004-02-14 11:10:30 +05:30
|
|
|
place.set_id(index)
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(PLACE_KEY,index,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.place_map.put(str(index), place.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.lmap_index = self.lmap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return index
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_place_from_id(self,gid,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, a new Place is added to the database."""
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
data = self.place_map.get(str(gid))
|
2004-02-21 11:41:59 +05:30
|
|
|
place = Place()
|
|
|
|
if not data:
|
2004-03-30 10:20:24 +05:30
|
|
|
place.id = gid
|
|
|
|
if trans != None:
|
|
|
|
trans.add(PLACE_KEY,gid,None)
|
|
|
|
self.place_map.put(str(gid),place.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.lmap_index = self.lmap_index + 1
|
2004-02-21 11:41:59 +05:30
|
|
|
else:
|
|
|
|
place.unserialize(data)
|
2002-10-20 19:55:16 +05:30
|
|
|
return place
|
|
|
|
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
def try_to_find_place_from_id(self,gid):
|
|
|
|
"""finds a Place in the database from the passed gramps' ID.
|
|
|
|
If no such Place exists, None is returned."""
|
|
|
|
|
|
|
|
data = self.place_map.get(str(gid))
|
|
|
|
|
|
|
|
if data:
|
|
|
|
place = Place()
|
|
|
|
place.unserialize(data)
|
|
|
|
return place
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2003-10-21 08:37:19 +05:30
|
|
|
def sortbyplace(self,f,s):
|
2004-06-20 08:36:21 +05:30
|
|
|
return cmp(self.placesortmap[f], self.placesortmap[s])
|
2004-03-22 10:11:35 +05:30
|
|
|
|
|
|
|
def sortbysource(self,f,s):
|
|
|
|
fp = self.source_map[f][1].upper()
|
|
|
|
sp = self.source_map[s][1].upper()
|
|
|
|
return cmp(fp,sp)
|
|
|
|
|
|
|
|
def sortbymedia(self,f,s):
|
|
|
|
fp = self.media_map[f][3].upper()
|
|
|
|
sp = self.media_map[s][3].upper()
|
2004-02-21 11:41:59 +05:30
|
|
|
return cmp(fp,sp)
|
2003-10-21 08:37:19 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def sort_place_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.place_map:
|
2004-06-20 08:36:21 +05:30
|
|
|
self.placesortmap = {}
|
|
|
|
for key in self.place_map.keys():
|
|
|
|
self.placesortmap[key] = self.place_map[key][1].upper()
|
|
|
|
keys = self.placesortmap.keys()
|
|
|
|
keys.sort(self.sortbyplace)
|
|
|
|
del self.placesortmap
|
2004-02-29 00:16:40 +05:30
|
|
|
return keys
|
|
|
|
return []
|
2003-10-21 08:37:19 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def sort_media_keys(self):
|
|
|
|
if self.media_map:
|
|
|
|
keys = self.media_map.keys()
|
|
|
|
keys.sort(self.sortbymedia)
|
|
|
|
return keys
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def sort_source_keys(self):
|
|
|
|
if self.source_map:
|
|
|
|
keys = self.source_map.keys()
|
|
|
|
keys.sort(self.sortbysource)
|
|
|
|
return keys
|
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_id_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.place_map:
|
|
|
|
return self.place_map.keys()
|
|
|
|
else:
|
|
|
|
return []
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_id(self,key):
|
2004-02-21 11:41:59 +05:30
|
|
|
place = Place()
|
2004-02-22 10:27:06 +05:30
|
|
|
place.unserialize(self.place_map.get(str(key)))
|
2004-02-21 11:41:59 +05:30
|
|
|
return place
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_place_display(self,key):
|
2004-02-21 11:41:59 +05:30
|
|
|
# fix this up better
|
|
|
|
place = Place()
|
2004-06-15 09:13:33 +05:30
|
|
|
place.unserialize(self.place_map[str(key)])
|
2004-02-21 11:41:59 +05:30
|
|
|
return place.get_display_info()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_source_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.source_map:
|
|
|
|
return self.source_map.keys()
|
|
|
|
return []
|
2004-02-21 11:41:59 +05:30
|
|
|
|
|
|
|
def get_object_keys(self):
|
2004-02-29 00:16:40 +05:30
|
|
|
if self.media_map:
|
|
|
|
return self.media_map.keys()
|
|
|
|
return []
|
2003-12-30 00:07:44 +05:30
|
|
|
|
2004-06-23 02:19:22 +05:30
|
|
|
def get_event_keys(self):
|
|
|
|
if self.event_map:
|
|
|
|
return self.event_map.keys()
|
|
|
|
return []
|
|
|
|
|
2003-12-30 00:07:44 +05:30
|
|
|
def sortbysource(self,f,s):
|
2004-02-25 02:23:58 +05:30
|
|
|
f1 = self.source_map[f][1].upper()
|
|
|
|
s1 = self.source_map[s][1].upper()
|
|
|
|
return cmp(f1,s1)
|
2003-12-30 00:07:44 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def set_source_keys(self):
|
2004-02-21 11:41:59 +05:30
|
|
|
keys = self.source_map.keys()
|
2003-12-30 00:07:44 +05:30
|
|
|
if type(keys) == type([]):
|
|
|
|
keys.sort(self.sortbyplace)
|
|
|
|
return keys
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_source_display(self,key):
|
2004-02-21 11:41:59 +05:30
|
|
|
source = Source()
|
|
|
|
source.unserialize(self.source_map.get(str(key)))
|
|
|
|
return source.get_display_info()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def get_source(self,key):
|
2004-02-22 10:27:06 +05:30
|
|
|
source = Source()
|
|
|
|
source.unserialize(self.source_map[key])
|
|
|
|
return source
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def build_source_display(self,nkey,okey=None):
|
2004-02-21 11:41:59 +05:30
|
|
|
pass
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def new_family(self,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""adds a Family to the database, assigning a gramps' ID"""
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
index = self.fprefix % self.fmap_index
|
2004-02-21 11:41:59 +05:30
|
|
|
while self.family_map.get(str(index)):
|
2004-02-14 11:10:30 +05:30
|
|
|
self.fmap_index = self.fmap_index + 1
|
|
|
|
index = self.fprefix % self.fmap_index
|
|
|
|
self.fmap_index = self.fmap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
family = Family()
|
2004-04-17 00:45:02 +05:30
|
|
|
family.set_id(unicode(index))
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
trans.add(FAMILY_KEY, index, None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.family_map.put(str(index),family.serialize())
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def new_family_no_map(self,gid,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, a new Family is added to the database."""
|
|
|
|
|
|
|
|
family = Family()
|
2004-03-30 10:20:24 +05:30
|
|
|
family.set_id(gid)
|
|
|
|
if trans != None:
|
2004-05-19 11:43:36 +05:30
|
|
|
trans.add(FAMILY_KEY, gid, None)
|
2004-03-30 10:20:24 +05:30
|
|
|
self.family_map.put(str(gid),family.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.fmap_index = self.fmap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_family_with_map(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Family in the database using the gid and map
|
2002-10-20 19:55:16 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Family exists, a new Family instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2004-02-14 11:10:30 +05:30
|
|
|
map - map build by find_family_with_map of external to gramp's IDs"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
2004-02-21 11:41:59 +05:30
|
|
|
family = Family()
|
2004-03-30 10:20:24 +05:30
|
|
|
data = self.family_map.get(str(map[gid]))
|
2004-02-21 11:41:59 +05:30
|
|
|
family.unserialize(data)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-05-24 10:02:19 +05:30
|
|
|
family = self.new_family(trans)
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = family.get_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_family_no_map(self,val,trans):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, a new Family is added to the database."""
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
family = Family()
|
|
|
|
data = self.family_map.get(str(val))
|
|
|
|
if data:
|
|
|
|
family.unserialize(data)
|
|
|
|
else:
|
2002-10-20 19:55:16 +05:30
|
|
|
family.id = val
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans:
|
|
|
|
trans.add(FAMILY_KEY,val,None)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.family_map.put(str(val),family.serialize())
|
2004-02-14 11:10:30 +05:30
|
|
|
self.fmap_index = self.fmap_index + 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
def find_family_from_id(self,val):
|
|
|
|
"""finds a Family in the database from the passed gramps' ID.
|
|
|
|
If no such Family exists, a new Family is added to the database."""
|
2004-02-21 11:41:59 +05:30
|
|
|
data = self.family_map.get(str(val))
|
|
|
|
if data:
|
|
|
|
family = Family()
|
|
|
|
family.unserialize(data)
|
|
|
|
return family
|
|
|
|
else:
|
|
|
|
return None
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def delete_family(self,family_id,trans):
|
2004-02-14 11:10:30 +05:30
|
|
|
"""deletes the Family instance from the database"""
|
2004-02-21 11:41:59 +05:30
|
|
|
if self.family_map.get(str(family_id)):
|
2004-03-30 10:20:24 +05:30
|
|
|
if trans != None:
|
|
|
|
old_data = self.family_map.get(str(family_id))
|
|
|
|
trans.add(FAMILY_KEY,family_id,old_data)
|
2004-02-22 10:27:06 +05:30
|
|
|
self.family_map.delete(str(family_id))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_family_no_conflicts(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Family in the database using the gid and map
|
2003-05-05 07:06:21 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Family exists, a new Family instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2003-05-05 07:06:21 +05:30
|
|
|
map - map build by findFamily of external to gramp's IDs"""
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(str(gid)):
|
2004-02-21 11:41:59 +05:30
|
|
|
family = Family()
|
2004-03-30 10:20:24 +05:30
|
|
|
family.unserialize(self.family_map.get(str(map[str(gid)])))
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
if self.family_map.has_key(str(gid)):
|
|
|
|
family = self.new_family(trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
family = self.new_family_no_map(str(gid),trans)
|
|
|
|
map[gid] = family.get_id()
|
2003-05-05 07:06:21 +05:30
|
|
|
return family
|
|
|
|
|
2004-05-24 10:02:19 +05:30
|
|
|
def find_source_no_conflicts(self,gid,map,trans):
|
2004-03-30 10:20:24 +05:30
|
|
|
"""finds a Source in the database using the gid and map
|
2003-05-05 07:06:21 +05:30
|
|
|
variables to translate between the external ID and gramps'
|
|
|
|
internal ID. If no such Source exists, a new Source instance
|
|
|
|
is created.
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
gid - external ID number
|
2003-05-05 07:06:21 +05:30
|
|
|
map - map build by findSource of external to gramp's IDs"""
|
|
|
|
|
2004-02-21 11:41:59 +05:30
|
|
|
source = Source()
|
2004-03-30 10:20:24 +05:30
|
|
|
if map.has_key(gid):
|
|
|
|
source.unserialize(self.source_map.get(str(map[gid])))
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
if self.source_map.get(str(gid)):
|
|
|
|
map[gid] = self.add_source(source,trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
else:
|
2004-03-30 10:20:24 +05:30
|
|
|
map[gid] = self.add_source(source,trans)
|
2003-05-05 07:06:21 +05:30
|
|
|
return source
|
2004-03-10 10:45:06 +05:30
|
|
|
|
|
|
|
def set_column_order(self,list):
|
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['columns'] = list
|
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def set_place_column_order(self,list):
|
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['place_columns'] = list
|
|
|
|
|
|
|
|
def set_source_column_order(self,list):
|
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['source_columns'] = list
|
|
|
|
|
|
|
|
def set_media_column_order(self,list):
|
|
|
|
if self.metadata != None:
|
|
|
|
self.metadata['media_columns'] = list
|
|
|
|
|
2004-03-10 10:45:06 +05:30
|
|
|
def get_column_order(self):
|
2004-06-03 08:58:46 +05:30
|
|
|
default = [(1,1),(1,2),(1,3),(0,4),(1,5),(0,6),(0,7)]
|
2004-03-10 10:45:06 +05:30
|
|
|
if self.metadata == None:
|
2004-06-03 08:58:46 +05:30
|
|
|
return default
|
2004-03-10 10:45:06 +05:30
|
|
|
else:
|
2004-06-03 08:58:46 +05:30
|
|
|
cols = self.metadata.get('columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
2004-03-10 10:45:06 +05:30
|
|
|
|
2004-03-22 10:11:35 +05:30
|
|
|
def get_place_column_order(self):
|
|
|
|
default = [(1,1),(1,2),(0,3),(1,4),(0,5),(1,6),(0,7),(0,8)]
|
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('place_columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
|
|
|
def get_source_column_order(self):
|
|
|
|
default = [(1,1),(1,2),(1,3),(0,4)]
|
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('source_columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
|
|
|
|
|
|
|
def get_media_column_order(self):
|
|
|
|
default = [(1,1),(1,2),(1,3)]
|
|
|
|
if self.metadata == None:
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
cols = self.metadata.get('meda_columns',default)
|
|
|
|
if len(cols) != len(default):
|
|
|
|
return cols + default[len(cols):]
|
|
|
|
else:
|
|
|
|
return cols
|
2004-03-30 10:20:24 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Transaction
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Transaction:
|
|
|
|
|
2004-05-20 05:42:14 +05:30
|
|
|
def __init__(self,msg,db):
|
|
|
|
self.db = db
|
|
|
|
self.first = None
|
|
|
|
self.last = None
|
2004-03-30 10:20:24 +05:30
|
|
|
|
2004-04-04 10:09:52 +05:30
|
|
|
def get_description(self):
|
|
|
|
return self.msg
|
|
|
|
|
|
|
|
def set_description(self,msg):
|
|
|
|
self.msg = msg
|
|
|
|
|
2004-03-30 10:20:24 +05:30
|
|
|
def add(self, type, gid, data):
|
2004-05-20 05:42:14 +05:30
|
|
|
self.last = self.db.append(cPickle.dumps((type,gid,data),1))
|
|
|
|
if self.first == None:
|
|
|
|
self.first = self.last
|
2004-03-22 10:11:35 +05:30
|
|
|
|
2004-05-20 05:42:14 +05:30
|
|
|
def get_recnos(self):
|
|
|
|
return range (self.first, self.last+1)
|
|
|
|
|
|
|
|
def get_record(self,id):
|
|
|
|
return cPickle.loads(self.db[id])
|
2004-03-30 10:20:24 +05:30
|
|
|
|
|
|
|
def __len__(self):
|
2004-05-26 08:59:00 +05:30
|
|
|
if self.last and self.first:
|
|
|
|
return self.last - self.first + 1
|
|
|
|
return 0
|
2004-03-30 10:20:24 +05:30
|
|
|
|
|
|
|
def display(self):
|
2004-05-20 05:42:14 +05:30
|
|
|
for record in self.get_recnos():
|
|
|
|
(key,gid,val) = self.get_record(record)
|
2004-03-30 10:20:24 +05:30
|
|
|
if key == PERSON_KEY:
|
|
|
|
if val:
|
|
|
|
print "PERSON %s change" % gid
|
|
|
|
else:
|
|
|
|
print "PERSON %s remove" % gid
|
|
|
|
elif key == FAMILY_KEY:
|
|
|
|
if val:
|
|
|
|
print "FAMILY %s change" % gid
|
|
|
|
else:
|
|
|
|
print "FAMILY %s remove" % gid
|
|
|
|
elif key == EVENT_KEY:
|
|
|
|
if val:
|
|
|
|
print "EVENT %s change" % gid
|
|
|
|
else:
|
|
|
|
print "EVENT %s remove" % gid
|
|
|
|
elif key == SOURCE_KEY:
|
|
|
|
if val:
|
|
|
|
print "SOURCE %s change" % gid
|
|
|
|
else:
|
|
|
|
print "SOURCE %s remove" % gid
|
|
|
|
elif key == MEDIA_KEY:
|
|
|
|
if val:
|
|
|
|
print "MEDIA %s change" % gid
|
|
|
|
else:
|
|
|
|
print "MEDIA %s remove" % gid
|
|
|
|
elif key == PLACE_KEY:
|
|
|
|
if val:
|
|
|
|
print "PLACE %s change" % gid
|
|
|
|
else:
|
|
|
|
print "PLACE %s remove" % gid
|
2004-05-20 05:42:14 +05:30
|
|
|
|