Exemple #1
0
    def read_relation_lines(self):
        if not self.current_relationship_person_handle:
            LOG.warning("Unknown person for relationship in line %d!" % self.lineno)
            return None
        rel_person = self.db.get_person_from_handle(self.current_relationship_person_handle)
        while 1:
            line = self.get_next_line()
            if line is None or line == "end":
                break
            if line == "":
                continue

            # match relationship type and related person
            line_re = re.compile("^- ([^:]+): (.*)$")
            matches = line_re.match(line)
            if matches:
                #split related person into fields
                fields = matches.groups()[1].split(" ")
                if fields:
                    (idx,asso_p) = self.parse_person(fields,0,Person.UNKNOWN,None)
                    pref = PersonRef()
                    pref.set_relation(matches.groups()[0])
                    LOG.warning("TODO: Handle association types properly")
                    pref.set_reference_handle(asso_p.get_handle())
                    rel_person.add_person_ref(pref)
                    self.db.commit_person(rel_person,self.trans)
                else:
                    LOG.warning("Invalid name of person in line %d" % self.lineno)
            else:
                LOG.warning("Invalid relationship in line %d" % self.lineno)
                break
        self.current_mode = None
        return None
Exemple #2
0
    def read_relation_lines(self):
        if not self.current_relationship_person_handle:
            LOG.warning("Unknown person for relationship in line %d!" % self.lineno)
            return None
        rel_person = self.db.get_person_from_handle(self.current_relationship_person_handle)
        while 1:
            line = self.get_next_line()
            if line is None or line == "end":
                break
            if line == "":
                continue

            # match relationship type and related person
            line_re = re.compile("^- ([^:]+): (.*)$")
            matches = line_re.match(line)
            if matches:
                #split related person into fields
                fields = matches.groups()[1].split(" ")
                if fields:
                    (idx,asso_p) = self.parse_person(fields,0,Person.UNKNOWN,None)
                    pref = PersonRef()
                    pref.set_relation(matches.groups()[0])
                    LOG.warning("TODO: Handle association types properly")
                    pref.set_reference_handle(asso_p.get_handle())
                    rel_person.add_person_ref(pref)
                    self.db.commit_person(rel_person,self.trans)
                else:
                    LOG.warning("Invalid name of person in line %d" % self.lineno)
            else:
                LOG.warning("Invalid relationship in line %d" % self.lineno)
                break
        self.current_mode = None
        return None
Exemple #3
0
 def __init__(self, dbstate, user, options_class, name, callback=None):
     uistate = user.uistate
     self.dbstate = dbstate
     self.db = dbstate.db
     count = 0
     has_assoc = False
     for person_handle in self.db.get_person_handles():
         person = self.db.get_person_from_handle(person_handle)
         for assoc in person.get_person_ref_list():
             has_assoc = True
             oldRel = assoc.get_relation()
             if oldRel in ASSOC_LOOKUP:
                 associate = self.db.get_person_from_handle(assoc.ref)
                 update = True
                 for assoc_rev in associate.get_person_ref_list():
                     if assoc_rev.get_relation() == ASSOC_LOOKUP.get(
                             assoc.get_relation(
                             )) and assoc_rev.ref == person_handle:
                         update = False
                 if update:
                     newRel = ASSOC_LOOKUP.get(assoc.get_relation())
                     personRef = PersonRef()
                     personRef.set_reference_handle(person_handle)
                     personRef.set_relation(newRel)
                     personRef.merge(assoc)
                     with DbTxn(
                             _('Add %s reciprocal association') %
                             _nd.display(associate), self.db) as self.trans:
                         associate.add_person_ref(personRef)
                         self.db.commit_person(associate, self.trans)
                     count += 1
     if uistate:
         if count > 0:
             OkDialog(_("Sync Associations"),
                      _("{} Reciprocal associations created".format(count)),
                      parent=uistate.window)
         elif has_assoc:
             OkDialog(_("Sync Associations"),
                      _("All reciprocal associations exist, none created"),
                      parent=uistate.window)
         else:
             OkDialog(
                 _("Sync Associations"),
                 _("No existing associations, so no reciprocal ones needed"
                   ),
                 parent=uistate.window)
     else:
         print("{} Reciprocal associations created".format(count))