2005-12-20 20:48:18 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-02-03 22:03:53 +00:00
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2005-12-20 20:48:18 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
"""
|
2008-02-24 13:55:55 +00:00
|
|
|
DateBase class for GRAMPS.
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-24 13:55:55 +00:00
|
|
|
from gen.lib.date import Date
|
2005-12-20 20:48:18 +00:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Base classes
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-05-21 17:19:50 +00:00
|
|
|
class DateBase(object):
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
|
|
|
Base class for storing date information.
|
|
|
|
"""
|
|
|
|
|
2007-01-08 01:49:33 +00:00
|
|
|
def __init__(self, source=None):
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
2008-02-24 13:55:55 +00:00
|
|
|
Create a new DateBase, copying from source if not None.
|
2005-12-20 20:48:18 +00:00
|
|
|
|
2009-06-24 21:56:07 +00:00
|
|
|
:param source: Object used to initialize the new object
|
|
|
|
:type source: DateBase
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
|
|
|
if source:
|
2006-02-03 22:03:53 +00:00
|
|
|
self.date = Date(source.date)
|
2005-12-20 20:48:18 +00:00
|
|
|
else:
|
2006-03-31 19:46:41 +00:00
|
|
|
self.date = Date()
|
2005-12-20 20:48:18 +00:00
|
|
|
|
2006-09-09 17:10:13 +00:00
|
|
|
def serialize(self, no_text_date=False):
|
2007-01-08 01:49:33 +00:00
|
|
|
"""
|
2008-02-24 13:55:55 +00:00
|
|
|
Convert the object to a serialized tuple of data.
|
2007-01-08 01:49:33 +00:00
|
|
|
"""
|
2008-06-16 15:01:46 +00:00
|
|
|
if self.date is None or (self.date.is_empty() and not self.date.text):
|
2006-02-03 22:03:53 +00:00
|
|
|
date = None
|
|
|
|
else:
|
2006-09-09 17:10:13 +00:00
|
|
|
date = self.date.serialize(no_text_date)
|
2006-02-03 22:03:53 +00:00
|
|
|
return date
|
|
|
|
|
2007-01-08 01:49:33 +00:00
|
|
|
def unserialize(self, data):
|
|
|
|
"""
|
2008-02-24 13:55:55 +00:00
|
|
|
Convert a serialized tuple of data to an object.
|
2007-01-08 01:49:33 +00:00
|
|
|
"""
|
2008-03-25 23:38:24 +00:00
|
|
|
self.date = Date()
|
|
|
|
if data is not None:
|
2007-08-29 23:01:16 +00:00
|
|
|
self.date.unserialize(data)
|
2006-02-03 22:03:53 +00:00
|
|
|
|
2005-12-20 20:48:18 +00:00
|
|
|
def get_date_object(self):
|
|
|
|
"""
|
2009-06-24 21:56:07 +00:00
|
|
|
Return the :class:`~gen.lib.date.Date` object associated with the DateBase.
|
2005-12-20 20:48:18 +00:00
|
|
|
|
2009-06-24 21:56:07 +00:00
|
|
|
:returns: Returns a DateBase :class:`~gen.lib.date.Date` instance.
|
|
|
|
:rtype: :class:`~gen.lib.date.Date`
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
|
|
|
if not self.date:
|
2006-02-03 22:03:53 +00:00
|
|
|
self.date = Date()
|
2005-12-20 20:48:18 +00:00
|
|
|
return self.date
|
|
|
|
|
2007-01-08 01:49:33 +00:00
|
|
|
def set_date_object(self, date):
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
2009-06-24 21:56:07 +00:00
|
|
|
Set the :class:`~gen.lib.date.Date` object associated with the DateBase.
|
2005-12-20 20:48:18 +00:00
|
|
|
|
2009-06-24 21:56:07 +00:00
|
|
|
:param date: :class:`~gen.lib.date.Date` instance to be assigned to the DateBase
|
|
|
|
:type date: :class:`~gen.lib.date.Date`
|
2005-12-20 20:48:18 +00:00
|
|
|
"""
|
|
|
|
self.date = date
|