Added to_struct methods to all gen.lib objects; 2623: Import Export Merge (GEPS 009)
svn: r20205
This commit is contained in:
parent
35bc7024d0
commit
8dddccf6b6
@ -68,6 +68,23 @@ class Address(SecondaryObject, PrivacyBase, CitationBase, NoteBase, DateBase,
|
||||
DateBase.serialize(self),
|
||||
LocationBase.serialize(self))
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.serialize(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"date": DateBase.to_struct(self),
|
||||
"street": self.street,
|
||||
"locality": self.locality,
|
||||
"city": self.city,
|
||||
"country": self.county,
|
||||
"state": self.state,
|
||||
"country": self.country,
|
||||
"postal": self.postal,
|
||||
"phone": self.phone}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -61,6 +61,12 @@ class AddressBase(object):
|
||||
"""
|
||||
return [addr.serialize() for addr in self.address_list]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return [addr.to_struct() for addr in self.address_list]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -65,6 +65,12 @@ class AttributeBase(object):
|
||||
"""
|
||||
return [attr.serialize() for attr in self.attribute_list]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return [attr.to_struct() for attr in self.attribute_list]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -83,6 +83,16 @@ class Attribute(SecondaryObject, PrivacyBase, CitationBase, NoteBase):
|
||||
NoteBase.serialize(self),
|
||||
self.type.serialize(), self.value)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.serialize(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"type": self.type.to_struct(),
|
||||
"value": self.value}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -51,6 +51,12 @@ class BaseObject(object):
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
assert False, "Needs to be overridden in the derived class"
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -75,6 +75,17 @@ class ChildRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
|
||||
self.frel.serialize(),
|
||||
self.mrel.serialize())
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"ref": RefBase.to_struct(self),
|
||||
"frel": self.frel.to_struct(),
|
||||
"mrel": self.mrel.to_struct()}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -91,6 +91,22 @@ class Citation(MediaBase, NoteBase, PrimaryObject, DateBase):
|
||||
self.change, # 9
|
||||
self.private) # 10
|
||||
|
||||
def to_struct(self, no_text_date = False):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return {"handle": self.handle, # 0
|
||||
"gramps_id": self.gramps_id, # 1
|
||||
"date": DateBase.to_struct(self), # 2
|
||||
"page": unicode(self.page), # 3
|
||||
"confidence": self.confidence, # 4
|
||||
"source_handle": self.source_handle, # 5
|
||||
"note_list": NoteBase.to_struct(self), # 6
|
||||
"media_list": MediaBase.to_struct(self), # 7
|
||||
"datamap": self.datamap, # 8
|
||||
"change": self.change, # 9
|
||||
"private": self.private} # 10
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -69,6 +69,12 @@ class CitationBase(object):
|
||||
"""
|
||||
return self.citation_list
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return self.citation_list
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -637,6 +637,18 @@ class Date(object):
|
||||
return (self.calendar, self.modifier, self.quality,
|
||||
self.dateval, text, self.sortval, self.newyear)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert to struct for data storage.
|
||||
"""
|
||||
return {"calendar": self.calendar,
|
||||
"modifier": self.modifier,
|
||||
"quality": self.quality,
|
||||
"dateval": self.dateval,
|
||||
"text": self.text,
|
||||
"sortval": self.sortval,
|
||||
"newyear": self.newyear}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Load from the format created by serialize.
|
||||
|
@ -63,6 +63,16 @@ class DateBase(object):
|
||||
date = self.date.serialize(no_text_date)
|
||||
return date
|
||||
|
||||
def to_struct(self, no_text_date=False):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
if self.date is None:
|
||||
date = Date().to_struct()
|
||||
else:
|
||||
date = self.date.to_struct()
|
||||
return date
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -117,6 +117,37 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
|
||||
AttributeBase.serialize(self),
|
||||
self.change, self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in the event to a Python tuple that
|
||||
represents all the data elements.
|
||||
|
||||
This method is used to convert the object into a form that can easily
|
||||
be saved to a database.
|
||||
|
||||
These elements may be primitive Python types (string, integers),
|
||||
complex Python types (lists or tuples, or Python objects. If the
|
||||
target database cannot handle complex types (such as objects or
|
||||
lists), the database is responsible for converting the data into
|
||||
a form that it can use.
|
||||
|
||||
:returns: Returns a python tuple containing the data that should
|
||||
be considered persistent.
|
||||
:rtype: tuple
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"type": self.__type.to_struct(),
|
||||
"date": DateBase.to_struct(self),
|
||||
"description": self.__description,
|
||||
"place": self.place,
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"media_list": MediaBase.to_struct(self),
|
||||
"attribute_list": AttributeBase.to_struct(self),
|
||||
"change": self.change,
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -77,6 +77,18 @@ class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase):
|
||||
self.__role.serialize()
|
||||
)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {
|
||||
"private": PrivacyBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"attribute_list": AttributeBase.to_struct(self),
|
||||
"ref": RefBase.to_struct(self),
|
||||
"role": self.__role.to_struct()
|
||||
}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -128,6 +128,40 @@ class Family(CitationBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase,
|
||||
NoteBase.serialize(self),
|
||||
self.change, TagBase.serialize(self), self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in the event to a Python tuple that
|
||||
represents all the data elements.
|
||||
|
||||
This method is used to convert the object into a form that can easily
|
||||
be saved to a database.
|
||||
|
||||
These elements may be primitive Python types (string, integers),
|
||||
complex Python types (lists or tuples, or Python objects. If the
|
||||
target database cannot handle complex types (such as objects or
|
||||
lists), the database is responsible for converting the data into
|
||||
a form that it can use.
|
||||
|
||||
:returns: Returns a python tuple containing the data that should
|
||||
be considered persistent.
|
||||
:rtype: tuple
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"father_handle": self.father_handle,
|
||||
"mother_handle": self.mother_handle,
|
||||
"child_ref_list": [cr.to_struct() for cr in self.child_ref_list],
|
||||
"type": self.type.to_struct(),
|
||||
"event_ref_list": [er.to_struct() for er in self.event_ref_list],
|
||||
"media_list": MediaBase.to_struct(self),
|
||||
"attribute_list": AttributeBase.to_struct(self),
|
||||
"lds_ord_list": LdsOrdBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"change": self.change,
|
||||
"tag_list": TagBase.to_struct(self),
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -198,6 +198,11 @@ class GrampsType(object):
|
||||
"""Convert the object to a serialized tuple of data. """
|
||||
return (self.__value, self.__string)
|
||||
|
||||
def to_struct(self):
|
||||
"""Convert the object to a serialized tuple of data. """
|
||||
return {"value": self.__value,
|
||||
"string": str(self)}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""Convert a serialized tuple of data to an object."""
|
||||
self.__value, self.__string = data
|
||||
|
@ -144,6 +144,20 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
|
||||
self.type, self.place,
|
||||
self.famc, self.temple, self.status, self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"date": DateBase.to_struct(self),
|
||||
"type": self.type,
|
||||
"place": self.place,
|
||||
"famc": self.famc,
|
||||
"temple": self.temple,
|
||||
"status": self.status,
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -66,6 +66,12 @@ class LdsOrdBase(object):
|
||||
"""
|
||||
return [lds_ord.serialize() for lds_ord in self.lds_ord_list]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return [lds_ord.to_struct() for lds_ord in self.lds_ord_list]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object
|
||||
|
@ -64,6 +64,20 @@ class Location(SecondaryObject, LocationBase):
|
||||
"""
|
||||
return (LocationBase.serialize(self), self.parish)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"street": self.street,
|
||||
"locality": self.locality,
|
||||
"city": self.city,
|
||||
"country": self.county,
|
||||
"state": self.state,
|
||||
"country": self.country,
|
||||
"postal": self.postal,
|
||||
"phone": self.phone,
|
||||
"parish": self.parish}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -66,6 +66,19 @@ class LocationBase(object):
|
||||
return (self.street, self.locality, self.city, self.county, self.state,
|
||||
self.country, self.postal, self.phone)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"street": self.street,
|
||||
"locality": self.locality,
|
||||
"city": self.city,
|
||||
"country": self.county,
|
||||
"state": self.state,
|
||||
"country": self.country,
|
||||
"postal": self.postal,
|
||||
"phone": self.phone}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -58,6 +58,12 @@ class MediaBase(object):
|
||||
"""
|
||||
return [mref.serialize() for mref in self.media_list]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return [mref.to_struct() for mref in self.media_list]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -116,6 +116,37 @@ class MediaObject(CitationBase, NoteBase, DateBase, AttributeBase,
|
||||
TagBase.serialize(self),
|
||||
self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in the event to a Python tuple that
|
||||
represents all the data elements.
|
||||
|
||||
This method is used to convert the object into a form that can easily
|
||||
be saved to a database.
|
||||
|
||||
These elements may be primitive Python types (string, integers),
|
||||
complex Python types (lists or tuples, or Python objects. If the
|
||||
target database cannot handle complex types (such as objects or
|
||||
lists), the database is responsible for converting the data into
|
||||
a form that it can use.
|
||||
|
||||
:returns: Returns a python tuple containing the data that should
|
||||
be considered persistent.
|
||||
:rtype: tuple
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"path": self.path,
|
||||
"mime": self.mime,
|
||||
"desc": self.desc,
|
||||
"attribute_list": AttributeBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"change": self.change,
|
||||
"date": DateBase.to_struct(self),
|
||||
"tag_list": TagBase.to_struct(self),
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -70,6 +70,17 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
|
||||
RefBase.serialize(self),
|
||||
self.rect)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.serialize(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"attribute_list": AttributeBase.to_struct(self),
|
||||
"ref": RefBase.to_struct(self),
|
||||
"rect": self.rect}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -126,6 +126,26 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
|
||||
self.group_as, self.sort_as, self.display_as, self.call,
|
||||
self.nick, self.famnick)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"date": DateBase.to_struct(self),
|
||||
"first_name": self.first_name,
|
||||
"surname_list": SurnameBase.to_struct(self),
|
||||
"suffix": self.suffix,
|
||||
"title": self.title,
|
||||
"type": self.type.to_struct(),
|
||||
"group_as": self.group_as,
|
||||
"sort_as": self.sort_as,
|
||||
"display_as": self.display_as,
|
||||
"call": self.call,
|
||||
"nick": self.nick,
|
||||
"famnick": self.famnick}
|
||||
|
||||
def is_empty(self):
|
||||
"""
|
||||
Indicate if the name is empty.
|
||||
|
@ -97,6 +97,22 @@ class Note(BasicPrimaryObject, TagBase):
|
||||
self.type.serialize(), self.change, TagBase.serialize(self),
|
||||
self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""Convert the object to a serialized tuple of data.
|
||||
|
||||
:returns: The serialized format of the instance.
|
||||
:rtype: tuple
|
||||
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"text": self.text.to_struct(),
|
||||
"format": self.format,
|
||||
"type": self.type.to_struct(),
|
||||
"change": self.change,
|
||||
"tag_list": TagBase.to_struct(self),
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""Convert a serialized tuple of data to an object.
|
||||
|
||||
|
@ -53,6 +53,12 @@ class NoteBase(object):
|
||||
"""
|
||||
return self.note_list
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return self.note_list
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -78,6 +78,28 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
|
||||
MALE = 1
|
||||
FEMALE = 0
|
||||
|
||||
FIELDS = ["handle", # 0
|
||||
"gramps_id", # 1
|
||||
"gender", # 2
|
||||
"primary_name", # 3
|
||||
"alternate_names", # 4
|
||||
"death_ref_index", # 5
|
||||
"birth_ref_index", # 6
|
||||
"event_ref_list", # 7
|
||||
"family_list", # 8
|
||||
"parent_family_list", # 9
|
||||
"media_list", # 10
|
||||
"address_list", # 11
|
||||
"attribute_list", # 12
|
||||
"urls", # 13
|
||||
"lds_ord_list", # 14
|
||||
"citation_list", # 15
|
||||
"note_list", # 16
|
||||
"change", # 17
|
||||
"tag_list", # 18
|
||||
"private", # 19
|
||||
"person_ref_list"] # 20
|
||||
|
||||
def __init__(self, data=None):
|
||||
"""
|
||||
Create a new Person instance.
|
||||
@ -159,6 +181,65 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
|
||||
[pr.serialize() for pr in self.person_ref_list] # 20
|
||||
)
|
||||
|
||||
def to_struct(self):
|
||||
return {
|
||||
"handle": self.handle, # 0
|
||||
"gramps_id": self.gramps_id, # 1
|
||||
"gender": self.gender, # 2
|
||||
"primary_name": self.primary_name.to_struct(), # 3
|
||||
"alternate_names": [name.to_struct() for name in self.alternate_names], # 4
|
||||
"death_ref_index": self.death_ref_index, # 5
|
||||
"birth_ref_index": self.birth_ref_index, # 6
|
||||
"event_ref_list": [er.to_struct() for er in self.event_ref_list], # 7
|
||||
"family_list": self.family_list, # 8
|
||||
"parent_family_list": self.parent_family_list, # 9
|
||||
"media_list": MediaBase.to_struct(self), # 10
|
||||
"address_list": AddressBase.to_struct(self), # 11
|
||||
"attribute_list": AttributeBase.to_struct(self), # 12
|
||||
"urls": UrlBase.to_struct(self), # 13
|
||||
"lds_ord_list": LdsOrdBase.to_struct(self), # 14
|
||||
"citation_list": CitationBase.to_struct(self), # 15
|
||||
"note_list": NoteBase.to_struct(self), # 16
|
||||
"change": self.change, # 17
|
||||
"tag_list": TagBase.to_struct(self), # 18
|
||||
"private": self.private, # 19
|
||||
"person_ref_list": [pr.to_struct() for pr in self.person_ref_list] # 20
|
||||
}
|
||||
|
||||
def from_struct(self, to_struct):
|
||||
self.handle = to_struct["handle"] # 0
|
||||
self.gramps_id = to_struct["gramps_id"] # 1
|
||||
self.gender = to_struct["gender"] # 2
|
||||
self.primary_name = Name.from_struct(to_struct["primary_name"]) # 3
|
||||
self.alternate_names = [Name.from_struct(name)
|
||||
for name in to_struct["alternate_names"]] # 4
|
||||
self.death_ref_index = to_struct["death_ref_index"] # 5
|
||||
self.birth_ref_index = to_struct["birth_ref_index"] # 6
|
||||
self.event_ref_list = [EventRef.from_struct(er)
|
||||
for er in to_struct["event_ref_list"]] # 7
|
||||
self.family_list = to_struct["family_list"] # 8
|
||||
self.parent_family_list = to_struct["parent_family_list"] # 9
|
||||
self.media_list = [MediaBase.from_struct(m)
|
||||
for m in to_struct["media_list"]] # 10
|
||||
self.address_list = [AddressBase.from_struct(a)
|
||||
for a in to_struct["address_list"]] # 11
|
||||
self.attribute_list = [AttributeBase.from_struct(attr)
|
||||
for attr in to_struct["attribute_list"]] # 12
|
||||
self.urls = [UrlBase.from_struct(url)
|
||||
for url in to_struct["urls"]] # 13
|
||||
self.lds_ord_list = [LdsOrdBase.from_struct(lref)
|
||||
for lref in to_struct["lds_ord_list"]] # 14
|
||||
self.citation_list = [CitationBase.from_struct(cref)
|
||||
for cref in to_struct["citation_list"]] # 15
|
||||
self.note_list = [NoteBase.from_struct(noteref)
|
||||
for noteref in to_struct["note_list"]] # 16
|
||||
self.change = to_struct["change"] # 17
|
||||
self.tag_list = [TagBase.from_struct(tag)
|
||||
for tag in to_struct["tag_list"]] # 18
|
||||
self.private = to_struct["private"] # 19
|
||||
self.person_ref_list = [PersonRef.from_struct(pr)
|
||||
for pr in to_struct["person_ref_list"]] # 20
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
@ -979,3 +1060,4 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
|
||||
break
|
||||
else:
|
||||
self.person_ref_list.append(addendum)
|
||||
|
||||
|
@ -72,6 +72,16 @@ class PersonRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
|
||||
RefBase.serialize(self),
|
||||
self.rel)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"private": PrivacyBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"ref": RefBase.to_struct(self),
|
||||
"rel": self.rel}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -109,6 +109,44 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
|
||||
NoteBase.serialize(self),
|
||||
self.change, self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in the Place to a Python tuple that
|
||||
represents all the data elements.
|
||||
|
||||
This method is used to convert the object into a form that can easily
|
||||
be saved to a database.
|
||||
|
||||
These elements may be primitive Python types (string, integers),
|
||||
complex Python types (lists or tuples, or Python objects. If the
|
||||
target database cannot handle complex types (such as objects or
|
||||
lists), the database is responsible for converting the data into
|
||||
a form that it can use.
|
||||
|
||||
:returns: Returns a python tuple containing the data that should
|
||||
be considered persistent.
|
||||
:rtype: tuple
|
||||
"""
|
||||
|
||||
if self.main_loc is None or self.main_loc.serialize() == _EMPTY_LOC:
|
||||
main_loc = None
|
||||
else:
|
||||
main_loc = self.main_loc.to_struct()
|
||||
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"title": self.title,
|
||||
"long": self.long,
|
||||
"lat": self.lat,
|
||||
"main_loc": main_loc,
|
||||
"alt_loc": [al.to_struct() for al in self.alt_loc],
|
||||
"urls": UrlBase.to_struct(self),
|
||||
"media_list": MediaBase.to_struct(self),
|
||||
"citation_list": CitationBase.to_struct(self),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"change": self.change,
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -164,6 +164,14 @@ class BasicPrimaryObject(TableObject, PrivacyBase):
|
||||
def replace_media_references(self, old_handle, new_handle):
|
||||
pass
|
||||
|
||||
def get_fields(self):
|
||||
"""
|
||||
Return a list of fields of the struct.
|
||||
"""
|
||||
return self.to_struct().keys()
|
||||
|
||||
FIELDS = property(get_fields)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Primary Object class
|
||||
@ -264,3 +272,4 @@ class PrimaryObject(BasicPrimaryObject):
|
||||
Replace the handle reference with the new reference.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
@ -57,6 +57,12 @@ class PrivacyBase(object):
|
||||
"""
|
||||
return self.private
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return self.private
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -48,6 +48,12 @@ class RefBase(object):
|
||||
"""
|
||||
return self.ref
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return self.ref
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -67,6 +67,20 @@ class Repository(NoteBase, AddressBase, UrlBase, PrimaryObject):
|
||||
UrlBase.serialize(self),
|
||||
self.change, self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"type": self.type.to_struct(),
|
||||
"name": unicode(self.name),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"address_list": AddressBase.to_struct(self),
|
||||
"urls": UrlBase.to_struct(self),
|
||||
"change": self.change,
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -69,6 +69,18 @@ class RepoRef(SecondaryObject, PrivacyBase, NoteBase, RefBase):
|
||||
PrivacyBase.serialize(self),
|
||||
)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"ref": RefBase.to_struct(self),
|
||||
"call_number": self.call_number,
|
||||
"media_type": self.media_type.to_struct(),
|
||||
"private": PrivacyBase.serialize(self),
|
||||
}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -61,6 +61,15 @@ class Researcher(LocationBase):
|
||||
return (LocationBase.serialize(self),
|
||||
self.name, self.addr, self.email)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"location": LocationBase.to_struct(self),
|
||||
"name": self.name,
|
||||
"address": self.addr,
|
||||
"email": self.email}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -69,6 +69,23 @@ class Source(MediaBase, NoteBase, PrimaryObject):
|
||||
[rr.serialize() for rr in self.reporef_list],
|
||||
self.private)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"gramps_id": self.gramps_id,
|
||||
"title": unicode(self.title),
|
||||
"author": unicode(self.author),
|
||||
"pubinfo": unicode(self.pubinfo),
|
||||
"note_list": NoteBase.to_struct(self),
|
||||
"media_list": MediaBase.to_struct(self),
|
||||
"abbrev": unicode(self.abbrev),
|
||||
"change": self.change,
|
||||
"datamap": {"dict": self.datamap},
|
||||
"reporef_list": [rr.to_struct() for rr in self.reporef_list],
|
||||
"private": self.private}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert the data held in a tuple created by the serialize method
|
||||
|
@ -272,6 +272,21 @@ class StyledText(object):
|
||||
|
||||
return (self._string, the_tags)
|
||||
|
||||
def to_struct(self):
|
||||
"""Convert the object to a serialized tuple of data.
|
||||
|
||||
:returns: Serialized format of the instance.
|
||||
:returnstype: tuple
|
||||
|
||||
"""
|
||||
if self._tags:
|
||||
the_tags = [tag.to_struct() for tag in self._tags]
|
||||
else:
|
||||
the_tags = []
|
||||
|
||||
return {"string": self._string,
|
||||
"tags": the_tags}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""Convert a serialized tuple of data to an object.
|
||||
|
||||
@ -298,6 +313,14 @@ class StyledText(object):
|
||||
"""
|
||||
return self._tags
|
||||
|
||||
def get_string(self):
|
||||
"""
|
||||
Accessor for the associated string.
|
||||
"""
|
||||
return self._string
|
||||
|
||||
tags = property(get_tags)
|
||||
string = property(get_string)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from styledtexttagtype import StyledTextTagType
|
||||
|
@ -73,6 +73,17 @@ class StyledTextTag(object):
|
||||
"""
|
||||
return (self.name.serialize(), self.value, self.ranges)
|
||||
|
||||
def to_struct(self):
|
||||
"""Convert the object to a serialized tuple of data.
|
||||
|
||||
:returns: Serialized format of the instance.
|
||||
:returnstype: tuple
|
||||
|
||||
"""
|
||||
return {"name": self.name.to_struct(),
|
||||
"value": self.value,
|
||||
"ranges": self.ranges}
|
||||
|
||||
def unserialize(self, data):
|
||||
"""Convert a serialized tuple of data to an object.
|
||||
|
||||
|
@ -71,6 +71,16 @@ class Surname(SecondaryObject):
|
||||
return (self.surname, self.prefix, self.primary,
|
||||
self.origintype.serialize(), self.connector)
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return {"surname": self.surname,
|
||||
"prefix": self.prefix,
|
||||
"primary": self.primary,
|
||||
"origintype": self.origintype.to_struct(),
|
||||
"connector": self.connector}
|
||||
|
||||
def is_empty(self):
|
||||
"""
|
||||
Indicate if the surname is empty.
|
||||
|
@ -62,6 +62,12 @@ class SurnameBase(object):
|
||||
"""
|
||||
return [surname.serialize() for surname in self.surname_list]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized struct of data.
|
||||
"""
|
||||
return [surname.to_struct() for surname in self.surname_list]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -198,6 +198,32 @@ class Tag(TableObject):
|
||||
:rtype: int
|
||||
"""
|
||||
return self.__priority
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the data held in the event to a Python tuple that
|
||||
represents all the data elements.
|
||||
|
||||
This method is used to convert the object into a form that can easily
|
||||
be saved to a database.
|
||||
|
||||
These elements may be primitive Python types (string, integers),
|
||||
complex Python types (lists or tuples, or Python objects. If the
|
||||
target database cannot handle complex types (such as objects or
|
||||
lists), the database is responsible for converting the data into
|
||||
a form that it can use.
|
||||
|
||||
:returns: Returns a python tuple containing the data that should
|
||||
be considered persistent.
|
||||
:rtype: tuple
|
||||
"""
|
||||
return {"handle": self.handle,
|
||||
"name": self.__name,
|
||||
"color": self.__color,
|
||||
"priority": self.__priority,
|
||||
"change": self.change}
|
||||
|
||||
FIELDS = ["handle", "name", "color", "priority", "change"]
|
||||
|
||||
priority = property(get_priority, set_priority, None,
|
||||
'Returns or sets priority of the tag')
|
||||
|
||||
|
@ -54,6 +54,12 @@ class TagBase(object):
|
||||
"""
|
||||
return self.tag_list
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data.
|
||||
"""
|
||||
return self.tag_list
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
@ -69,6 +69,12 @@ class Url(SecondaryObject, PrivacyBase):
|
||||
def serialize(self):
|
||||
return (self.private, self.path, self.desc, self.type.serialize())
|
||||
|
||||
def to_struct(self):
|
||||
return {"private": self.private,
|
||||
"path": self.path,
|
||||
"desc": self.desc,
|
||||
"type": self.type.to_struct()}
|
||||
|
||||
def unserialize(self, data):
|
||||
(self.private, self.path, self.desc, type_value) = data
|
||||
self.type.unserialize(type_value)
|
||||
|
@ -60,6 +60,12 @@ class UrlBase(object):
|
||||
"""
|
||||
return [url.serialize() for url in self.urls]
|
||||
|
||||
def to_struct(self):
|
||||
"""
|
||||
Convert the object to a serialized tuple of data
|
||||
"""
|
||||
return [url.to_struct() for url in self.urls]
|
||||
|
||||
def unserialize(self, data):
|
||||
"""
|
||||
Convert a serialized tuple of data to an object.
|
||||
|
Loading…
x
Reference in New Issue
Block a user