Fixed RefBase.to_struct in gen.lib objects

This commit is contained in:
Doug Blank 2013-12-28 10:11:43 -05:00
parent c07aebd7d0
commit 2a4ba037c6
8 changed files with 38 additions and 31 deletions

View File

@ -38,6 +38,7 @@ from .notebase import NoteBase
from .refbase import RefBase from .refbase import RefBase
from .childreftype import ChildRefType from .childreftype import ChildRefType
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -100,7 +101,7 @@ class ChildRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
"private": PrivacyBase.to_struct(self), "private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self), "citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self), "note_list": NoteBase.to_struct(self),
"ref": RefBase.to_struct(self), "ref": Handle("Person", self.ref),
"frel": self.frel.to_struct(), "frel": self.frel.to_struct(),
"mrel": self.mrel.to_struct()} "mrel": self.mrel.to_struct()}

View File

@ -40,6 +40,7 @@ from .refbase import RefBase
from .eventroletype import EventRoleType from .eventroletype import EventRoleType
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .citationbase import IndirectCitationBase from .citationbase import IndirectCitationBase
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -105,7 +106,7 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
"private": PrivacyBase.to_struct(self), "private": PrivacyBase.to_struct(self),
"note_list": NoteBase.to_struct(self), "note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self), "attribute_list": AttributeBase.to_struct(self),
"ref": RefBase.to_struct(self), "ref": Handle("Event", self.ref),
"role": self.__role.to_struct() "role": self.__role.to_struct()
} }

View File

@ -39,6 +39,7 @@ from .notebase import NoteBase
from .refbase import RefBase from .refbase import RefBase
from .attrbase import AttributeBase from .attrbase import AttributeBase
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -96,7 +97,7 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
"citation_list": CitationBase.to_struct(self), "citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self), "note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self), "attribute_list": AttributeBase.to_struct(self),
"ref": RefBase.to_struct(self), "ref": Handle("Media", self.ref),
"rect": self.rect if self.rect != (0,0,0,0) else None} "rect": self.rect if self.rect != (0,0,0,0) else None}
@classmethod @classmethod

View File

@ -243,6 +243,32 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
[PersonRef.from_struct(p) for p in struct.get("person_ref_list", default.person_ref_list)] [PersonRef.from_struct(p) for p in struct.get("person_ref_list", default.person_ref_list)]
) )
@classmethod
def get_schema(cls):
return {
"handle": Handle("Person", "PERSON-HANDLE"),
"gramps_id": str,
"gender": int,
"primary_name": Name,
"alternate_names": [Name],
"death_ref_index": int,
"birth_ref_index": int,
"event_ref_list": [EventRef],
"family_list": [Handle("Family", "FAMILY-HANDLE")],
"parent_family_list": [Handle("Family", "FAMILY-HANDLE")],
"media_list": [MediaRef],
"address_list": [Address],
"attribute_list": [Attribute],
"urls": [Url],
"lds_ord_list": [LdsOrd],
"citation_list": [Handle("Citation", "CITATION-HANDLE")],
"note_list": [Handle("Note", "NOTE-HANDLE")],
"change": int,
"tag_list": [Handle("Tag", "TAG-HANDLE")],
"private": bool,
"person_ref_list": [PersonRef]
}
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -38,6 +38,7 @@ from .citationbase import CitationBase
from .notebase import NoteBase from .notebase import NoteBase
from .refbase import RefBase from .refbase import RefBase
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -97,7 +98,7 @@ class PersonRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
"private": PrivacyBase.to_struct(self), "private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self), "citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self), "note_list": NoteBase.to_struct(self),
"ref": RefBase.to_struct(self), "ref": Handle("Person", self.ref),
"rel": self.rel} "rel": self.rel}
@classmethod @classmethod

View File

@ -34,6 +34,7 @@ from .secondaryobj import SecondaryObject
from .refbase import RefBase from .refbase import RefBase
from .datebase import DateBase from .datebase import DateBase
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -86,7 +87,7 @@ class PlaceRef(RefBase, DateBase, SecondaryObject):
""" """
return { return {
"_class": "PlaceRef", "_class": "PlaceRef",
"ref": RefBase.to_struct(self), "ref": Handle("Place", self.ref),
"date": DateBase.to_struct(self) "date": DateBase.to_struct(self)
} }

View File

@ -24,8 +24,6 @@
Base Reference class for Gramps. Base Reference class for Gramps.
""" """
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# RefBase class # RefBase class
@ -50,29 +48,6 @@ class RefBase(object):
""" """
return self.ref return self.ref
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: str
"""
## Return name of referenced item (remove "Ref" from name)
return Handle(self.__class__.__name__[:-3], self.ref)
@classmethod @classmethod
def from_struct(cls, struct): def from_struct(cls, struct):
""" """

View File

@ -37,6 +37,7 @@ from .notebase import NoteBase
from .refbase import RefBase from .refbase import RefBase
from .srcmediatype import SourceMediaType from .srcmediatype import SourceMediaType
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .handle import Handle
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -93,7 +94,7 @@ class RepoRef(SecondaryObject, PrivacyBase, NoteBase, RefBase):
return { return {
"_class": "RepositoryRef", "_class": "RepositoryRef",
"note_list": NoteBase.to_struct(self), "note_list": NoteBase.to_struct(self),
"ref": RefBase.to_struct(self), "ref": Handle("Repository", self.ref),
"call_number": self.call_number, "call_number": self.call_number,
"media_type": self.media_type.to_struct(), "media_type": self.media_type.to_struct(),
"private": PrivacyBase.serialize(self), "private": PrivacyBase.serialize(self),