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