Add labels to gen.lib object fields

This commit is contained in:
Doug Blank 2015-12-24 23:16:57 -05:00
parent 0ff9363d72
commit b793b9d068
4 changed files with 120 additions and 0 deletions

View File

@ -37,7 +37,9 @@ from .notebase import NoteBase
from .datebase import DateBase from .datebase import DateBase
from .surnamebase import SurnameBase from .surnamebase import SurnameBase
from .nametype import NameType from .nametype import NameType
from .handle import Handle
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
from .date import Date
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@ -188,6 +190,47 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
struct.get("nick", default.nick), struct.get("nick", default.nick),
struct.get("famnick", default.famnick)) struct.get("famnick", default.famnick))
@classmethod
def get_labels(cls):
return {
"_class": _("Name"),
"private": _("Private"),
"citation_list": _("Citations"),
"note_list": _("Notes"),
"date": _("Date"),
"first_name": _("Given name"),
"surname_list": _("Surnames"),
"suffix": _("Suffix"),
"title": _("Title"),
"type": _("Type"),
"group_as": _("Group as"),
"sort_as": _("Sort as"),
"display_as": _("Display as"),
"call": _("Call name"),
"nick": _("Nick name"),
"famnick": _("Family nick name"),
}
@classmethod
def get_schema(cls):
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")],
"suffix": str,
"title": str,
"type": NameType,
"group_as": str,
"sort_as": str,
"display_as": str,
"call": str,
"nick": str,
"famnick": str,
}
def is_empty(self): def is_empty(self):
""" """
Indicate if the name is empty. Indicate if the name is empty.

View File

@ -207,6 +207,34 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
for pr in self.person_ref_list] # 20 for pr in self.person_ref_list] # 20
} }
@classmethod
def get_labels(cls):
return {
"_class": _("Person"),
"handle": _("Handle"),
"gramps_id": _("Gramps ID"),
"gender": _("Gender"),
"primary_name": _("Primary name"),
"alternate_names": _("Alternate names"),
"death_ref_index": _("Death reference index"),
"birth_ref_index": _("Birth reference index"),
"event_ref_list": _("Event references"),
"family_list": _("Families"),
"parent_family_list": _("Parent families"),
"media_list": _("Media"),
"address_list": _("Addresses"),
"attribute_list": _("Attributes"),
"urls": _("Urls"),
"lds_ord_list": _("LDS ordinances"),
"citation_list": _("Citations"),
"note_list": _("Notes"),
"change": _("Last changed"),
"tag_list": _("Tags"),
"private": _("Private"),
"person_ref_list": _("Person references"),
"probably_alive": _("Probably alive"),
}
@classmethod @classmethod
def from_struct(cls, struct): def from_struct(cls, struct):
""" """
@ -241,6 +269,10 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
from .mediaref import MediaRef
from .address import Address
from .url import Url
from .ldsord import LdsOrd
return { return {
"handle": Handle("Person", "PERSON-HANDLE"), "handle": Handle("Person", "PERSON-HANDLE"),
"gramps_id": str, "gramps_id": str,

View File

@ -71,6 +71,37 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
else: else:
self.gramps_id = None self.gramps_id = None
def get_label(self, field):
"""
Get the associated label given a field name of this object.
"""
chain = field.split(".")
path = self
for part in chain[:-1]:
if hasattr(path, part):
path = getattr(path, part)
else:
path = path[int(part)]
labels = path.get_labels()
if chain[-1] in labels:
return labels[chain[-1]]
else:
raise Exception("%s has no such label: '%s'" % (self, field))
def get_field(self, field):
"""
Get the value of a field.
"""
chain = field.split(".")
path = self
for part in chain:
class_ = None
if hasattr(path, part):
path = getattr(path, part)
else:
path = path[int(part)]
return path
def set_gramps_id(self, gramps_id): def set_gramps_id(self, gramps_id):
""" """
Set the Gramps ID for the primary object. Set the Gramps ID for the primary object.

View File

@ -28,6 +28,9 @@ Surname class for Gramps.
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from .secondaryobj import SecondaryObject from .secondaryobj import SecondaryObject
from .nameorigintype import NameOriginType from .nameorigintype import NameOriginType
from .const import IDENTICAL, EQUAL, DIFFERENT from .const import IDENTICAL, EQUAL, DIFFERENT
@ -98,6 +101,17 @@ class Surname(SecondaryObject):
"origintype": self.origintype.to_struct(), "origintype": self.origintype.to_struct(),
"connector": self.connector} "connector": self.connector}
@classmethod
def get_labels(cls):
return {
"_class": _("Surname"),
"surname": _("Surname"),
"prefix": _("Prefix"),
"primary": _("Primary"),
"origintype": _("Origin type"),
"connector": _("Connector")
}
@classmethod @classmethod
def from_struct(cls, struct): def from_struct(cls, struct):
""" """