Object.get_label() now a class method. Fixed error in Name schema

This commit is contained in:
Doug Blank 2015-12-31 08:47:48 -05:00
parent b77aeb39e7
commit cc6b54c5d9
2 changed files with 13 additions and 7 deletions

View File

@ -213,13 +213,14 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
@classmethod
def get_schema(cls):
from .surname import Surname
return {
"private": bool,
"citation_list": [Handle("Citation", "CITATION-HANDLE")],
"note_list": [Handle("Note", "NOTE-HANDLE")],
"date": Date,
"first_name": str,
"surname_list": [Handle("Surname", "SURNAME-HANDLE")],
"surname_list": [Surname],
"suffix": str,
"title": str,
"type": NameType,

View File

@ -71,22 +71,27 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
else:
self.gramps_id = None
def get_label(self, field, _):
@classmethod
def get_label(cls, field, _):
"""
Get the associated label given a field name of this object.
No index positions allowed on lists.
"""
chain = field.split(".")
path = self
path = cls
for part in chain[:-1]:
if hasattr(path, part):
path = getattr(path, part)
schema = path.get_schema()
if part in schema.keys():
path = schema[part]
else:
path = path[int(part)]
raise Exception("No such %s in %s" % (part, schema))
if isinstance(path, (list, tuple)):
path = path[0]
labels = path.get_labels(_)
if chain[-1] in labels:
return labels[chain[-1]]
else:
raise Exception("%s has no such label: '%s'" % (self, field))
raise Exception("%s has no such label on %s: '%s'" % (cls, path, field))
def get_field(self, field):
"""