Exemple #1
0
 def latin_american(self):
     """
     Child inherits name from father and mother
     """
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     if self.family:
         father_handle = self.family.get_father_handle()
         mother_handle = self.family.get_mother_handle()
         father = self.dbstate.db.get_person_from_handle(father_handle)
         mother = self.dbstate.db.get_person_from_handle(mother_handle)
         if not father and not mother:
             return name
         if not father:
             preset_name(mother, name)
             return name
         if not mother:
             preset_name(father, name)
             return name
         #we take first surname, and keep that
         mothername = Name()
         preset_name(mother, mothername)
         preset_name(father, name)
         mothersurname = mothername.get_surname_list()[0]
         mothersurname.set_primary(False)
         name.set_surname_list([name.get_surname_list()[0], mothersurname])
         return name
     else:
         return name
Exemple #2
0
    def add(self, *obj):
        person = Person()

        # attempt to get the current surname
        (model, pathlist) = self.selection.get_selected_rows()
        name = Name()
        #the editor requires a surname
        name.add_surname(Surname())
        name.set_primary_surname(0)
        basepers = None
        if len(pathlist) == 1:
            path = pathlist[0]
            pathids = path.get_indices()
            if len(pathids) == 1:
                path = Gtk.TreePath((pathids[0], 0))
            iter_ = model.get_iter(path)
            handle = model.get_handle_from_iter(iter_)
            basepers = self.dbstate.db.get_person_from_handle(handle)
        if basepers:
            preset_name(basepers, name)
        person.set_primary_name(name)
        try:
            EditPerson(self.dbstate, self.uistate, [], person)
        except WindowActiveError:
            pass
Exemple #3
0
    def latin_american_child(self, parent):
        """
        If SURNAME_GUESSING is latin american, then find a child
        and return their name for the father or mother.

        parent = "mother" | "father"
        """
        name = Name()
        #the editor requires a surname
        name.add_surname(Surname())
        name.set_primary_surname(0)
        # for each child, find one with a last name
        for ref in self.obj.get_child_ref_list():
            child = self.db.get_person_from_handle(ref.ref)
            if child:
                pname = child.get_primary_name()
                preset_name(child, name) # add the known family surnames, etc.
                surnames = name.get_surname_list()
                if len(surnames) < 2:
                    return name
                else:
                    #return first for the father, and last for the mother
                    if parent == 'father':
                        name.set_surname_list([surnames[0]])
                        return name
                    else:
                        name.set_surname_list([surnames[-1]])
                        return name
        return name
Exemple #4
0
def _get_styled(name, callname, placeholder=False,
                trans_text=glocale.translation.sgettext, name_format=None):
    """
    Return a StyledText object with the name formatted according to the
    parameters:

    @param callname: whether the callname should be used instead of the first
        name (CALLNAME_REPLACE), underlined within the first name
        (CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
    @param placeholder: whether a series of underscores should be inserted as a
        placeholder if first name or surname are missing.
    @param trans_text: allow deferred translation of strings
    @type trans_text: a GrampsLocale sgettext instance
    trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
    :param name_format: optional format to control display of person's name
    :type name_format: None or int
    """

    # Make a copy of the name object so we don't mess around with the real
    # data.
    n = Name(source=name)

    # Insert placeholders.
    if placeholder:
        if not n.first_name:
            n.first_name = "____________"
        if not n.surname:
            n.surname = "____________"

    if n.call:
        if callname == CALLNAME_REPLACE:
            # Replace first name with call name.
            n.first_name = n.call
        elif callname == CALLNAME_UNDERLINE_ADD:
            if n.call not in n.first_name:
                # Add call name to first name.
                # translators: used in French+Russian, ignore otherwise
                n.first_name = trans_text('"%(callname)s" (%(firstname)s)') % {
                                             'callname':  n.call,
                                             'firstname': n.first_name }

    real_format = name_displayer.get_default_format()
    if name_format is not None:
        name_displayer.set_default_format(name_format)
    text = name_displayer.display_name(n)
    name_displayer.set_default_format(real_format)
    tags = []

    if n.call:
        if callname == CALLNAME_UNDERLINE_ADD:
            # "name" in next line is on purpose: only underline the call name
            # if it was a part of the *original* first name
            if n.call in name.first_name:
                # Underline call name
                callpos = text.find(n.call)
                tags = [StyledTextTag(StyledTextTagType.UNDERLINE, True,
                            [(callpos, callpos + len(n.call))])]

    return StyledText(text, tags)
Exemple #5
0
 def add_nicknames(self, fields, data):
     """Read the NICKNAME property of a VCard."""
     for nick in self.split_unescaped(data, ','):
         nickname = nick.strip()
         if nickname:
             name = Name()
             name.set_nick_name(self.unesc(nickname))
             self.person.add_alternate_name(name)
Exemple #6
0
 def no_name(self):
     """
     Default surname guess.
     """
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     return name
Exemple #7
0
 def add_button_clicked(self, obj):
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     try:
         from .. import EditName
         EditName(self.dbstate, self.uistate, self.track, 
                  name, self.add_callback)
     except WindowActiveError:
         pass
Exemple #8
0
def _get_styled(name, callname, placeholder=False, name_format=None):
    """
    Return a StyledText object with the name formatted according to the
    parameters:

    @param callname: whether the callname should be used instead of the first
        name (CALLNAME_REPLACE), underlined within the first name
        (CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
    @param placeholder: whether a series of underscores should be inserted as a
        placeholder if first name or surname are missing.
    """

    # Make a copy of the name object so we don't mess around with the real
    # data.
    n = Name(source=name)

    # Insert placeholders.
    if placeholder:
        if not n.first_name:
            n.first_name = "____________"
        if not n.surname:
            n.surname = "____________"

    if n.call:
        if callname == CALLNAME_REPLACE:
            # Replace first name with call name.
            n.first_name = n.call
        elif callname == CALLNAME_UNDERLINE_ADD:
            if n.call not in n.first_name:
                # Add call name to first name.
                n.first_name = "\"%(call)s\" (%(first)s)" % {
                        'call':  n.call,
                        'first': n.first_name}

    real_format = name_displayer.get_default_format()
    if name_format is not None:
        name_displayer.set_default_format(name_format)
    text = name_displayer.display_name(n)
    name_displayer.set_default_format(real_format)
    tags = []

    if n.call:
        if callname == CALLNAME_UNDERLINE_ADD:
            # "name" in next line is on purpose: only underline the call name
            # if it was a part of the *original* first name
            if n.call in name.first_name:
                # Underline call name
                callpos = text.find(n.call)
                tags = [StyledTextTag(StyledTextTagType.UNDERLINE, True,
                            [(callpos, callpos + len(n.call))])]

    return StyledText(text, tags)
Exemple #9
0
 def north_american(self):
     """
     Child inherits name from father
     """
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     father_handle = self.family.get_father_handle()
     if father_handle:
         father = self.dbstate.db.get_person_from_handle(father_handle)
         preset_name(father, name)
     return name
Exemple #10
0
 def north_american_child(self):
     """
     If SURNAME_GUESSING is north american, then find a child
     and return their name for the father.
     """
     # for each child, find one with a last name
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     for ref in self.obj.get_child_ref_list():
         child = self.db.get_person_from_handle(ref.ref)
         if child:
             preset_name(child, name)
             return name
     return name
Exemple #11
0
 def get_name(self, person, maiden_name = None):
     """ Return person's name, unless maiden_name given, 
         unless married_name listed. 
     """
     # Get all of a person's names:
     primary_name = person.get_primary_name()
     married_name = None
     names = [primary_name] + person.get_alternate_names()
     for name in names:
         if int(name.get_type()) == NameType.MARRIED:
             married_name = name
             break # use first
     # Now, decide which to use:
     if maiden_name is not None:
         if married_name is not None:
             name = Name(married_name)
         else:
             name = Name(primary_name)
             surname = Surname()
             surname.set_surname(maiden_name)
             name.set_surname_list([surname])
     else:
         name = Name(primary_name)
     name.set_display_as(self.name_format)
     return _nd.display_name(name)
Exemple #12
0
    def add_name(self):
        """
        Add the name to the person.

        Returns True on success, False on failure.
        """
        if not self.name_parts.strip():
            LOG.warning("VCard is malformed missing the compulsory N property,"
                        " so there is no name; skip it.")
            return False
        if not self.formatted_name:
            LOG.warning("VCard is malformed missing the compulsory FN property"
                        ", get name from N alone.")
        data_fields = self.split_unescaped(self.name_parts, ';')
        if len(data_fields) != 5:
            LOG.warning("VCard is malformed wrong number of name components.")

        name = Name()
        name.set_type(NameType(NameType.BIRTH))

        if data_fields[0].strip():
            # assume first surname is primary
            for surname_str in self.split_unescaped(data_fields[0], ','):
                surname = Surname()
                prefix, sname = splitof_nameprefix(self.unesc(surname_str))
                surname.set_surname(sname.strip())
                surname.set_prefix(prefix.strip())
                name.add_surname(surname)

        if len(data_fields) > 1 and data_fields[1].strip():
            given_name = ' '.join(self.unesc(
                                  self.split_unescaped(data_fields[1], ',')))
        else:
            given_name = ''
        if len(data_fields) > 2 and data_fields[2].strip():
            additional_names = ' '.join(self.unesc(
                                     self.split_unescaped(data_fields[2], ',')))
        else:
            additional_names = ''
        self.add_firstname(given_name.strip(), additional_names.strip(), name)

        if len(data_fields) > 3 and data_fields[3].strip():
            name.set_title(' '.join(self.unesc(
                            self.split_unescaped(data_fields[3], ','))))
        if len(data_fields) > 4 and data_fields[4].strip():
            name.set_suffix(' '.join(self.unesc(
                             self.split_unescaped(data_fields[4], ','))))

        self.person.set_primary_name(name)
        return True
Exemple #13
0
 def get_names(self, sql, from_type, from_handle, primary):
     handles = self.get_links(sql, from_type, from_handle, "name")
     names = []
     for handle in handles:
         results = sql.query(
             "select * from name where handle = ? and primary_name = ?;",
             handle, primary)
         if len(results) > 0:
             names += results
     result = [self.pack_name(sql, name) for name in names]
     if primary:
         if len(result) == 1:
             return result[0]
         elif len(result) == 0:
             return Name().serialize()
         else:
             raise Exception("too many primary names")
     else:
         return result
Exemple #14
0
def _get_styled(name, callname, placeholder=False):
    """
    Return a StyledText object with the name formatted according to the
    parameters:

    @param callname: whether the callname should be used instead of the first
        name (CALLNAME_REPLACE), underlined within the first name
        (CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
    @param placeholder: whether a series of underscores should be inserted as a
        placeholder if first name or surname are missing.
    """

    # Make a copy of the name object so we don't mess around with the real
    # data.
    n = Name(source=name)

    # Insert placeholders.
    if placeholder:
        if not n.first_name:
            n.first_name = "____________"
        if not n.surname:
            n.surname = "____________"

    if n.call:
        if callname == CALLNAME_REPLACE:
            # Replace first name with call name.
            n.first_name = n.call
        elif callname == CALLNAME_UNDERLINE_ADD:
            if n.call not in n.first_name:
                # Add call name to first name.
                n.first_name = "\"%(call)s\" (%(first)s)" % {
                        'call':  n.call,
                        'first': n.first_name}

    text = name_displayer.display_name(n)
    tags = []

    if n.call:
        if callname == CALLNAME_UNDERLINE_ADD:
            # "name" in next line is on purpose: only underline the call name
            # if it was a part of the *original* first name
            if n.call in name.first_name:
                # Underline call name
                callpos = text.find(n.call)
                tags = [StyledTextTag(StyledTextTagType.UNDERLINE, True,
                            [(callpos, callpos + len(n.call))])]

    return StyledText(text, tags)
Exemple #15
0
 def north_american_child(self):
     """
     If SURNAME_GUESSING is north american, then find a child
     and return their name for the father.
     """
     # for each child, find one with a last name
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     for ref in self.obj.get_child_ref_list():
         child = self.db.get_person_from_handle(ref.ref)
         if child:
             preset_name(child, name)
             return name
     return name
Exemple #16
0
 def add_child_to_fam(self, obj, event, handle):
     if button_activated(event, _LEFT_BUTTON):
         callback = lambda x: self.callback_add_child(x, handle)
         person = Person()
         name = Name()
         #the editor requires a surname
         name.add_surname(Surname())
         name.set_primary_surname(0)
         family = self.dbstate.db.get_family_from_handle(handle)
         father = self.dbstate.db.get_person_from_handle(
                                     family.get_father_handle())
         if father:
             preset_name(father, name)
         person.set_primary_name(name)
         try:
             EditPerson(self.dbstate, self.uistate, [], person,
                        callback=callback)
         except WindowActiveError:
             pass
 def get_name(self, person, maiden_name=None):
     """
     Return person's name, unless maiden_name given, unless married_name
     listed.
     """
     # Get all of a person's names:
     primary_name = person.get_primary_name()
     married_name = None
     names = [primary_name] + person.get_alternate_names()
     for name in names:
         if int(name.get_type()) == NameType.MARRIED:
             married_name = name
             break  # use first
     # Now, decide which to use:
     if maiden_name is not None:
         if married_name is not None:
             name = Name(married_name)
         else:
             name = Name(primary_name)
             surname_obj = name.get_primary_surname()
             surname_obj.set_surname(maiden_name)
     else:
         name = Name(primary_name)
     return self._name_display.display_name(name)
Exemple #18
0
 def sort_name(self, data):
     n = Name()
     n.unserialize(data[COLUMN_NAME])
     return (n.get_primary_surname().get_surname(), n.get_first_name())
    def run_tool(self):
        self.progress = ProgressMeter(_('Running Date Test'),
                                      '',
                                      parent=self.parent_window)
        self.progress.set_pass(_('Generating dates'), 4)
        dates = []
        # first some valid dates
        calendar = Date.CAL_GREGORIAN
        for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED,
                        Date.QUAL_CALCULATED):
            for modifier in (Date.MOD_NONE, Date.MOD_BEFORE, Date.MOD_AFTER,
                             Date.MOD_ABOUT):
                for slash1 in (False, True):
                    for month in range(0, 13):
                        for day in (0, 5, 27):
                            if not month and day:
                                continue
                            d = Date()
                            d.set(quality, modifier, calendar,
                                  (day, month, 1789, slash1), "Text comment")
                            dates.append(d)
            for modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
                for slash1 in (False, True):
                    for slash2 in (False, True):
                        for month in range(0, 13):
                            for day in (0, 5, 27):
                                if not month and day:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, day, month,
                                       1876, slash2), "Text comment")
                                dates.append(d)

                                if not month:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, day,
                                       13 - month, 1876, slash2),
                                      "Text comment")
                                dates.append(d)

                                if not day:
                                    continue

                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, 32 - day,
                                       month, 1876, slash2), "Text comment")
                                dates.append(d)
                                d = Date()
                                d.set(quality, modifier, calendar,
                                      (day, month, 1789, slash1, 32 - day,
                                       13 - month, 1876, slash2),
                                      "Text comment")
                                dates.append(d)
            modifier = Date.MOD_TEXTONLY
            d = Date()
            d.set(quality, modifier, calendar, Date.EMPTY,
                  "This is a textual date")
            dates.append(d)
            self.progress.step()

        # test invalid dates
        #dateval = (4,7,1789,False,5,8,1876,False)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #              Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #self.progress.step()
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,55,8,1876,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,5,88,1876,False),"Text comment")
        #dates.append( d)

        with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
            self.db.disable_signals()
            self.progress.set_pass(_('Generating dates'), len(dates))

            # create pass and fail tags
            pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
            fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')

            # now add them as birth to new persons
            i = 1
            for dateval in dates:
                person = Person()
                surname = Surname()
                surname.set_surname("DateTest")
                name = Name()
                name.add_surname(surname)
                name.set_first_name("Test %d" % i)
                person.set_primary_name(name)
                self.db.add_person(person, self.trans)
                bevent = Event()
                bevent.set_type(EventType.BIRTH)
                bevent.set_date_object(dateval)
                bevent.set_description("Date Test %d (source)" % i)
                bevent_h = self.db.add_event(bevent, self.trans)
                bevent_ref = EventRef()
                bevent_ref.set_reference_handle(bevent_h)
                # for the death event display the date as text and parse it back to a new date
                ndate = None
                try:
                    datestr = _dd.display(dateval)
                    try:
                        ndate = _dp.parse(datestr)
                        if not ndate:
                            ndate = Date()
                            ndate.set_as_text("DateParser None")
                            person.add_tag(fail_handle)
                        else:
                            person.add_tag(pass_handle)
                    except:
                        ndate = Date()
                        ndate.set_as_text("DateParser Exception %s" % ("".join(
                            traceback.format_exception(*sys.exc_info())), ))
                        person.add_tag(fail_handle)
                    else:
                        person.add_tag(pass_handle)
                except:
                    ndate = Date()
                    ndate.set_as_text("DateDisplay Exception: %s" % ("".join(
                        traceback.format_exception(*sys.exc_info())), ))
                    person.add_tag(fail_handle)

                if dateval.get_modifier() != Date.MOD_TEXTONLY \
                       and ndate.get_modifier() == Date.MOD_TEXTONLY:
                    # parser was unable to correctly parse the string
                    ndate.set_as_text("TEXTONLY: " + ndate.get_text())
                    person.add_tag(fail_handle)
                if dateval.get_modifier() == Date.MOD_TEXTONLY \
                        and dateval.get_text().count("Traceback") \
                        and pass_handle in person.get_tag_list():
                    person.add_tag(fail_handle)

                devent = Event()
                devent.set_type(EventType.DEATH)
                devent.set_date_object(ndate)
                devent.set_description("Date Test %d (result)" % i)
                devent_h = self.db.add_event(devent, self.trans)
                devent_ref = EventRef()
                devent_ref.set_reference_handle(devent_h)
                person.set_birth_ref(bevent_ref)
                person.set_death_ref(devent_ref)
                self.db.commit_person(person, self.trans)
                i = i + 1
                self.progress.step()
        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()
    def add_name(self):
        """
        Add the name to the person.

        Returns True on success, False on failure.
        """
        if not self.name_parts.strip():
            self.__add_msg(
                _("VCard is malformed missing the compulsory N "
                  "property, so there is no name; skip it."),
                self.line_num - 1)
            return False
        if not self.formatted_name:
            self.__add_msg(
                _("VCard is malformed missing the compulsory FN "
                  "property, get name from N alone."), self.line_num - 1)
        data_fields = self.split_unescaped(self.name_parts, ';')
        if len(data_fields) != 5:
            self.__add_msg(
                _("VCard is malformed wrong number of name "
                  "components."), self.line_num - 1)

        name = Name()
        name.set_type(NameType(NameType.BIRTH))

        if data_fields[0].strip():
            # assume first surname is primary
            for surname_str in self.split_unescaped(data_fields[0], ','):
                surname = Surname()
                prefix, sname = splitof_nameprefix(self.unesc(surname_str))
                surname.set_surname(sname.strip())
                surname.set_prefix(prefix.strip())
                name.add_surname(surname)
            name.set_primary_surname()

        if len(data_fields) > 1 and data_fields[1].strip():
            given_name = ' '.join(
                self.unesc(self.split_unescaped(data_fields[1], ',')))
        else:
            given_name = ''
        if len(data_fields) > 2 and data_fields[2].strip():
            additional_names = ' '.join(
                self.unesc(self.split_unescaped(data_fields[2], ',')))
        else:
            additional_names = ''
        self.add_firstname(given_name.strip(), additional_names.strip(), name)

        if len(data_fields) > 3 and data_fields[3].strip():
            name.set_title(' '.join(
                self.unesc(self.split_unescaped(data_fields[3], ','))))
        if len(data_fields) > 4 and data_fields[4].strip():
            name.set_suffix(' '.join(
                self.unesc(self.split_unescaped(data_fields[4], ','))))

        self.person.set_primary_name(name)
        return True
Exemple #21
0
    def parse_person(self, fields, idx, gender, father_surname):

        if not father_surname:
            if not idx < len(fields):
                LOG.warning("Missing surname of person in line %d!" %
                            self.lineno)
                surname = ""
            else:
                surname = self.decode(fields[idx])
            idx += 1
        else:
            surname = father_surname

        if not idx < len(fields):
            LOG.warning("Missing firstname of person in line %d!" %
                        self.lineno)
            firstname = ""
        else:
            firstname = self.decode(fields[idx])
        idx += 1
        if idx < len(fields) and father_surname:
            noSurnameRe = re.compile("^[({\[~><?0-9#].*$")
            if not noSurnameRe.match(fields[idx]):
                surname = self.decode(fields[idx])
                idx += 1

        LOG.debug("Person: %s %s" % (firstname, surname))
        person = self.get_or_create_person(firstname, surname)
        name = Name()
        name.set_type(NameType(NameType.BIRTH))
        name.set_first_name(firstname)
        surname_obj = name.get_primary_surname()
        surname_obj.set_surname(surname)
        person.set_primary_name(name)
        if person.get_gender() == Person.UNKNOWN and gender is not None:
            person.set_gender(gender)
        self.db.commit_person(person, self.trans)
        personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$")
        dateRe = re.compile("^[kmes0-9~<>?]+.*$")

        source = None
        birth_parsed = False
        birth_date = None
        birth_place = None
        birth_source = None

        bapt_date = None
        bapt_place = None
        bapt_source = None

        death_date = None
        death_place = None
        death_source = None
        death_cause = None

        crem_date = None
        bur_date = None
        bur_place = None
        bur_source = None

        public_name = None
        firstname_aliases = []
        nick_names = []
        name_aliases = []
        surname_aliases = []

        while idx < len(fields) and personDataRe.match(fields[idx]):
            field = fields[idx]
            idx += 1
            if field.startswith('('):
                LOG.debug("Public Name: %s" % field)
                public_name = self.decode(field[1:-1])
            elif field.startswith('{'):
                LOG.debug("Firstsname Alias: %s" % field)
                firstname_aliases.append(self.decode(field[1:-1]))
            elif field.startswith('['):
                LOG.debug("Title: %s" % field)
                titleparts = self.decode(field[1:-1]).split(":")
                tname = ttitle = tplace = tstart = tend = tnth = None
                try:
                    tname = titleparts[0]
                    ttitle = titleparts[1]
                    if titleparts[2]:
                        tplace = self.get_or_create_place(titleparts[2])
                    tstart = self.parse_date(titleparts[3])
                    tend = self.parse_date(titleparts[4])
                    tnth = titleparts[5]
                except IndexError:  # not all parts are written all the time
                    pass
                if tnth:  # Append title numer to title
                    ttitle += ", " + tnth
                title = self.create_event(EventType.NOB_TITLE, ttitle, tstart,
                                          tplace)
                # TODO: Geneweb has a start date and an end date, and therefore
                # supports stuff like: FROM about 1955 TO between 1998 and 1999
                # gramps only supports one single date or range.
                if tname and tname != "*":
                    n = Note()
                    n.set(tname)
                    self.db.add_note(n, self.trans)
                    title.add_note(n.handle)
                title_ref = EventRef()
                title_ref.set_reference_handle(title.get_handle())
                person.add_event_ref(title_ref)
            elif field == '#nick' and idx < len(fields):
                LOG.debug("Nick Name: %s" % fields[idx])
                nick_names.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#occu' and idx < len(fields):
                LOG.debug("Occupation: %s" % fields[idx])
                occu = self.create_event(EventType.OCCUPATION,
                                         self.decode(fields[idx]))
                occu_ref = EventRef()
                occu_ref.set_reference_handle(occu.get_handle())
                person.add_event_ref(occu_ref)
                idx += 1
            elif field == '#alias' and idx < len(fields):
                LOG.debug("Name Alias: %s" % fields[idx])
                name_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#salias' and idx < len(fields):
                LOG.debug("Surname Alias: %s" % fields[idx])
                surname_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#image' and idx < len(fields):
                LOG.debug("Image: %s" % fields[idx])
                idx += 1
            elif field == '#src' and idx < len(fields):
                LOG.debug("Source: %s" % fields[idx])
                source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#bs' and idx < len(fields):
                LOG.debug("Birth Source: %s" % fields[idx])
                birth_source = self.get_or_create_source(
                    self.decode(fields[idx]))
                idx += 1
            elif field[0] == '!':
                LOG.debug("Baptize at: %s" % field[1:])
                bapt_date = self.parse_date(self.decode(field[1:]))
            elif field == '#bp' and idx < len(fields):
                LOG.debug("Birth Place: %s" % fields[idx])
                birth_place = self.get_or_create_place(self.decode(
                    fields[idx]))
                idx += 1
            elif field == '#pp' and idx < len(fields):
                LOG.debug("Baptize Place: %s" % fields[idx])
                bapt_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#ps' and idx < len(fields):
                LOG.debug("Baptize Source: %s" % fields[idx])
                bapt_source = self.get_or_create_source(
                    self.decode(fields[idx]))
                idx += 1
            elif field == '#dp' and idx < len(fields):
                LOG.debug("Death Place: %s" % fields[idx])
                death_place = self.get_or_create_place(self.decode(
                    fields[idx]))
                idx += 1
            elif field == '#ds' and idx < len(fields):
                LOG.debug("Death Source: %s" % fields[idx])
                death_source = self.get_or_create_source(
                    self.decode(fields[idx]))
                idx += 1
            elif field == '#buri' and idx < len(fields):
                if fields[idx][0] != '#':  # bug in GeneWeb: empty #buri fields
                    LOG.debug("Burial Date: %s" % fields[idx])
                    bur_date = self.parse_date(self.decode(fields[idx]))
                    idx += 1
            elif field == '#crem' and idx < len(fields):
                LOG.debug("Cremention Date: %s" % fields[idx])
                crem_date = self.parse_date(self.decode(fields[idx]))
                idx += 1
            elif field == '#rp' and idx < len(fields):
                LOG.debug("Burial Place: %s" % fields[idx])
                bur_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#rs' and idx < len(fields):
                LOG.debug("Burial Source: %s" % fields[idx])
                bur_source = self.get_or_create_source(self.decode(
                    fields[idx]))
                idx += 1
            elif field == '#apubl':
                LOG.debug("This is a public record")
            elif field == '#apriv':
                LOG.debug("This is a private record")
                person.set_privacy(True)
            elif field == '#h':
                LOG.debug("This is a restricted record")
                #TODO: Gramps does currently not feature this level
                person.set_privacy(True)
            elif dateRe.match(field):
                if not birth_parsed:
                    LOG.debug("Birth Date: %s" % field)
                    birth_date = self.parse_date(self.decode(field))
                    birth_parsed = True
                else:
                    LOG.debug("Death Date: %s" % field)
                    death_date = self.parse_date(self.decode(field))
                    if field == "mj":
                        death_cause = "Died joung"
                    elif field.startswith("k"):
                        death_cause = "Killed"
                    elif field.startswith("m"):
                        death_cause = "Murdered"
                    elif field.startswith("e"):
                        death_cause = "Executed"
                    elif field.startswith("d"):
                        death_cause = "Disappeared"
                    #TODO: Set special death types more properly
            else:
                LOG.warning(
                    ("parse_person(): Unknown field " +
                     "'%s' for person in line %d!") % (field, self.lineno))

        if public_name:
            name = person.get_primary_name()
            name.set_type(NameType(NameType.BIRTH))
            person.add_alternate_name(name)
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(public_name)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.set_primary_name(name)

        for aka in nick_names:
            name = Attribute()
            name.set_type(AttributeType(AttributeType.NICKNAME))
            name.set_value(aka)
            person.add_attribute(name)

        for aka in firstname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in name_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in surname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            if public_name:
                name.set_first_name(public_name)
            else:
                name.set_first_name(firstname)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(aka)
            person.add_alternate_name(name)

        if source:
            person.add_citation(source.get_handle())

        if birth_date or birth_place or birth_source:
            birth = self.create_event(EventType.BIRTH, None, birth_date,
                                      birth_place, birth_source)
            birth_ref = EventRef()
            birth_ref.set_reference_handle(birth.get_handle())
            person.set_birth_ref(birth_ref)

        if bapt_date or bapt_place or bapt_source:
            babt = self.create_event(EventType.BAPTISM, None, bapt_date,
                                     bapt_place, bapt_source)
            babt_ref = EventRef()
            babt_ref.set_reference_handle(babt.get_handle())
            person.add_event_ref(babt_ref)

        if death_date or death_place or death_source or death_cause:
            death = self.create_event(EventType.DEATH, None, death_date,
                                      death_place, death_source)
            if death_cause:
                death.set_description(death_cause)
                self.db.commit_event(death, self.trans)
            death_ref = EventRef()
            death_ref.set_reference_handle(death.get_handle())
            person.set_death_ref(death_ref)

        if bur_date:
            bur = self.create_event(EventType.BURIAL, None, bur_date,
                                    bur_place, bur_source)
            bur_ref = EventRef()
            bur_ref.set_reference_handle(bur.get_handle())
            person.add_event_ref(bur_ref)

        if crem_date:
            crem = self.create_event(EventType.CREMATION, None, crem_date,
                                     bur_place, bur_source)
            crem_ref = EventRef()
            crem_ref.set_reference_handle(crem.get_handle())
            person.add_event_ref(crem_ref)

        self.db.commit_person(person, self.trans)

        return (idx, person)
Exemple #22
0
def _get_styled(name,
                callname,
                placeholder=False,
                trans_text=glocale.translation.sgettext,
                name_format=None):
    """
    Return a StyledText object with the name formatted according to the
    parameters:

    @param callname: whether the callname should be used instead of the first
        name (CALLNAME_REPLACE), underlined within the first name
        (CALLNAME_UNDERLINE_ADD) or not used at all (CALLNAME_DONTUSE).
    @param placeholder: whether a series of underscores should be inserted as a
        placeholder if first name or surname are missing.
    @param trans_text: allow deferred translation of strings
    @type trans_text: a GrampsLocale sgettext instance
    trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
    :param name_format: optional format to control display of person's name
    :type name_format: None or int
    """

    # Make a copy of the name object so we don't mess around with the real
    # data.
    n = Name(source=name)

    # Insert placeholders.
    if placeholder:
        if not n.first_name:
            n.first_name = "____________"
        if not n.surname:
            n.surname = "____________"

    if n.call:
        if callname == CALLNAME_REPLACE:
            # Replace first name with call name.
            n.first_name = n.call
        elif callname == CALLNAME_UNDERLINE_ADD:
            if n.call not in n.first_name:
                # Add call name to first name.
                # translators: used in French+Russian, ignore otherwise
                n.first_name = trans_text('"%(callname)s" (%(firstname)s)') % {
                    'callname': n.call,
                    'firstname': n.first_name
                }

    real_format = name_displayer.get_default_format()
    if name_format is not None:
        name_displayer.set_default_format(name_format)
    text = name_displayer.display_name(n)
    name_displayer.set_default_format(real_format)
    tags = []

    if n.call:
        if callname == CALLNAME_UNDERLINE_ADD:
            # "name" in next line is on purpose: only underline the call name
            # if it was a part of the *original* first name
            if n.call in name.first_name:
                # Underline call name
                callpos = text.find(n.call)
                tags = [
                    StyledTextTag(StyledTextTagType.UNDERLINE, True,
                                  [(callpos, callpos + len(n.call))])
                ]

    return StyledText(text, tags)
Exemple #23
0
    def parse_person(self,fields,idx,gender,father_surname):

        if not father_surname:
            if not idx < len(fields):
                LOG.warning("Missing surname of person in line %d!" % self.lineno)
                surname =""
            else:
                surname = self.decode(fields[idx])
            idx += 1
        else:
            surname = father_surname

        if not idx < len(fields):
            LOG.warning("Missing firstname of person in line %d!" % self.lineno)
            firstname = ""
        else:
            firstname = self.decode(fields[idx])
        idx += 1
        if idx < len(fields) and father_surname:
            noSurnameRe = re.compile("^[({\[~><?0-9#].*$")
            if not noSurnameRe.match(fields[idx]):
                surname = self.decode(fields[idx])
                idx += 1

        LOG.debug("Person: %s %s" % (firstname, surname))
        person = self.get_or_create_person(firstname,surname)
        name = Name()
        name.set_type( NameType(NameType.BIRTH))
        name.set_first_name(firstname)
        surname_obj = name.get_primary_surname()
        surname_obj.set_surname(surname)
        person.set_primary_name(name)
        if person.get_gender() == Person.UNKNOWN and gender is not None:
            person.set_gender(gender)
        self.db.commit_person(person,self.trans)
        personDataRe = re.compile("^[kmes0-9<>~#\[({!].*$")
        dateRe = re.compile("^[kmes0-9~<>?]+.*$")

        source = None
        birth_parsed = False
        birth_date = None
        birth_place = None
        birth_source = None

        bapt_date = None
        bapt_place = None
        bapt_source = None

        death_date = None
        death_place = None
        death_source = None
        death_cause = None

        crem_date = None
        bur_date = None
        bur_place = None
        bur_source = None

        public_name = None
        firstname_aliases = []
        nick_names = []
        name_aliases = []
        surname_aliases = []

        while idx < len(fields) and personDataRe.match(fields[idx]):
            field = fields[idx]
            idx += 1
            if field.startswith('('):
                LOG.debug("Public Name: %s" % field)
                public_name = self.decode(field[1:-1])
            elif field.startswith('{'):
                LOG.debug("Firstsname Alias: %s" % field)
                firstname_aliases.append(self.decode(field[1:-1]))
            elif field.startswith('['):
                LOG.debug("Title: %s" % field)
                titleparts = self.decode(field[1:-1]).split(":")
                tname = ttitle = tplace = tstart = tend = tnth = None
                try:
                    tname =  titleparts[0]
                    ttitle = titleparts[1]
                    if titleparts[2]:
                        tplace = self.get_or_create_place(titleparts[2])
                    tstart = self.parse_date(titleparts[3])
                    tend =   self.parse_date(titleparts[4])
                    tnth =   titleparts[5]
                except IndexError:  # not all parts are written all the time
                    pass
                if tnth:    # Append title numer to title
                    ttitle += ", " + tnth
                title = self.create_event(
                           EventType.NOB_TITLE, ttitle, tstart, tplace)
                # TODO: Geneweb has a start date and an end date, and therefore
                # supports stuff like: FROM about 1955 TO between 1998 and 1999
                # gramps only supports one single date or range.
                if tname and tname != "*":
                    n = Note()
                    n.set(tname)
                    self.db.add_note(n,self.trans)
                    title.add_note( n.handle)
                title_ref = EventRef()
                title_ref.set_reference_handle(title.get_handle())
                person.add_event_ref(title_ref)
            elif field == '#nick' and idx < len(fields):
                LOG.debug("Nick Name: %s" % fields[idx])
                nick_names.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#occu' and idx < len(fields):
                LOG.debug("Occupation: %s" % fields[idx])
                occu = self.create_event(
                        EventType.OCCUPATION, self.decode(fields[idx]))
                occu_ref = EventRef()
                occu_ref.set_reference_handle(occu.get_handle())
                person.add_event_ref(occu_ref)
                idx += 1
            elif field == '#alias' and idx < len(fields):
                LOG.debug("Name Alias: %s" % fields[idx])
                name_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#salias' and idx < len(fields):
                LOG.debug("Surname Alias: %s" % fields[idx])
                surname_aliases.append(self.decode(fields[idx]))
                idx += 1
            elif field == '#image' and idx < len(fields):
                LOG.debug("Image: %s" % fields[idx])
                idx += 1
            elif field == '#src' and idx < len(fields):
                LOG.debug("Source: %s" % fields[idx])
                source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#bs' and idx < len(fields):
                LOG.debug("Birth Source: %s" % fields[idx])
                birth_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field[0] == '!':
                LOG.debug("Baptize at: %s" % field[1:])
                bapt_date = self.parse_date(self.decode(field[1:]))
            elif field == '#bp' and idx < len(fields):
                LOG.debug("Birth Place: %s" % fields[idx])
                birth_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#pp' and idx < len(fields):
                LOG.debug("Baptize Place: %s" % fields[idx])
                bapt_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#ps' and idx < len(fields):
                LOG.debug("Baptize Source: %s" % fields[idx])
                bapt_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#dp' and idx < len(fields):
                LOG.debug("Death Place: %s" % fields[idx])
                death_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#ds' and idx < len(fields):
                LOG.debug("Death Source: %s" % fields[idx])
                death_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#buri' and idx < len(fields):
                if fields[idx][0]!='#': # bug in GeneWeb: empty #buri fields
                    LOG.debug("Burial Date: %s" % fields[idx])
                    bur_date = self.parse_date(self.decode(fields[idx]))
                    idx += 1
            elif field == '#crem' and idx < len(fields):
                LOG.debug("Cremention Date: %s" % fields[idx])
                crem_date = self.parse_date(self.decode(fields[idx]))
                idx += 1
            elif field == '#rp' and idx < len(fields):
                LOG.debug("Burial Place: %s" % fields[idx])
                bur_place = self.get_or_create_place(self.decode(fields[idx]))
                idx += 1
            elif field == '#rs' and idx < len(fields):
                LOG.debug("Burial Source: %s" % fields[idx])
                bur_source = self.get_or_create_source(self.decode(fields[idx]))
                idx += 1
            elif field == '#apubl':
                LOG.debug("This is a public record")
            elif field == '#apriv':
                LOG.debug("This is a private record")
                person.set_privacy(True)
            elif field == '#h':
                LOG.debug("This is a restricted record")
                #TODO: Gramps does currently not feature this level
                person.set_privacy(True)
            elif dateRe.match(field):
                if not birth_parsed:
                    LOG.debug("Birth Date: %s" % field)
                    birth_date = self.parse_date(self.decode(field))
                    birth_parsed = True
                else:
                    LOG.debug("Death Date: %s" % field)
                    death_date = self.parse_date(self.decode(field))
                    if field == "mj":
                        death_cause = "Died joung"
                    elif field.startswith("k"):
                        death_cause = "Killed"
                    elif field.startswith("m"):
                        death_cause = "Murdered"
                    elif field.startswith("e"):
                        death_cause = "Executed"
                    elif field.startswith("d"):
                        death_cause = "Disappeared"
                    #TODO: Set special death types more properly
            else:
                LOG.warning(("parse_person(): Unknown field " +
                          "'%s' for person in line %d!") % (field, self.lineno))

        if public_name:
            name = person.get_primary_name()
            name.set_type(NameType(NameType.BIRTH))
            person.add_alternate_name(name)
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(public_name)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.set_primary_name(name)

        for aka in nick_names:
            name = Attribute()
            name.set_type(AttributeType(AttributeType.NICKNAME))
            name.set_value(aka)
            person.add_attribute(name)

        for aka in firstname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in name_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            name.set_first_name(aka)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(surname)
            person.add_alternate_name(name)

        for aka in surname_aliases:
            name = Name()
            name.set_type(NameType(NameType.AKA))
            if public_name:
                name.set_first_name(public_name)
            else:
                name.set_first_name(firstname)
            surname_obj = name.get_primary_surname()
            surname_obj.set_surname(aka)
            person.add_alternate_name(name)

        if source:
            person.add_citation(source.get_handle())

        if birth_date or birth_place or birth_source:
            birth = self.create_event(EventType.BIRTH, None, birth_date, birth_place, birth_source)
            birth_ref = EventRef()
            birth_ref.set_reference_handle( birth.get_handle())
            person.set_birth_ref( birth_ref)

        if bapt_date or bapt_place or bapt_source:
            babt = self.create_event(EventType.BAPTISM, None, bapt_date, bapt_place, bapt_source)
            babt_ref = EventRef()
            babt_ref.set_reference_handle( babt.get_handle())
            person.add_event_ref( babt_ref)

        if death_date or death_place or death_source or death_cause:
            death = self.create_event(EventType.DEATH, None, death_date, death_place, death_source)
            if death_cause:
                death.set_description(death_cause)
                self.db.commit_event(death,self.trans)
            death_ref = EventRef()
            death_ref.set_reference_handle( death.get_handle())
            person.set_death_ref( death_ref)

        if bur_date:
            bur = self.create_event(EventType.BURIAL, None, bur_date, bur_place, bur_source)
            bur_ref = EventRef()
            bur_ref.set_reference_handle( bur.get_handle())
            person.add_event_ref( bur_ref)

        if crem_date:
            crem = self.create_event(EventType.CREMATION, None, crem_date, bur_place, bur_source)
            crem_ref = EventRef()
            crem_ref.set_reference_handle( crem.get_handle())
            person.add_event_ref(crem_ref)

        self.db.commit_person(person,self.trans)

        return (idx,person)
Exemple #24
0
    def familypage(self, report, title, family_handle):
        """
        Create a family page

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: family_handle -- The handle for the family to add
        """
        family = report.database.get_family_from_handle(family_handle)
        if not family:
            return
        BasePage.__init__(self, report, title, family.get_gramps_id())
        ldatec = family.get_change_time()

        self.bibli = Bibliography()
        self.uplink = True
        family_name = self.report.get_family_name(family)
        self.page_title = family_name

        self.familymappages = report.options["familymappages"]

        output_file, sio = self.report.create_file(family.get_handle(), "fam")
        result = self.write_header(family_name)
        familydetailpage, dummy_head, dummy_body, outerwrapper = result

        # begin FamilyDetaill division
        with Html("div", class_="content",
                  id="RelationshipDetail") as relationshipdetail:
            outerwrapper += relationshipdetail

            # family media list for initial thumbnail
            if self.create_media:
                media_list = family.get_media_list()
                # If Event pages are not being created, then we need to display
                # the family event media here
                if not self.inc_events:
                    for evt_ref in family.get_event_ref_list():
                        event = self.r_db.get_event_from_handle(evt_ref.ref)
                        media_list += event.get_media_list()

            relationshipdetail += Html(
                "h2", self.page_title, inline=True) + (
                    Html('sup') + (Html('small') +
                                   self.get_citation_links(
                                       family.get_citation_list())))

            # display relationships
            families = self.display_family_relationships(family, None)
            if families is not None:
                relationshipdetail += families

            # display additional images as gallery
            if self.create_media and media_list:
                addgallery = self.disp_add_img_as_gallery(media_list, family)
                if addgallery:
                    relationshipdetail += addgallery

            # Narrative subsection
            notelist = family.get_note_list()
            if notelist:
                relationshipdetail += self.display_note_list(notelist, Family)

            # display family LDS ordinance...
            family_lds_ordinance_list = family.get_lds_ord_list()
            if family_lds_ordinance_list:
                relationshipdetail += self.display_lds_ordinance(family)

            # get attribute list
            attrlist = family.get_attribute_list()
            if attrlist:
                attrsection, attrtable = self.display_attribute_header()
                self.display_attr_list(attrlist, attrtable)
                relationshipdetail += attrsection

            # for use in family map pages...
            if self.report.options["familymappages"]:
                name_format = self.report.options['name_format']
                fhandle = mhandle = father = mother = None
                relationshipdetail += Html("h4", _("Family map"), inline=True)
                mapdetail = Html("br")
                fhandle = family.get_father_handle()
                for handle, dummy_url in self.report.fam_link.items():
                    if fhandle == handle:
                        father = self.r_db.get_person_from_handle(fhandle)
                        break
                if father:
                    primary_name = father.get_primary_name()
                    name = Name(primary_name)
                    name.set_display_as(name_format)
                    fname = html_escape(_nd.display_name(name))
                    mapdetail += self.family_map_link_for_parent(fhandle, fname)
                mapdetail += Html("br")
                mhandle = family.get_mother_handle()
                for handle, dummy_url in self.report.fam_link.items():
                    if mhandle == handle:
                        mother = self.r_db.get_person_from_handle(mhandle)
                        break
                if mother:
                    primary_name = mother.get_primary_name()
                    name = Name(primary_name)
                    name.set_display_as(name_format)
                    mname = html_escape(_nd.display_name(name))
                    mapdetail += self.family_map_link_for_parent(mhandle, mname)
                relationshipdetail += mapdetail

            # source references
            srcrefs = self.display_ind_sources(family)
            if srcrefs:
                relationshipdetail += srcrefs

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(familydetailpage, output_file, sio, ldatec)
Exemple #25
0
 def sort_name(self, data):
     n = Name()
     n.unserialize(data[COLUMN_NAME])
     return (n.get_primary_surname().get_surname(), n.get_first_name())
Exemple #26
0
 def _parse_person(self, line_number, row, col):
     "Parse the content of a Person line."
     surname = rd(line_number, row, col, "surname")
     firstname = rd(line_number, row, col, "firstname", "")
     callname = rd(line_number, row, col, "callname")
     title = rd(line_number, row, col, "title")
     prefix = rd(line_number, row, col, "prefix")
     suffix = rd(line_number, row, col, "suffix")
     gender = rd(line_number, row, col, "gender")
     source = rd(line_number, row, col, "source")
     note = rd(line_number, row, col, "note")
     birthplace = rd(line_number, row, col, "birthplace")
     birthplace_id = rd(line_number, row, col, "birthplace_id")
     birthdate = rd(line_number, row, col, "birthdate")
     birthsource = rd(line_number, row, col, "birthsource")
     baptismplace = rd(line_number, row, col, "baptismplace")
     baptismplace_id = rd(line_number, row, col, "baptismplace_id")
     baptismdate = rd(line_number, row, col, "baptismdate")
     baptismsource = rd(line_number, row, col, "baptismsource")
     burialplace = rd(line_number, row, col, "burialplace")
     burialplace_id = rd(line_number, row, col, "burialplace_id")
     burialdate = rd(line_number, row, col, "burialdate")
     burialsource = rd(line_number, row, col, "burialsource")
     deathplace = rd(line_number, row, col, "deathplace")
     deathplace_id = rd(line_number, row, col, "deathplace_id")
     deathdate = rd(line_number, row, col, "deathdate")
     deathsource = rd(line_number, row, col, "deathsource")
     deathcause = rd(line_number, row, col, "deathcause")
     grampsid = rd(line_number, row, col, "grampsid")
     person_ref = rd(line_number, row, col, "person")
     #########################################################
     # if this person already exists, don't create them
     person = self.lookup("person", person_ref)
     if person is None:
         if surname is None:
             LOG.warn("empty surname for new person on line %d" %
                      line_number)
             surname = ""
         # new person
         person = self.create_person()
         name = Name()
         name.set_type(NameType(NameType.BIRTH))
         name.set_first_name(firstname)
         surname_obj = Surname()
         surname_obj.set_surname(surname)
         name.add_surname(surname_obj)
         person.set_primary_name(name)
     else:
         name = person.get_primary_name()
     #########################################################
     if person_ref is not None:
         self.storeup("person", person_ref, person)
     # replace
     if surname is not None:
         name.get_primary_surname().set_surname(surname)
     if firstname is not None:
         name.set_first_name(firstname)
     if callname is not None:
         name.set_call_name(callname)
     if title is not None:
         name.set_title(title)
     if prefix is not None:
         name.get_primary_surname().set_prefix(prefix)
         name.group_as = ''  # HELP? what should I do here?
     if suffix is not None:
         name.set_suffix(suffix)
     if note is not None:
         # append notes, if previous notes
         previous_notes_list = person.get_note_list()
         updated_note = False
         for note_handle in previous_notes_list:
             previous_note = self.db.get_note_from_handle(note_handle)
             if previous_note.type == NoteType.PERSON:
                 previous_text = previous_note.get()
                 if note not in previous_text:
                     note = previous_text + "\n" + note
                 previous_note.set(note)
                 self.db.commit_note(previous_note, self.trans)
                 updated_note = True
                 break
         if not updated_note:
             # add new note here
             new_note = Note()
             new_note.handle = create_id()
             new_note.type.set(NoteType.PERSON)
             new_note.set(note)
             if self.default_tag:
                 new_note.add_tag(self.default_tag.handle)
             self.db.add_note(new_note, self.trans)
             person.add_note(new_note.handle)
     if grampsid is not None:
         person.gramps_id = grampsid
     elif person_ref is not None:
         if person_ref.startswith("[") and person_ref.endswith("]"):
             person.gramps_id = self.db.id2user_format(person_ref[1:-1])
     if (person.get_gender() == Person.UNKNOWN and gender is not None):
         gender = gender.lower()
         if gender == gender_map[Person.MALE].lower():
             gender = Person.MALE
         elif gender == gender_map[Person.FEMALE].lower():
             gender = Person.FEMALE
         else:
             gender = Person.UNKNOWN
         person.set_gender(gender)
     #########################################################
     # add if new, replace if different
     # Birth:
     if birthdate is not None:
         birthdate = _dp.parse(birthdate)
     if birthplace and birthplace_id:
         raise Error(
             "Error in person: can't have a birthplace and birthplace_id")
     if birthplace is not None:
         new, birthplace = self.get_or_create_place(birthplace)
     elif birthplace_id:
         # better exist already, locally or in database:
         birthplace = self.lookup("place", birthplace_id)
     if birthsource is not None:
         new, birthsource = self.get_or_create_source(birthsource)
     if birthdate or birthplace or birthsource:
         new, birth = self.get_or_create_event(person, EventType.BIRTH,
                                               birthdate, birthplace,
                                               birthsource)
         birth_ref = person.get_birth_ref()
         if birth_ref is None:
             # new
             birth_ref = EventRef()
         birth_ref.set_reference_handle(birth.get_handle())
         person.set_birth_ref(birth_ref)
     # Baptism:
     if baptismdate is not None:
         baptismdate = _dp.parse(baptismdate)
     if baptismplace and baptismplace_id:
         raise Error(
             "Error in person: can't have a baptismplace and baptismplace_id"
         )
     if baptismplace is not None:
         new, baptismplace = self.get_or_create_place(baptismplace)
     elif baptismplace_id:
         # better exist already, locally or in database:
         baptismplace = self.lookup("place", baptismplace_id)
     if baptismsource is not None:
         new, baptismsource = self.get_or_create_source(baptismsource)
     if baptismdate or baptismplace or baptismsource:
         new, baptism = self.get_or_create_event(person, EventType.BAPTISM,
                                                 baptismdate, baptismplace,
                                                 baptismsource)
         baptism_ref = get_primary_event_ref_from_type(
             self.db, person, "Baptism")
         if baptism_ref is None:
             # new
             baptism_ref = EventRef()
         baptism_ref.set_reference_handle(baptism.get_handle())
         person.add_event_ref(baptism_ref)
     # Death:
     if deathdate is not None:
         deathdate = _dp.parse(deathdate)
     if deathplace and deathplace_id:
         raise Error(
             "Error in person: can't have a deathplace and deathplace_id")
     if deathplace is not None:
         new, deathplace = self.get_or_create_place(deathplace)
     elif deathplace_id:
         # better exist already, locally or in database:
         deathplace = self.lookup("place", deathplace_id)
     if deathsource is not None:
         new, deathsource = self.get_or_create_source(deathsource)
     if deathdate or deathplace or deathsource or deathcause:
         new, death = self.get_or_create_event(person, EventType.DEATH,
                                               deathdate, deathplace,
                                               deathsource)
         if deathcause:
             death.set_description(deathcause)
             self.db.commit_event(death, self.trans)
         death_ref = person.get_death_ref()
         if death_ref is None:
             # new
             death_ref = EventRef()
         death_ref.set_reference_handle(death.get_handle())
         person.set_death_ref(death_ref)
     # Burial:
     if burialdate is not None:
         burialdate = _dp.parse(burialdate)
     if burialplace and burialplace_id:
         raise Error(
             "Error in person: can't have a burialplace and burialplace_id")
     if burialplace is not None:
         new, burialplace = self.get_or_create_place(burialplace)
     elif burialplace_id:
         # better exist already, locally or in database:
         burialplace = self.lookup("place", burialplace_id)
     if burialsource is not None:
         new, burialsource = self.get_or_create_source(burialsource)
     if burialdate or burialplace or burialsource:
         new, burial = self.get_or_create_event(person, EventType.BURIAL,
                                                burialdate, burialplace,
                                                burialsource)
         burial_ref = get_primary_event_ref_from_type(
             self.db, person, "Burial")
         if burial_ref is None:
             # new
             burial_ref = EventRef()
         burial_ref.set_reference_handle(burial.get_handle())
         person.add_event_ref(burial_ref)
     if source:
         # add, if new
         new, source = self.get_or_create_source(source)
         self.find_and_set_citation(person, source)
     self.db.commit_person(person, self.trans)
Exemple #27
0
 def latin_american(self):
     """
     Child inherits name from father and mother
     """
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     if self.family:
         father_handle = self.family.get_father_handle()
         mother_handle = self.family.get_mother_handle()
         father = self.dbstate.db.get_person_from_handle(father_handle)
         mother = self.dbstate.db.get_person_from_handle(mother_handle)
         if not father and not mother:
             return name
         if not father:
             preset_name(mother, name)
             return name
         if not mother:
             preset_name(father, name)
             return name
         #we take first surname, and keep that
         mothername = Name()
         preset_name(mother, mothername)
         preset_name(father, name)
         mothersurname = mothername.get_surname_list()[0]
         mothersurname.set_primary(False)
         name.set_surname_list([name.get_surname_list()[0], mothersurname])
         return name
     else:
         return name
Exemple #28
0
 def no_name(self):
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     return name
Exemple #29
0
    def latin_american_child(self, parent):
        """
        If SURNAME_GUESSING is latin american, then find a child
        and return their name for the father or mother.

        parent = "mother" | "father"
        """
        name = Name()
        #the editor requires a surname
        name.add_surname(Surname())
        name.set_primary_surname(0)
        # for each child, find one with a last name
        for ref in self.obj.get_child_ref_list():
            child = self.db.get_person_from_handle(ref.ref)
            if child:
                pname = child.get_primary_name()
                preset_name(child, name)
                if len(name.get_surname_list()) < 2:
                    return name
                else:
                    #return first for the father, and last for the mother
                    if parent == 'father':
                        name.set_surname_list(name.get_surname_list()[0])
                        return name
                    else:
                        name.set_surname_list(name.get_surname_list()[-1])
                        return name
        return name
Exemple #30
0
 def no_name(self):
     name = Name()
     #the editor requires a surname
     name.add_surname(Surname())
     name.set_primary_surname(0)
     return name
    def run_tool(self):
        self.progress = ProgressMeter(_('Running Date Test'),'',
                                        parent=self.parent_window)
        self.progress.set_pass(_('Generating dates'),
                               4)
        dates = []
        # first some valid dates
        calendar = Date.CAL_GREGORIAN
        for quality in (Date.QUAL_NONE, Date.QUAL_ESTIMATED,
                        Date.QUAL_CALCULATED):
            for modifier in (Date.MOD_NONE, Date.MOD_BEFORE,
                             Date.MOD_AFTER, Date.MOD_ABOUT):
                for slash1 in (False,True):
                    for month in range(0,13):
                        for day in (0,5,27):
                            if not month and day:
                                continue
                            d = Date()
                            d.set(quality,modifier,calendar,(day,month,1789,slash1),"Text comment")
                            dates.append( d)
            for modifier in (Date.MOD_RANGE, Date.MOD_SPAN):
                for slash1 in (False,True):
                    for slash2 in (False,True):
                        for month in range(0,13):
                            for day in (0,5,27):
                                if not month and day:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,day,month,1876,slash2),"Text comment")
                                dates.append( d)

                                if not month:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,day,13-month,1876,slash2),"Text comment")
                                dates.append( d)

                                if not day:
                                    continue

                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,month,1876,slash2),"Text comment")
                                dates.append( d)
                                d = Date()
                                d.set(quality,modifier,calendar,(day,month,1789,slash1,32-day,13-month,1876,slash2),"Text comment")
                                dates.append( d)
            modifier = Date.MOD_TEXTONLY
            d = Date()
            d.set(quality,modifier,calendar,Date.EMPTY,
                  "This is a textual date")
            dates.append( d)
            self.progress.step()
        
        # test invalid dates
        #dateval = (4,7,1789,False,5,8,1876,False)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #              Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #for l in range(1,len(dateval)):
        #    d = Date()
        #    try:
        #        d.set(Date.QUAL_NONE,Date.MOD_SPAN,Date.CAL_GREGORIAN,dateval[:l],"Text comment")
        #        dates.append( d)
        #    except DateError, e:
        #        d.set_as_text("Date identified value correctly as invalid.\n%s" % e)
        #        dates.append( d)
        #    except:
        #        d = Date()
        #        d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
        #        dates.append( d)
        #self.progress.step()
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_NONE,
        #      Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,55,8,1876,False),"Text comment")
        #dates.append( d)
        #d = Date()
        #d.set(Date.QUAL_NONE,Date.MOD_SPAN,
        #      Date.CAL_GREGORIAN,
        #      (4,7,1789,False,5,88,1876,False),"Text comment")
        #dates.append( d)
        
        with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
            self.db.disable_signals()
            self.progress.set_pass(_('Generating dates'),
                                   len(dates))

            # create pass and fail tags
            pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
            fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')

            # now add them as birth to new persons
            i = 1
            for dateval in dates:
                person = Person()
                surname = Surname()
                surname.set_surname("DateTest")
                name = Name()
                name.add_surname(surname)
                name.set_first_name("Test %d" % i)
                person.set_primary_name(name)
                self.db.add_person(person, self.trans)
                bevent = Event()
                bevent.set_type(EventType.BIRTH)
                bevent.set_date_object(dateval)
                bevent.set_description("Date Test %d (source)" % i)
                bevent_h = self.db.add_event(bevent, self.trans)
                bevent_ref = EventRef()
                bevent_ref.set_reference_handle(bevent_h)
                # for the death event display the date as text and parse it back to a new date
                ndate = None
                try:
                    datestr = _dd.display( dateval)
                    try:
                        ndate = _dp.parse( datestr)
                        if not ndate:
                            ndate = Date()
                            ndate.set_as_text("DateParser None")
                            person.add_tag(fail_handle)
                        else:
                            person.add_tag(pass_handle)
                    except:
                        ndate = Date()
                        ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
                        person.add_tag(fail_handle)
                    else:
                        person.add_tag(pass_handle)
                except:
                    ndate = Date()
                    ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
                    person.add_tag(fail_handle)
                
                if dateval.get_modifier() != Date.MOD_TEXTONLY \
                       and ndate.get_modifier() == Date.MOD_TEXTONLY:
                    # parser was unable to correctly parse the string
                    ndate.set_as_text( "TEXTONLY: "+ndate.get_text())
                    person.add_tag(fail_handle)
                if dateval.get_modifier() == Date.MOD_TEXTONLY \
                        and dateval.get_text().count("Traceback") \
                        and pass_handle in person.get_tag_list():
                    person.add_tag(fail_handle)
                
                devent = Event()
                devent.set_type(EventType.DEATH)
                devent.set_date_object(ndate)
                devent.set_description("Date Test %d (result)" % i)
                devent_h = self.db.add_event(devent, self.trans)
                devent_ref = EventRef()
                devent_ref.set_reference_handle(devent_h)
                person.set_birth_ref(bevent_ref)
                person.set_death_ref(devent_ref)
                self.db.commit_person(person, self.trans)
                i = i + 1
                self.progress.step()
        self.db.enable_signals()
        self.db.request_rebuild()
        self.progress.close()
Exemple #32
0
 def _parse_person(self, line_number, row, col):
     "Parse the content of a Person line."
     surname   = rd(line_number, row, col, "surname")
     firstname = rd(line_number, row, col, "firstname", "")
     callname  = rd(line_number, row, col, "callname")
     title     = rd(line_number, row, col, "title")
     prefix    = rd(line_number, row, col, "prefix")
     suffix    = rd(line_number, row, col, "suffix")
     gender    = rd(line_number, row, col, "gender")
     source    = rd(line_number, row, col, "source")
     note      = rd(line_number, row, col, "note")
     birthplace  = rd(line_number, row, col, "birthplace")
     birthplace_id  = rd(line_number, row, col, "birthplace_id")
     birthdate   = rd(line_number, row, col, "birthdate")
     birthsource = rd(line_number, row, col, "birthsource")
     baptismplace  = rd(line_number, row, col, "baptismplace")
     baptismplace_id  = rd(line_number, row, col, "baptismplace_id")
     baptismdate   = rd(line_number, row, col, "baptismdate")
     baptismsource = rd(line_number, row, col, "baptismsource")
     burialplace  = rd(line_number, row, col, "burialplace")
     burialplace_id  = rd(line_number, row, col, "burialplace_id")
     burialdate   = rd(line_number, row, col, "burialdate")
     burialsource = rd(line_number, row, col, "burialsource")
     deathplace  = rd(line_number, row, col, "deathplace")
     deathplace_id  = rd(line_number, row, col, "deathplace_id")
     deathdate   = rd(line_number, row, col, "deathdate")
     deathsource = rd(line_number, row, col, "deathsource")
     deathcause  = rd(line_number, row, col, "deathcause")
     grampsid    = rd(line_number, row, col, "grampsid")
     person_ref  = rd(line_number, row, col, "person")
     #########################################################
     # if this person already exists, don't create them
     person = self.lookup("person", person_ref)
     if person is None:
         if surname is None:
             LOG.warn("empty surname for new person on line %d" %
                      line_number)
             surname = ""
         # new person
         person = self.create_person()
         name = Name()
         name.set_type(NameType(NameType.BIRTH))
         name.set_first_name(firstname)
         surname_obj = Surname()
         surname_obj.set_surname(surname)
         name.add_surname(surname_obj)
         person.set_primary_name(name)
     else:
         name = person.get_primary_name()
     #########################################################
     if person_ref is not None:
         self.storeup("person", person_ref, person)
     # replace
     if surname is not None:
         name.get_primary_surname().set_surname(surname)
     if firstname is not None:
         name.set_first_name(firstname)
     if callname is not None:
         name.set_call_name(callname)
     if title is not None:
         name.set_title(title)
     if prefix is not None:
         name.get_primary_surname().set_prefix(prefix)
         name.group_as = '' # HELP? what should I do here?
     if suffix is not None:
         name.set_suffix(suffix)
     if note is not None:
         # append notes, if previous notes
         previous_notes_list = person.get_note_list()
         updated_note = False
         for note_handle in previous_notes_list:
             previous_note = self.db.get_note_from_handle(note_handle)
             if previous_note.type == NoteType.PERSON:
                 previous_text = previous_note.get()
                 if note not in previous_text:
                     note = previous_text + "\n" + note
                 previous_note.set(note)
                 self.db.commit_note(previous_note, self.trans)
                 updated_note = True
                 break
         if not updated_note:
             # add new note here
             new_note = Note()
             new_note.handle = create_id()
             new_note.type.set(NoteType.PERSON)
             new_note.set(note)
             if self.default_tag:
                 new_note.add_tag(self.default_tag.handle)
             self.db.add_note(new_note, self.trans)
             person.add_note(new_note.handle)
     if grampsid is not None:
         person.gramps_id = grampsid
     elif person_ref is not None:
         if person_ref.startswith("[") and person_ref.endswith("]"):
             person.gramps_id = self.db.id2user_format(person_ref[1:-1])
     if (person.get_gender() == Person.UNKNOWN and
             gender is not None):
         gender = gender.lower()
         if gender == gender_map[Person.MALE].lower():
             gender = Person.MALE
         elif gender == gender_map[Person.FEMALE].lower():
             gender = Person.FEMALE
         else:
             gender = Person.UNKNOWN
         person.set_gender(gender)
     #########################################################
     # add if new, replace if different
     # Birth:
     if birthdate is not None:
         birthdate = _dp.parse(birthdate)
     if birthplace and birthplace_id:
         raise Error("Error in person: can't have a birthplace and birthplace_id")
     if birthplace is not None:
         new, birthplace = self.get_or_create_place(birthplace)
     elif birthplace_id:
         # better exist already, locally or in database:
         birthplace = self.lookup("place", birthplace_id)
     if birthsource is not None:
         new, birthsource = self.get_or_create_source(birthsource)
     if birthdate or birthplace or birthsource:
         new, birth = self.get_or_create_event(person,
              EventType.BIRTH, birthdate,
              birthplace, birthsource)
         birth_ref = person.get_birth_ref()
         if birth_ref is None:
             # new
             birth_ref = EventRef()
         birth_ref.set_reference_handle( birth.get_handle())
         person.set_birth_ref( birth_ref)
     # Baptism:
     if baptismdate is not None:
         baptismdate = _dp.parse(baptismdate)
     if baptismplace and baptismplace_id:
         raise Error("Error in person: can't have a baptismplace and baptismplace_id")
     if baptismplace is not None:
         new, baptismplace = self.get_or_create_place(baptismplace)
     elif baptismplace_id:
         # better exist already, locally or in database:
         baptismplace = self.lookup("place", baptismplace_id)
     if baptismsource is not None:
         new, baptismsource = self.get_or_create_source(baptismsource)
     if baptismdate or baptismplace or baptismsource:
         new, baptism = self.get_or_create_event(person,
              EventType.BAPTISM, baptismdate,
              baptismplace, baptismsource)
         baptism_ref = get_primary_event_ref_from_type(self.db, person,
                                                       "Baptism")
         if baptism_ref is None:
             # new
             baptism_ref = EventRef()
         baptism_ref.set_reference_handle( baptism.get_handle())
         person.add_event_ref( baptism_ref)
     # Death:
     if deathdate is not None:
         deathdate = _dp.parse(deathdate)
     if deathplace and deathplace_id:
         raise Error("Error in person: can't have a deathplace and deathplace_id")
     if deathplace is not None:
         new, deathplace = self.get_or_create_place(deathplace)
     elif deathplace_id:
         # better exist already, locally or in database:
         deathplace = self.lookup("place", deathplace_id)
     if deathsource is not None:
         new, deathsource = self.get_or_create_source(deathsource)
     if deathdate or deathplace or deathsource or deathcause:
         new, death = self.get_or_create_event(person,
                 EventType.DEATH, deathdate, deathplace,
                 deathsource)
         if deathcause:
             death.set_description(deathcause)
             self.db.commit_event(death, self.trans)
         death_ref = person.get_death_ref()
         if death_ref is None:
             # new
             death_ref = EventRef()
         death_ref.set_reference_handle(death.get_handle())
         person.set_death_ref(death_ref)
     # Burial:
     if burialdate is not None:
         burialdate = _dp.parse(burialdate)
     if burialplace and burialplace_id:
         raise Error("Error in person: can't have a burialplace and burialplace_id")
     if burialplace is not None:
         new, burialplace = self.get_or_create_place(burialplace)
     elif burialplace_id:
         # better exist already, locally or in database:
         burialplace = self.lookup("place", burialplace_id)
     if burialsource is not None:
         new, burialsource = self.get_or_create_source(burialsource)
     if burialdate or burialplace or burialsource:
         new, burial = self.get_or_create_event(person,
              EventType.BURIAL, burialdate,
              burialplace, burialsource)
         burial_ref = get_primary_event_ref_from_type(self.db, person,
                                                      "Burial")
         if burial_ref is None:
             # new
             burial_ref = EventRef()
         burial_ref.set_reference_handle( burial.get_handle())
         person.add_event_ref( burial_ref)
     if source:
         # add, if new
         new, source = self.get_or_create_source(source)
         self.find_and_set_citation(person, source)
     self.db.commit_person(person, self.trans)