From 2a4ba037c6ff4d52bca24db60d7685aa7826fd2c Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 28 Dec 2013 10:11:43 -0500 Subject: [PATCH] Fixed RefBase.to_struct in gen.lib objects --- gramps/gen/lib/childref.py | 3 ++- gramps/gen/lib/eventref.py | 3 ++- gramps/gen/lib/mediaref.py | 3 ++- gramps/gen/lib/person.py | 26 ++++++++++++++++++++++++++ gramps/gen/lib/personref.py | 3 ++- gramps/gen/lib/placeref.py | 3 ++- gramps/gen/lib/refbase.py | 25 ------------------------- gramps/gen/lib/reporef.py | 3 ++- 8 files changed, 38 insertions(+), 31 deletions(-) diff --git a/gramps/gen/lib/childref.py b/gramps/gen/lib/childref.py index 8acf7b2e5..48e887ada 100644 --- a/gramps/gen/lib/childref.py +++ b/gramps/gen/lib/childref.py @@ -38,6 +38,7 @@ from .notebase import NoteBase from .refbase import RefBase from .childreftype import ChildRefType 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), "citation_list": CitationBase.to_struct(self), "note_list": NoteBase.to_struct(self), - "ref": RefBase.to_struct(self), + "ref": Handle("Person", self.ref), "frel": self.frel.to_struct(), "mrel": self.mrel.to_struct()} diff --git a/gramps/gen/lib/eventref.py b/gramps/gen/lib/eventref.py index adad274ec..9b8095670 100644 --- a/gramps/gen/lib/eventref.py +++ b/gramps/gen/lib/eventref.py @@ -40,6 +40,7 @@ from .refbase import RefBase from .eventroletype import EventRoleType from .const import IDENTICAL, EQUAL, DIFFERENT from .citationbase import IndirectCitationBase +from .handle import Handle #------------------------------------------------------------------------- # @@ -105,7 +106,7 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase, "private": PrivacyBase.to_struct(self), "note_list": NoteBase.to_struct(self), "attribute_list": AttributeBase.to_struct(self), - "ref": RefBase.to_struct(self), + "ref": Handle("Event", self.ref), "role": self.__role.to_struct() } diff --git a/gramps/gen/lib/mediaref.py b/gramps/gen/lib/mediaref.py index 1c58c5776..be49c77ab 100644 --- a/gramps/gen/lib/mediaref.py +++ b/gramps/gen/lib/mediaref.py @@ -39,6 +39,7 @@ from .notebase import NoteBase from .refbase import RefBase from .attrbase import AttributeBase 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), "note_list": NoteBase.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} @classmethod diff --git a/gramps/gen/lib/person.py b/gramps/gen/lib/person.py index 22e11892d..344f44d1e 100644 --- a/gramps/gen/lib/person.py +++ b/gramps/gen/lib/person.py @@ -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)] ) + @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): """ Convert the data held in a tuple created by the serialize method diff --git a/gramps/gen/lib/personref.py b/gramps/gen/lib/personref.py index f73d907f6..507e02a02 100644 --- a/gramps/gen/lib/personref.py +++ b/gramps/gen/lib/personref.py @@ -38,6 +38,7 @@ from .citationbase import CitationBase from .notebase import NoteBase from .refbase import RefBase 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), "citation_list": CitationBase.to_struct(self), "note_list": NoteBase.to_struct(self), - "ref": RefBase.to_struct(self), + "ref": Handle("Person", self.ref), "rel": self.rel} @classmethod diff --git a/gramps/gen/lib/placeref.py b/gramps/gen/lib/placeref.py index 229a61893..ff8bd1cdc 100644 --- a/gramps/gen/lib/placeref.py +++ b/gramps/gen/lib/placeref.py @@ -34,6 +34,7 @@ from .secondaryobj import SecondaryObject from .refbase import RefBase from .datebase import DateBase from .const import IDENTICAL, EQUAL, DIFFERENT +from .handle import Handle #------------------------------------------------------------------------- # @@ -86,7 +87,7 @@ class PlaceRef(RefBase, DateBase, SecondaryObject): """ return { "_class": "PlaceRef", - "ref": RefBase.to_struct(self), + "ref": Handle("Place", self.ref), "date": DateBase.to_struct(self) } diff --git a/gramps/gen/lib/refbase.py b/gramps/gen/lib/refbase.py index f6fcf8cbd..d50aab088 100644 --- a/gramps/gen/lib/refbase.py +++ b/gramps/gen/lib/refbase.py @@ -24,8 +24,6 @@ Base Reference class for Gramps. """ -from .handle import Handle - #------------------------------------------------------------------------- # # RefBase class @@ -50,29 +48,6 @@ class RefBase(object): """ 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 def from_struct(cls, struct): """ diff --git a/gramps/gen/lib/reporef.py b/gramps/gen/lib/reporef.py index 2b600d71c..3a3c971a3 100644 --- a/gramps/gen/lib/reporef.py +++ b/gramps/gen/lib/reporef.py @@ -37,6 +37,7 @@ from .notebase import NoteBase from .refbase import RefBase from .srcmediatype import SourceMediaType from .const import IDENTICAL, EQUAL, DIFFERENT +from .handle import Handle #------------------------------------------------------------------------- # @@ -93,7 +94,7 @@ class RepoRef(SecondaryObject, PrivacyBase, NoteBase, RefBase): return { "_class": "RepositoryRef", "note_list": NoteBase.to_struct(self), - "ref": RefBase.to_struct(self), + "ref": Handle("Repository", self.ref), "call_number": self.call_number, "media_type": self.media_type.to_struct(), "private": PrivacyBase.serialize(self),