Moved translation funtion to get_label/get_labels
This commit is contained in:
parent
57e349a280
commit
e0c6468c77
@ -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
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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):
|
||||
"""
|
||||
|
@ -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"),
|
||||
|
@ -208,7 +208,7 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_labels(cls):
|
||||
def get_labels(cls, _):
|
||||
return {
|
||||
"_class": _("Person"),
|
||||
"handle": _("Handle"),
|
||||
|
@ -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:
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user