* src/RelLib.py: Move constants back to RelLib, as class attributes.

* src/Utils.py: Move constant mappings from const.py.in.
* src/const.py.in: Move constants and mappings elsewhere.
* various: Use constants from RelLib, not const.

* src/RelLib.py: Fix (int,str) types.

* src/GrampsBSDDB.py (upgrade_7): Handle case of not set default person


svn: r4737
This commit is contained in:
Alex Roitman 2005-05-30 21:38:09 +00:00
parent 3771ee4ff9
commit 5652f21069
2 changed files with 52 additions and 127 deletions

View File

@ -1,5 +1,13 @@
2005-05-30 Alex Roitman <shura@gramps-project.org>
* src/RelLib.py: Move constants back to RelLib, as class attributes.
* src/Utils.py: Move constant mappings from const.py.in.
* src/const.py.in: Move constants and mappings elsewhere.
* various: Use constants from RelLib, not const.
* src/RelLib.py: Fix (int,str) types.
2005-05-30 Martin Hawlisch <Martin.Hawlisch@gmx.de> 2005-05-30 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/src/GrampsBSDDB.py (upgrade_7): Handle case of not set default person * src/GrampsBSDDB.py (upgrade_7): Handle case of not set default person
2005-05-28 Alex Roitman <shura@gramps-project.org> 2005-05-28 Alex Roitman <shura@gramps-project.org>
* src/RelLib.py: Delegate event handle reference lookup from * src/RelLib.py: Delegate event handle reference lookup from

View File

@ -2209,19 +2209,12 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
if source: if source:
self.description = source.description self.description = source.description
self.type_int = source.type_int self.type = source.type
self.type_str = source.type_str
self.cause = source.cause self.cause = source.cause
if source.witness != None:
self.witness = source.witness[:]
else:
self.witness = None
else: else:
self.description = "" self.description = ""
self.type_int = Event.CUSTOM self.type = (Event.CUSTOM,"")
self.type_str = ""
self.cause = "" self.cause = ""
self.witness = None
def serialize(self): def serialize(self):
""" """
@ -2239,10 +2232,9 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
be considered persistent. be considered persistent.
@rtype: tuple @rtype: tuple
""" """
return (self.handle, self.gramps_id, self.type_int, self.type_str, return (self.handle, self.gramps_id, self.type, self.date,
self.date, self.description, self.place, self.cause, self.description, self.place, self.cause, self.private,
self.private, self.source_list, self.note, self.witness, self.source_list, self.note, self.media_list, self.change)
self.media_list, self.change)
def unserialize(self,data): def unserialize(self,data):
""" """
@ -2253,34 +2245,21 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
Person object Person object
@type data: tuple @type data: tuple
""" """
(self.handle, self.gramps_id, self.type_int, self.type_str, (self.handle, self.gramps_id, self.type, self.date,
self.date, self.description, self.place, self.cause, self.private, self.description, self.place, self.cause, self.private,
self.source_list, self.note, self.witness, self.media_list, self.source_list, self.note, self.media_list, self.change) = data
self.change) = data
def _has_handle_reference(self,classname,handle): def _has_handle_reference(self,classname,handle):
if classname == 'Place': if classname == 'Place':
return self.place == handle return self.place == handle
elif classname == 'Person':
return handle in [ witness.val for witness in self.witness \
if witness.type == Event.ID ]
return False return False
def _remove_handle_references(self,classname,handle_list): def _remove_handle_references(self,classname,handle_list):
if classname == 'Person' and self.witness: if classname == 'Place' and self.place in handle_list:
new_list = [ witness for witness in self.witness \
if witness.type == Event.ID and \
witness.val not in handle_list ]
self.witness = new_list
elif classname == 'Place' and self.place in handle_list:
self.place = "" self.place = ""
def _replace_handle_reference(self,classname,old_handle,new_handle): def _replace_handle_reference(self,classname,old_handle,new_handle):
if classname == 'Person' and self.witness: if classname == 'Place' and self.place == old_handle:
for witness in self.witness:
if witness.type == Event.ID and witness.val == old_handle:
witness.val = new_handle
elif classname == 'Place' and self.place == old_handle:
self.place = new_handle self.place = new_handle
def get_text_data_list(self): def get_text_data_list(self):
@ -2290,7 +2269,8 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
@return: Returns the list of all textual attributes of the object. @return: Returns the list of all textual attributes of the object.
@rtype: list @rtype: list
""" """
return [self.description,self.name,self.cause,self.get_date(),self.gramps_id] return [self.description,self.type[1],self.cause,
self.get_date(),self.gramps_id]
def get_text_data_child_list(self): def get_text_data_child_list(self):
""" """
@ -2300,8 +2280,6 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
@rtype: list @rtype: list
""" """
check_list = self.media_list + self.source_list check_list = self.media_list + self.source_list
if self.witness:
check_list = check_list + self.witness
if self.note: if self.note:
check_list.append(self.note) check_list.append(self.note)
return check_list return check_list
@ -2336,45 +2314,7 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
@return: Returns the list of objects refereincing primary objects. @return: Returns the list of objects refereincing primary objects.
@rtype: list @rtype: list
""" """
return self.media_list + self.source_list + \ return self.media_list + self.source_list
[witness for witness in self.witness
if witness.type == Event.ID]
def get_witness_list(self):
"""
Returns the list of L{Witness} instances associated with the Event.
@return: Returns the list of L{Witness} objects assocated with
the object.
@rtype: list
"""
return self.witness
def set_witness_list(self,witness_list):
"""
Assigns the passed list to the object's list of L{Witness}
instances. To clear the list, None should be passed.
@param witness_list: List of L{Witness} instances to ba associated
with the Event.
@type witness_list: list
"""
if witness_list:
self.witness = witness_list
else:
self.witness = None
def add_witness(self,witness):
"""
Adds the L{Witness} instance to the Event's witness list.
@param witness: The L{Witness} instance to be added to the
Event's list of L{Witness} instances.
@type witness: L{Witness}
"""
if self.witness:
self.witness.append(witness)
else:
self.witness = [witness]
def is_empty(self): def is_empty(self):
""" """
@ -2387,9 +2327,9 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
place = self.get_place_handle() place = self.get_place_handle()
description = self.description description = self.description
cause = self.cause cause = self.cause
name = self.name the_type = self.type
return ((not name or name == "Birth" or name == "Death") and return (the_type == (Event.CUSTOM,"") and date.is_empty()
date.is_empty() and not place and not description and not cause) and not place and not description and not cause)
def are_equal(self,other): def are_equal(self,other):
""" """
@ -2402,10 +2342,11 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
""" """
if other == None: if other == None:
other = Event (None) other = Event (None)
if (self.name != other.name or if self.type[0] != other.type[0] or \
((self.place or other.place) and (self.place != other.place)) or self.type[0] == Event.CUSTOM and self.type[1] != other.type[1]) or \
self.description != other.description or self.cause != other.cause or ((self.place or other.place) and (self.place != other.place)) or \
self.private != other.private or self.description != other.description or self.cause != other.cause \
or self.private != other.private or
(not self.get_date_object().is_equal(other.get_date_object())) or (not self.get_date_object().is_equal(other.get_date_object())) or
len(self.get_source_references()) != len(other.get_source_references())): len(self.get_source_references()) != len(other.get_source_references())):
return False return False
@ -2417,39 +2358,25 @@ class Event(PrimaryObject,PrivateSourceNote,MediaBase,DateBase,PlaceBase):
return False return False
index += 1 index += 1
witness_list = self.get_witness_list()
other_list = other.get_witness_list()
if (witness_list and not other_list) or \
(other_list and not witness_list):
return False
if witness_list and other_list:
another_list = other_list[:]
for a in witness_list:
if a in another_list:
another_list.remove(a)
else:
return False
if another_list:
return False
return True return True
def set_name(self,name): def set_type(self,the_type):
""" """
Sets the name of the Event to the passed string. Sets the type of the Event to the passed (int,str) tuple.
@param name: Name to assign to the Event @param the_type: Type to assign to the Event
@type name: str @type the_type: tuple
""" """
self.name = name self.type = the_type
def get_name(self): def get_type(self):
""" """
Returns the name of the Event. Returns the type of the Event.
@return: Name of the Event @return: Type of the Event
@rtype: str @rtype: tuple
""" """
return self.name return self.type
def set_cause(self,cause): def set_cause(self,cause):
""" """
@ -3570,7 +3497,7 @@ class Attribute(PrivateSourceNote):
self.type = source.type self.type = source.type
self.value = source.value self.value = source.value
else: else:
self.type = "" self.type = (Attribute.CUSTOM,"")
self.value = "" self.value = ""
def get_text_data_list(self): def get_text_data_list(self):
@ -3580,7 +3507,7 @@ class Attribute(PrivateSourceNote):
@return: Returns the list of all textual attributes of the object. @return: Returns the list of all textual attributes of the object.
@rtype: list @rtype: list
""" """
return [self.type,self.value] return [self.value]
def get_text_data_child_list(self): def get_text_data_child_list(self):
""" """
@ -3760,7 +3687,7 @@ class Name(PrivateSourceNote,DateBase):
self.surname = "" self.surname = ""
self.suffix = "" self.suffix = ""
self.title = "" self.title = ""
self.type = "Birth Name" self.type = (Name.BIRTH,"")
self.prefix = "" self.prefix = ""
self.patronymic = "" self.patronymic = ""
self.sname = '@' self.sname = '@'
@ -3776,7 +3703,7 @@ class Name(PrivateSourceNote,DateBase):
@rtype: list @rtype: list
""" """
return [self.first_name,self.surname,self.suffix,self.title, return [self.first_name,self.surname,self.suffix,self.title,
self.type,self.prefix,self.patronymic,self.get_date()] self.type[1],self.prefix,self.patronymic,self.get_date()]
def get_text_data_child_list(self): def get_text_data_child_list(self):
""" """
@ -4469,13 +4396,11 @@ class RepoRef(BaseObject,NoteBase):
if source: if source:
self.ref = source.ref self.ref = source.ref
self.call_number = source.call_number self.call_number = source.call_number
self.media_type_int = source.media_type_int self.media_type = source.media_type
self.media_type_str = source.media_type_str
else: else:
self.ref = None self.ref = None
self.call_number = "" self.call_number = ""
self.media_type_int = RepoRef.CUSTOM self.media_type = (RepoRef.CUSTOM,"")
self.media_type_str = ""
def get_text_data_list(self): def get_text_data_list(self):
""" """
@ -4484,7 +4409,7 @@ class RepoRef(BaseObject,NoteBase):
@return: Returns the list of all textual attributes of the object. @return: Returns the list of all textual attributes of the object.
@rtype: list @rtype: list
""" """
return [self.call_number,self.media_type_str] return [self.call_number,self.media_type[1]]
def get_text_data_child_list(self): def get_text_data_child_list(self):
""" """
@ -4523,18 +4448,10 @@ class RepoRef(BaseObject,NoteBase):
return self.call_number return self.call_number
def get_media_type(self): def get_media_type(self):
if self.media_type_int == RepoRef.CUSTOM: return self.media_type
return self.media_type_str
else:
return self.media_type_int
def set_media_type(self,media_type): def set_media_type(self,media_type):
if type(media_type) == int: self.media_type = media_type
self.media_type_int = media_type
self.media_type_str = ""
else:
self.media_type_int = RepoRef.CUSTOM
self.media_type_str = media_type
class Repository(PrimaryObject,NoteBase): class Repository(PrimaryObject,NoteBase):
"""A location where collections of Sources are found""" """A location where collections of Sources are found"""