diff --git a/gramps/gen/lib/date.py b/gramps/gen/lib/date.py index 5fc848ed2..4fd21ae71 100644 --- a/gramps/gen/lib/date.py +++ b/gramps/gen/lib/date.py @@ -681,7 +681,7 @@ class Date(object): "newyear": self.newyear} @classmethod - def from_struct(cls, struct): + def from_struct(cls, struct, full=False): """ Given a struct data representation, return a serialized object. @@ -695,7 +695,7 @@ class Date(object): struct.get("text", default.text), struct.get("sortval", default.sortval), struct.get("newyear", default.newyear)) - if retval == (0, 0, 0, (0, 0, 0, False), '', 0, 0): + if not full and retval == (0, 0, 0, (0, 0, 0, False), '', 0, 0): return None else: return retval diff --git a/gramps/gen/lib/event.py b/gramps/gen/lib/event.py index 99e66c829..903794a10 100644 --- a/gramps/gen/lib/event.py +++ b/gramps/gen/lib/event.py @@ -152,6 +152,25 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase, "tag_list": TagBase.to_struct(self), "private": self.private} + @classmethod + def get_labels(cls, _): + return { + "_class": _("Event"), + "handle": _("Handle"), + "gramps_id": _("Gramps ID"), + "type": _("Type"), + "date": _("Date"), + "description": _("Description"), + "place": _("Place"), + "citation_list": _("Citations"), + "note_list": _("Notes"), + "media_list": _("Media"), + "attribute_list": _("Attributes"), + "change": _("Last changed"), + "tag_list": _("Tags"), + "private": _("Private"), + } + @classmethod def from_struct(cls, struct): """ diff --git a/gramps/gen/lib/eventref.py b/gramps/gen/lib/eventref.py index 00cf9ff18..9330e9db5 100644 --- a/gramps/gen/lib/eventref.py +++ b/gramps/gen/lib/eventref.py @@ -108,6 +108,16 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase, "role": self.__role.to_struct() } + @classmethod + def get_labels(cls, _): + return { + "private": _("Private"), + "note_list": _("Notes"), + "attribute_list": _("Attributes"), + "ref": _("Event"), + "role": _("Role"), + } + @classmethod def from_struct(cls, struct): """ diff --git a/gramps/gen/lib/name.py b/gramps/gen/lib/name.py index ebfc74d03..8410d62de 100644 --- a/gramps/gen/lib/name.py +++ b/gramps/gen/lib/name.py @@ -191,7 +191,7 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase, struct.get("famnick", default.famnick)) @classmethod - def get_labels(cls): + def get_labels(cls, _): return { "_class": _("Name"), "private": _("Private"), diff --git a/gramps/gen/lib/person.py b/gramps/gen/lib/person.py index 18950c0b9..6aebb082a 100644 --- a/gramps/gen/lib/person.py +++ b/gramps/gen/lib/person.py @@ -208,7 +208,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase, } @classmethod - def get_labels(cls): + def get_labels(cls, _): return { "_class": _("Person"), "handle": _("Handle"), diff --git a/gramps/gen/lib/primaryobj.py b/gramps/gen/lib/primaryobj.py index 24b1cee1c..5271a3236 100644 --- a/gramps/gen/lib/primaryobj.py +++ b/gramps/gen/lib/primaryobj.py @@ -71,7 +71,7 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): else: self.gramps_id = None - def get_label(self, field): + def get_label(self, field, _): """ Get the associated label given a field name of this object. """ @@ -82,7 +82,7 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): path = getattr(path, part) else: path = path[int(part)] - labels = path.get_labels() + labels = path.get_labels(_) if chain[-1] in labels: return labels[chain[-1]] else: diff --git a/gramps/gen/lib/secondaryobj.py b/gramps/gen/lib/secondaryobj.py index ab0581275..a3703f8ec 100644 --- a/gramps/gen/lib/secondaryobj.py +++ b/gramps/gen/lib/secondaryobj.py @@ -50,3 +50,21 @@ class SecondaryObject(BaseObject): Should be overwritten by objects that inherit from this class. """ pass + + 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)) + diff --git a/gramps/gen/lib/struct.py b/gramps/gen/lib/struct.py index 53bc15eb9..e226b8e56 100644 --- a/gramps/gen/lib/struct.py +++ b/gramps/gen/lib/struct.py @@ -308,12 +308,13 @@ class Struct(object): add_func = self.db._tables[name]["add_func"] add_func(new_obj, trans) - def from_struct(struct): + def from_struct(self): """ Given a struct with metadata, create a Gramps object. """ from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, - Repository, MediaObject, Note, Tag) + Repository, MediaObject, Note, Tag, Date) + struct = self.struct if isinstance(struct, dict): if "_class" in struct.keys(): if struct["_class"] == "Person": @@ -336,6 +337,8 @@ class Struct(object): return Note.create(Note.from_struct(struct)) elif struct["_class"] == "Tag": return Tag.create(Tag.from_struct(struct)) + elif struct["_class"] == "Date": + return Date().unserialize(Date.from_struct(struct, full=True)) raise AttributeError("invalid struct: %s" % struct) def __str__(self): diff --git a/gramps/gen/lib/surname.py b/gramps/gen/lib/surname.py index b76492065..2915f71ca 100644 --- a/gramps/gen/lib/surname.py +++ b/gramps/gen/lib/surname.py @@ -28,9 +28,6 @@ Surname class for Gramps. # Gramps modules # #------------------------------------------------------------------------- -from gramps.gen.const import GRAMPS_LOCALE as glocale -_ = glocale.translation.gettext - from .secondaryobj import SecondaryObject from .nameorigintype import NameOriginType from .const import IDENTICAL, EQUAL, DIFFERENT @@ -102,7 +99,7 @@ class Surname(SecondaryObject): "connector": self.connector} @classmethod - def get_labels(cls): + def get_labels(cls, _): return { "_class": _("Surname"), "surname": _("Surname"),