Event types know how to abbreviate themselves

svn: r13898
This commit is contained in:
Doug Blank 2009-12-23 19:35:18 +00:00
parent 80c53cce3d
commit 302781a6b3
3 changed files with 46 additions and 25 deletions

View File

@ -29,7 +29,8 @@ Provide the different event types
# Python modules # Python modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gettext import gettext as _ from TransUtils import sgettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
@ -187,6 +188,12 @@ class EventType(GrampsType):
(MARR_ALT , _("Alternate Marriage"), "Alternate Marriage"), (MARR_ALT , _("Alternate Marriage"), "Alternate Marriage"),
] ]
_ABBREVIATIONS = {
BIRTH: _("birth abbreviation|b"),
DEATH: _("death abbreviation|d"),
MARRIAGE: _("marriage abbreviation|m"),
}
def __init__(self, value=None): def __init__(self, value=None):
GrampsType.__init__(self, value) GrampsType.__init__(self, value)
@ -231,3 +238,18 @@ class EventType(GrampsType):
Returns True if EventType is DIVORCE, False otherwise. Returns True if EventType is DIVORCE, False otherwise.
""" """
return self.value == self.DIVORCE return self.value == self.DIVORCE
def get_abbreviation(self):
"""
Returns the abbreviation for this event. Uses the explicitly
given abbreviations, or first letter of each word, or the first
three letters. Appends a period after the abbreviation.
"""
if self.value in self._ABBREVIATIONS:
return self._ABBREVIATIONS[self.value] + "."
else:
abbrev = str(self)
if " " in abbrev:
return ".".join([letter[0].lower() for letter in abbrev.split()]) + "."
else:
return abbrev[:3].lower() + "."

View File

@ -40,6 +40,7 @@ from gen.plug import Gramplet
from ReportBase import ReportUtils from ReportBase import ReportUtils
from BasicUtils import name_displayer from BasicUtils import name_displayer
import DateHandler import DateHandler
from gen.utils import get_birth_or_fallback, get_death_or_fallback
class DescendantGramplet(Gramplet): class DescendantGramplet(Gramplet):
def init(self): def init(self):
@ -69,21 +70,14 @@ class DescendantGramplet(Gramplet):
self.append_text("", scroll_to="begin") self.append_text("", scroll_to="begin")
def dump_dates(self, person): def dump_dates(self, person):
birth_date = "" birth = get_birth_or_fallback(self.dbstate.db, person)
birth_ref = person.get_birth_ref() death = get_death_or_fallback(self.dbstate.db, person)
if birth_ref:
birth = self.dbstate.db.get_event_from_handle(birth_ref.ref)
birth_date = DateHandler.get_date(birth)
else:
birth = None
death_date = "" if birth:
death_ref = person.get_death_ref() birth_date = DateHandler.get_date(birth)
if death_ref:
death = self.dbstate.db.get_event_from_handle(death_ref.ref) if death:
death_date = DateHandler.get_date(death) death_date = DateHandler.get_date(death)
else:
death = None
if birth or death: if birth or death:
self.append_text(' (') self.append_text(' (')
@ -104,12 +98,14 @@ class DescendantGramplet(Gramplet):
if birth: if birth:
if birth_place: if birth_place:
self.append_text(_("b. %(birth_date)s - %(place)s") % { self.append_text(_("%(event_abbrev)s %(birth_date)s - %(place)s") % {
'event_abbrev': birth.type.get_abbreviation(),
'birth_date' : birth_date, 'birth_date' : birth_date,
'place' : birth_place, 'place' : birth_place,
}) })
else: else:
self.append_text(_("b. %(birth_date)s") % { self.append_text(_("%(event_abbrev)s %(birth_date)s") % {
'event_abbrev': birth.type.get_abbreviation(),
'birth_date' : birth_date 'birth_date' : birth_date
}) })
@ -117,12 +113,14 @@ class DescendantGramplet(Gramplet):
if birth: if birth:
self.append_text(', ') self.append_text(', ')
if death_place: if death_place:
self.append_text(_("d. %(death_date)s - %(place)s") % { self.append_text(_("%(event_abbrev)s %(death_date)s - %(place)s") % {
'event_abbrev': death.type.get_abbreviation(),
'death_date' : death_date, 'death_date' : death_date,
'place' : death_place, 'place' : death_place,
}) })
else: else:
self.append_text(_("d. %(death_date)s") % { self.append_text(_("%(event_abbrev)s %(death_date)s") % {
'event_abbrev': death.type.get_abbreviation(),
'death_date' : death_date 'death_date' : death_date
}) })

View File

@ -48,9 +48,6 @@ import DateHandler
import Sort import Sort
from gen.utils import get_birth_or_fallback, get_death_or_fallback from gen.utils import get_birth_or_fallback, get_death_or_fallback
_BORN = _('b.')
_DIED = _('d.')
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# DescendantReport # DescendantReport
@ -98,12 +95,14 @@ class DescendantReport(Report):
if bplace_handle: if bplace_handle:
birth_place = self.database.get_place_from_handle( birth_place = self.database.get_place_from_handle(
bplace_handle).get_title() bplace_handle).get_title()
self.doc.write_text(_("b. %(birth_date)s - %(place)s") % { self.doc.write_text(_("%(event_abbrev)s %(birth_date)s - %(place)s") % {
'event_abbrev': birth.type.get_abbreviation(),
'birth_date' : birth_date, 'birth_date' : birth_date,
'place' : birth_place, 'place' : birth_place,
}) })
else: else:
self.doc.write_text(_("b. %(birth_date)s") % { self.doc.write_text(_("%(event_abbrev)s %(birth_date)s") % {
'event_abbrev': birth.type.get_abbreviation(),
'birth_date' : birth_date 'birth_date' : birth_date
}) })
@ -115,12 +114,14 @@ class DescendantReport(Report):
if dplace_handle: if dplace_handle:
death_place = self.database.get_place_from_handle( death_place = self.database.get_place_from_handle(
dplace_handle).get_title() dplace_handle).get_title()
self.doc.write_text(_("d. %(death_date)s - %(place)s") % { self.doc.write_text(_("%(event_abbrev)s %(death_date)s - %(place)s") % {
'event_abbrev': death.type.get_abbreviation(),
'death_date' : death_date, 'death_date' : death_date,
'place' : death_place, 'place' : death_place,
}) })
else: else:
self.doc.write_text(_("d. %(death_date)s") % { self.doc.write_text(_("%(event_abbrev)s %(death_date)s") % {
'event_abbrev': death.type.get_abbreviation(),
'death_date' : death_date 'death_date' : death_date
}) })