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))