From 0c90679515cfba0f0c92cf13d413d668f989e43a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Mon, 11 Jan 2016 21:46:10 -0500 Subject: [PATCH] Added missing get_schema() to some objects --- gramps/gen/db/__init__.py | 7 +++++ gramps/gen/lib/event.py | 27 ++++++++++++++++++ gramps/gen/lib/mediaobj.py | 55 ++++++++++++++++++++++++++++++++++++ gramps/gen/lib/mediaref.py | 20 +++++++++++++ gramps/gen/lib/person.py | 4 ++- gramps/gen/lib/primaryobj.py | 9 ++++-- 6 files changed, 119 insertions(+), 3 deletions(-) diff --git a/gramps/gen/db/__init__.py b/gramps/gen/db/__init__.py index d9fcf1ad1..7806c7926 100644 --- a/gramps/gen/db/__init__.py +++ b/gramps/gen/db/__init__.py @@ -110,3 +110,10 @@ def __index_surname(surn_list): else: surn = "" return surn + +def open_database(database, force_unlock=False): + """ + Shortcut for external uses of databases. + """ + from ..dbstate import DbState + return DbState().open_database(database, force_unlock) diff --git a/gramps/gen/lib/event.py b/gramps/gen/lib/event.py index 0cc0a8385..b3ab66eeb 100644 --- a/gramps/gen/lib/event.py +++ b/gramps/gen/lib/event.py @@ -153,6 +153,33 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase, "tag_list": TagBase.to_struct(self), "private": self.private} + @classmethod + def get_schema(cls): + """ + Return the schema as a dictionary for this class. + """ + from .attribute import Attribute + from .citation import Citation + from .note import Note + from .date import Date + from .tag import Tag + from .mediaobj import MediaObject + return { + "handle": Handle("Event", "EVENT-HANDLE"), + "gramps_id": str, + "type": EventType, + "date": Date, + "description": str, + "place": Handle("Place", "PLACE-HANDLE"), + "citation_list": [Citation], + "note_list": [Note], + "media_list": [MediaObject], + "attribute_list": [Attribute], + "change": float, + "tag_list": [Tag], + "private": bool, + } + @classmethod def get_labels(cls, _): return { diff --git a/gramps/gen/lib/mediaobj.py b/gramps/gen/lib/mediaobj.py index 643f20d41..165afbac0 100644 --- a/gramps/gen/lib/mediaobj.py +++ b/gramps/gen/lib/mediaobj.py @@ -153,6 +153,61 @@ class MediaObject(CitationBase, NoteBase, DateBase, AttributeBase, "tag_list": TagBase.to_struct(self), "private": self.private} + @classmethod + def get_schema(cls): + """ + Returns the schema for EventRef. + + :returns: Returns a dict containing the fields to types. + :rtype: dict + """ + from .attribute import Attribute + from .citation import Citation + from .note import Note + from .date import Date + from .tag import Tag + return { + "handle": Handle("Media", "MEDIA-HANDLE"), + "gramps_id": str, + "path": str, + "mime": str, + "desc": str, + "checksum": str, + "attribute_list": [Attribute], + "citation_list": [Citation], + "note_list": [Note], + "change": float, + "date": Date, + "tag_list": Tag, + "private": bool, + } + + @classmethod + def get_labels(cls, _): + """ + Given a translation function, returns the labels for + each field of this object. + + :returns: Returns a dict containing the fields to labels. + :rtype: dict + """ + return { + "_class": _("Media"), + "handle": _("Media"), + "gramps_id": _("Gramps ID"), + "path": _("Path"), + "mime": _("MIME"), + "desc": _("Description"), + "checksum": _("Checksum"), + "attribute_list": _("Attributes"), + "citation_list": _("Citations"), + "note_list": _("Notes"), + "change": _("Last changed"), + "date": _("Date"), + "tag_list": _("Tags"), + "private": _("Private"), + } + @classmethod def from_struct(cls, struct): """ diff --git a/gramps/gen/lib/mediaref.py b/gramps/gen/lib/mediaref.py index fc44f92e5..201df3818 100644 --- a/gramps/gen/lib/mediaref.py +++ b/gramps/gen/lib/mediaref.py @@ -98,6 +98,26 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase, "ref": Handle("Media", self.ref), "rect": self.rect if self.rect != (0, 0, 0, 0) else None} + @classmethod + def get_schema(cls): + """ + Returns the schema for MediaRef. + + :returns: Returns a dict containing the fields to types. + :rtype: dict + """ + from .attribute import Attribute + from .citation import Citation + from .note import Note + return { + "private": bool, + "citation_list": [Citation], + "note_list": [Note], + "attribute_list": [Attribute], + "ref": Handle("Media", "MEDIA-HANDLE"), + "rect": tuple, # or None if (0,0,0,0) + } + @classmethod def from_struct(cls, struct): """ diff --git a/gramps/gen/lib/person.py b/gramps/gen/lib/person.py index c6c871ae3..ac11e33e4 100644 --- a/gramps/gen/lib/person.py +++ b/gramps/gen/lib/person.py @@ -222,7 +222,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase, @classmethod def get_labels(cls, _): return { - "_class": _("Person"), "handle": _("Handle"), "gramps_id": _("Gramps ID"), "gender": _("Gender"), @@ -292,6 +291,9 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase, @classmethod def get_schema(cls): + """ + Return the schema as a dictionary for this class. + """ from .mediaref import MediaRef from .address import Address from .url import Url diff --git a/gramps/gen/lib/primaryobj.py b/gramps/gen/lib/primaryobj.py index 20c03e182..9c4f5f16c 100644 --- a/gramps/gen/lib/primaryobj.py +++ b/gramps/gen/lib/primaryobj.py @@ -217,8 +217,13 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): if hasattr(current, part): # attribute current = getattr(current, part) elif part.isdigit(): # index into list - current = current[int(part)] - continue + if int(part) < len(current): + current = current[int(part)] + continue + elif ignore_errors: + return + else: + raise Exception("Can't get position %s of %s" % (part, current)) elif isinstance(current, (list, tuple)): current = [getattr(attr, part) for attr in current] else: # part not found on this self