diff --git a/gramps/gen/lib/name.py b/gramps/gen/lib/name.py index 8410d62de..3d44d7e85 100644 --- a/gramps/gen/lib/name.py +++ b/gramps/gen/lib/name.py @@ -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, diff --git a/gramps/gen/lib/primaryobj.py b/gramps/gen/lib/primaryobj.py index cb45d8b53..082d85555 100644 --- a/gramps/gen/lib/primaryobj.py +++ b/gramps/gen/lib/primaryobj.py @@ -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): """