Added missing get_schema() to some objects

This commit is contained in:
Doug Blank 2016-01-11 21:46:10 -05:00
parent 2195c2e885
commit 0c90679515
6 changed files with 119 additions and 3 deletions

View File

@ -110,3 +110,10 @@ def __index_surname(surn_list):
else: else:
surn = "" surn = ""
return 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)

View File

@ -153,6 +153,33 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
"tag_list": TagBase.to_struct(self), "tag_list": TagBase.to_struct(self),
"private": self.private} "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 @classmethod
def get_labels(cls, _): def get_labels(cls, _):
return { return {

View File

@ -153,6 +153,61 @@ class MediaObject(CitationBase, NoteBase, DateBase, AttributeBase,
"tag_list": TagBase.to_struct(self), "tag_list": TagBase.to_struct(self),
"private": self.private} "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 @classmethod
def from_struct(cls, struct): def from_struct(cls, struct):
""" """

View File

@ -98,6 +98,26 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
"ref": Handle("Media", self.ref), "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
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 @classmethod
def from_struct(cls, struct): def from_struct(cls, struct):
""" """

View File

@ -222,7 +222,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
@classmethod @classmethod
def get_labels(cls, _): def get_labels(cls, _):
return { return {
"_class": _("Person"),
"handle": _("Handle"), "handle": _("Handle"),
"gramps_id": _("Gramps ID"), "gramps_id": _("Gramps ID"),
"gender": _("Gender"), "gender": _("Gender"),
@ -292,6 +291,9 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
"""
Return the schema as a dictionary for this class.
"""
from .mediaref import MediaRef from .mediaref import MediaRef
from .address import Address from .address import Address
from .url import Url from .url import Url

View File

@ -217,8 +217,13 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
if hasattr(current, part): # attribute if hasattr(current, part): # attribute
current = getattr(current, part) current = getattr(current, part)
elif part.isdigit(): # index into list elif part.isdigit(): # index into list
if int(part) < len(current):
current = current[int(part)] current = current[int(part)]
continue continue
elif ignore_errors:
return
else:
raise Exception("Can't get position %s of %s" % (part, current))
elif isinstance(current, (list, tuple)): elif isinstance(current, (list, tuple)):
current = [getattr(attr, part) for attr in current] current = [getattr(attr, part) for attr in current]
else: # part not found on this self else: # part not found on this self