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 @classmethod
def get_schema(cls): def get_schema(cls):
from .surname import Surname
return { return {
"private": bool, "private": bool,
"citation_list": [Handle("Citation", "CITATION-HANDLE")], "citation_list": [Handle("Citation", "CITATION-HANDLE")],
"note_list": [Handle("Note", "NOTE-HANDLE")], "note_list": [Handle("Note", "NOTE-HANDLE")],
"date": Date, "date": Date,
"first_name": str, "first_name": str,
"surname_list": [Handle("Surname", "SURNAME-HANDLE")], "surname_list": [Surname],
"suffix": str, "suffix": str,
"title": str, "title": str,
"type": NameType, "type": NameType,

View File

@ -71,22 +71,27 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
else: else:
self.gramps_id = None 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. Get the associated label given a field name of this object.
No index positions allowed on lists.
""" """
chain = field.split(".") chain = field.split(".")
path = self path = cls
for part in chain[:-1]: for part in chain[:-1]:
if hasattr(path, part): schema = path.get_schema()
path = getattr(path, part) if part in schema.keys():
path = schema[part]
else: 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(_) labels = path.get_labels(_)
if chain[-1] in labels: if chain[-1] in labels:
return labels[chain[-1]] return labels[chain[-1]]
else: 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): def get_field(self, field):
""" """