def add_note(self, note, trans, set_gid=True): if not note.handle: note.handle = create_id() if not note.gramps_id and set_gid: note.gramps_id = self.find_next_note_gramps_id() self.commit_note(note, trans) return note.handle
def add_place(self, place, trans, set_gid=True): if not place.handle: place.handle = create_id() if not place.gramps_id and set_gid: place.gramps_id = self.find_next_place_gramps_id() self.commit_place(place, trans) return place.handle
def add_source(self, source, trans, set_gid=True): if not source.handle: source.handle = create_id() if not source.gramps_id and set_gid: source.gramps_id = self.find_next_source_gramps_id() self.commit_source(source, trans) return source.handle
def create_event(self, description=_("Estimated date"), type=None, date=None, source=None, note_text="", modifier=None): event = Event() event.set_description(description) note = Note() note.handle = create_id() note.type.set(NoteType.EVENT) note.set(note_text) self.db.add_note(note, self.trans) event.add_note(note.handle) if type: event.set_type(EventType(type)) if date: if modifier: date.set_modifier(modifier) date.set_quality(Date.QUAL_ESTIMATED) date.set_yr_mon_day(date.get_year(), 0, 0) event.set_date_object(date) if source: citation = Citation() citation.set_reference_handle(source.get_handle()) self.db.add_citation(citation, self.trans) event.add_citation(citation.get_handle()) self.db.commit_source(source, self.trans) self.db.add_event(event, self.trans) return event
def export_date(db, from_type, from_handle, data): if data is None: return (calendar, modifier, quality, dateval, text, sortval, newyear) = data if len(dateval) == 4: day1, month1, year1, slash1 = dateval day2, month2, year2, slash2 = 0, 0, 0, 0 elif len(dateval) == 8: day1, month1, year1, slash1, day2, month2, year2, slash2 = dateval else: raise ("ERROR: date dateval format", dateval) date_handle = create_id() db.query("""INSERT INTO date ( handle, calendar, modifier, quality, day1, month1, year1, slash1, day2, month2, year2, slash2, text, sortval, newyear) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""", date_handle, calendar, modifier, quality, day1, month1, year1, slash1, day2, month2, year2, slash2, text, sortval, newyear) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "date", date_handle)
def add_citation(self, citation, trans, set_gid=True): if not citation.handle: citation.handle = create_id() if not citation.gramps_id and set_gid: citation.gramps_id = self.find_next_citation_gramps_id() self.commit_citation(citation, trans) return citation.handle
def export_location(db, from_type, from_handle, location): if location == None: return if len(location) == 8: (street, locality, city, county, state, country, postal, phone) = location parish = None elif len(location) == 2: ((street, locality, city, county, state, country, postal, phone), parish) = location else: print("ERROR: what kind of location is this?", location) return handle = create_id() db.query("""INSERT INTO location ( handle, street, locality, city, county, state, country, postal, phone, parish) VALUES (?,?,?,?,?,?,?,?,?,?);""", handle, street, locality, city, county, state, country, postal, phone, parish) # finally, link the parent to the address export_link(db, from_type, from_handle, "location", handle)
def export_date(db, from_type, from_handle, data): if data is None: return (calendar, modifier, quality, dateval, text, sortval, newyear) = data if len(dateval) == 4: day1, month1, year1, slash1 = dateval day2, month2, year2, slash2 = 0, 0, 0, 0 elif len(dateval) == 8: day1, month1, year1, slash1, day2, month2, year2, slash2 = dateval else: raise ("ERROR: date dateval format", dateval) date_handle = create_id() db.query( """INSERT INTO date ( handle, calendar, modifier, quality, day1, month1, year1, slash1, day2, month2, year2, slash2, text, sortval, newyear) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""", date_handle, calendar, modifier, quality, day1, month1, year1, slash1, day2, month2, year2, slash2, text, sortval, newyear) export_link(db, from_type, from_handle, "date", date_handle)
def _local_init(self): """ Performs basic initialization, including setting up widgets and the glade interface. Local initialization function. This is called by the base class of EditPrimary, and overridden here. """ self.width_key = "interface.person-width" self.height_key = "interface.person-height" self.pname = self.obj.get_primary_name() self.should_guess_gender = not self.obj.get_gramps_id() and self.obj.get_gender() == Person.UNKNOWN self.added = self.obj.handle is None if self.added: self.obj.handle = create_id() self.top = Glade() self.set_window(self.top.toplevel, None, self.get_menu_title()) self.obj_photo = self.top.get_object("personPix") self.frame_photo = self.top.get_object("frame5") self.eventbox = self.top.get_object("eventbox1") self.singsurnfr = SingSurn(self.top) self.multsurnfr = self.top.get_object("hboxmultsurnames") self.singlesurn_active = True self.surntab = SurnameTab( self.dbstate, self.uistate, self.track, self.obj.get_primary_name(), on_change=self._changed_name ) self.set_contexteventbox(self.top.get_object("eventboxtop"))
def export_place_ref(db, handle, place_ref): (to_place_handle, date) = place_ref ref_handle = create_id() db.query("insert into place_ref" " (handle, from_place_handle, to_place_handle) VALUES (?, ?, ?);", ref_handle, handle, to_place_handle) export_date(db, "place_ref", ref_handle, date)
def export_place_name(db, handle, place_name): # alt_place_name_list = [('Ohio', None, ''), ...] [(value, date, lang)...] (value, date, lang) = place_name ref_handle = create_id() db.query("insert into place_name (handle, from_handle, value, lang)" " VALUES (?, ?, ?, ?);", ref_handle, handle, value, lang) export_date(db, "place_name", ref_handle, date)
def export_name(db, from_type, from_handle, primary, data): if data: (private, citation_list, note_list, date, first_name, surname_list, suffix, title, name_type, group_as, sort_as, display_as, call, nick, famnick) = data handle = create_id() db.query( """INSERT into name ( handle, primary_name, private, first_name, suffix, title, name_type0, name_type1, group_as, sort_as, display_as, call, nick, famnick ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""", handle, primary, private, first_name, suffix, title, name_type[0], name_type[1], group_as, sort_as, display_as, call, nick, famnick) export_surname(db, handle, surname_list) export_date(db, "name", handle, date) export_list(db, "name", handle, "note", note_list) export_citation_list(db, "name", handle, citation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "name", handle)
def add_event(self, event, trans, set_gid=True): if not event.handle: event.handle = create_id() if not event.gramps_id and set_gid: event.gramps_id = self.find_next_event_gramps_id() self.commit_event(event, trans) return event.handle
def add_person(self, person, trans, set_gid=True): if not person.handle: person.handle = create_id() if not person.gramps_id and set_gid: person.gramps_id = self.find_next_person_gramps_id() self.commit_person(person, trans) return person.handle
def export_name(db, from_type, from_handle, primary, data): if data: (private, citation_list, note_list, date, first_name, surname_list, suffix, title, name_type, group_as, sort_as, display_as, call, nick, famnick) = data handle = create_id() db.query("""INSERT into name ( handle, primary_name, private, first_name, suffix, title, name_type0, name_type1, group_as, sort_as, display_as, call, nick, famnick ) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);""", handle, primary, private, first_name, suffix, title, name_type[0], name_type[1], group_as, sort_as, display_as, call, nick, famnick) export_surname(db, handle, surname_list) export_date(db, "name", handle, date) export_list(db, "name", handle, "note", note_list) export_citation_list(db, "name", handle, citation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "name", handle)
def add_family(self, family, trans, set_gid=True): if not family.handle: family.handle = create_id() if not family.gramps_id and set_gid: family.gramps_id = self.find_next_family_gramps_id() self.commit_family(family, trans) return family.handle
def add_object( db_handle: DbWriteBase, obj: GrampsObject, trans: DbTxn, fail_if_exists: bool = False, ): """Commit a Gramps object to the database. If `fail_if_exists` is true, raises a ValueError if an object of the same type exists with the same handle or same Gramps ID. In the case of a family object, also updates the referenced handles in the corresponding person objects. """ if db_handle.readonly: # adding objects is forbidden on a read-only db! abort(HTTPStatus.FORBIDDEN) obj_class = obj.__class__.__name__.lower() if fail_if_exists: if has_handle(db_handle, obj): raise ValueError("Handle already exists.") if has_gramps_id(db_handle, obj): raise ValueError("Gramps ID already exists.") try: add_method = db_handle.method("add_%s", obj_class) if obj_class == "family": # need to add handle if not present yet! if not obj.handle: obj.handle = create_id() add_family_update_refs(db_handle=db_handle, obj=obj, trans=trans) return add_method(obj, trans) except AttributeError: raise ValueError("Database does not support writing.")
def add_repository(self, repository, trans, set_gid=True): if not repository.handle: repository.handle = create_id() if not repository.gramps_id and set_gid: repository.gramps_id = self.find_next_repository_gramps_id() self.commit_repository(repository, trans) return repository.handle
def _local_init(self): """ Performs basic initialization, including setting up widgets and the glade interface. Local initialization function. This is called by the base class of EditPrimary, and overridden here. """ self.pname = self.obj.get_primary_name() self.should_guess_gender = (not self.obj.get_gramps_id() and self.obj.get_gender () == Person.UNKNOWN) self.added = self.obj.handle is None if self.added: self.obj.handle = create_id() self.top = Glade() self.set_window(self.top.toplevel, None, self.get_menu_title()) self.setup_configs('interface.person', 750, 550) self.obj_photo = self.top.get_object("personPix") self.frame_photo = self.top.get_object("frame5") self.eventbox = self.top.get_object("eventbox1") self.singsurnfr = SingSurn(self.top) self.multsurnfr = self.top.get_object("hboxmultsurnames") self.singlesurn_active = True self.set_contexteventbox(self.top.get_object("eventboxtop"))
def export_location(db, from_type, from_handle, location): if location == None: return if len(location) == 8: (street, locality, city, county, state, country, postal, phone) = location parish = None elif len(location) == 2: ((street, locality, city, county, state, country, postal, phone), parish) = location else: print("ERROR: what kind of location is this?", location) return handle = create_id() db.query( """INSERT INTO location ( handle, street, locality, city, county, state, country, postal, phone, parish) VALUES (?,?,?,?,?,?,?,?,?,?);""", handle, street, locality, city, county, state, country, postal, phone, parish) # finally, link the parent to the address export_link(db, from_type, from_handle, "location", handle)
def _local_init(self): self.added = self.obj.handle is None if self.added: self.obj.handle = create_id() self.build_interface() self.load_data()
def export_place_ref(db, handle, place_ref): (to_place_handle, date) = place_ref ref_handle = create_id() db.query("""insert into place_ref (handle, from_place_handle, to_place_handle) VALUES (?, ?, ?) ;""", ref_handle, handle, to_place_handle) export_date(db, "place_ref", ref_handle, date)
def export_place_name(db, handle, place_name): # alt_place_name_list = [('Ohio', None, ''), ...] [(value, date, lang)...] (value, date, lang) = place_name ref_handle = create_id() db.query("""insert into place_name (handle, from_handle, value, lang) VALUES (?, ?, ?, ?) ;""", ref_handle, handle, value, lang) export_date(db, "place_name", ref_handle, date)
def buildTag(self, tname, thandle=None): if thandle == None: thandle = id.create_id() # 26-merkkinen tunniste tag = Tag() tag.set_name(tname) tag.set_change_time(self.chgtime) # tag.set_color("#EF2929") tag.set_handle(thandle) # print ("Tag ") ; print(tag.to_struct()) return ([tag, thandle])
def export_datamap_dict(db, from_type, from_handle, datamap): for key_field in datamap: handle = create_id() value_field = datamap[key_field] db.query("""INSERT INTO datamap ( handle, key_field, value_field) values (?, ?, ?)""", handle, key_field, value_field) export_link(db, from_type, from_handle, "datamap", handle)
def export_address(db, from_type, from_handle, address): (private, acitation_list, anote_list, date, location) = address addr_handle = create_id() db.query("""INSERT INTO address ( handle, private) VALUES (?, ?);""", addr_handle, private) export_location(db, "address", addr_handle, location) export_date(db, "address", addr_handle, date) export_list(db, "address", addr_handle, "note", anote_list) export_citation_list(db, "address", addr_handle, acitation_list) # finally, link the parent to the address export_link(db, from_type, from_handle, "address", addr_handle)
def add_object(self, obj, transaction, set_gid=True): """ Add a MediaObject to the database, assigning internal IDs if they have not already been defined. If not set_gid, then gramps_id is not set. """ if not obj.handle: obj.handle = create_id() if not obj.gramps_id and set_gid: obj.gramps_id = self.find_next_object_gramps_id() self.commit_media_object(obj, transaction) return obj.handle
def export_markup(db, from_type, from_handle, markup_code0, markup_code1, value, start_stop_list): markup_handle = create_id() db.query( """INSERT INTO markup ( handle, markup0, markup1, value, start_stop_list) VALUES (?,?,?,?,?);""", markup_handle, markup_code0, markup_code1, value, start_stop_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "markup", markup_handle)
def export_markup(db, from_type, from_handle, markup_code0, markup_code1, value, start_stop_list): markup_handle = create_id() db.query("""INSERT INTO markup ( handle, markup0, markup1, value, start_stop_list) VALUES (?,?,?,?,?);""", markup_handle, markup_code0, markup_code1, value, start_stop_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "markup", markup_handle)
def export_lds(db, from_type, from_handle, data): (lcitation_list, lnote_list, date, type, place, famc, temple, status, private) = data lds_handle = create_id() db.query("""INSERT into lds (handle, type, place, famc, temple, status, private) VALUES (?,?,?,?,?,?,?);""", lds_handle, type, place, famc, temple, status, private) export_link(db, "lds", lds_handle, "place", place) export_list(db, "lds", lds_handle, "note", lnote_list) export_date(db, "lds", lds_handle, date) export_citation_list(db, "lds", lds_handle, lcitation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "lds", lds_handle)
def export_attribute(db, from_type, from_handle, attribute): (private, citation_list, note_list, the_type, value) = attribute handle = create_id() db.query("""INSERT INTO attribute ( handle, the_type0, the_type1, value, private) VALUES (?,?,?,?,?);""", handle, the_type[0], the_type[1], value, private) export_citation_list(db, "attribute", handle, citation_list) export_list(db, "attribute", handle, "note", note_list) # finally, link the parent to the address export_link(db, from_type, from_handle, "attribute", handle)
def export_lds(db, from_type, from_handle, data): (lcitation_list, lnote_list, date, type, place, famc, temple, status, private) = data lds_handle = create_id() db.query( """INSERT into lds (handle, type, place, famc, temple, status, private) VALUES (?,?,?,?,?,?,?);""", lds_handle, type, place, famc, temple, status, private) export_link(db, "lds", lds_handle, "place", place) export_list(db, "lds", lds_handle, "note", lnote_list) export_date(db, "lds", lds_handle, date) export_citation_list(db, "lds", lds_handle, lcitation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "lds", lds_handle)
def export_child_ref_list(db, from_type, from_handle, to_type, ref_list): for child_ref in ref_list: # family -> child_ref # (False, [], [], u'b305e96e39652d8f08c', (1, u''), (1, u'')) (private, citation_list, note_list, ref, frel, mrel) = child_ref handle = create_id() db.query( """INSERT INTO child_ref (handle, ref, frel0, frel1, mrel0, mrel1, private) VALUES (?, ?, ?, ?, ?, ?, ?);""", handle, ref, frel[0], frel[1], mrel[0], mrel[1], private) export_citation_list(db, "child_ref", handle, citation_list) export_list(db, "child_ref", handle, "note", note_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "child_ref", handle)
def export_surname(db, name_handle, surname_list): for data in surname_list: surname_handle = create_id() (surname, prefix, primary, origin_type, connector) = data db.query("""INSERT INTO surname ( handle, surname, prefix, primary_surname, origin_type0, origin_type1, connector) VALUES (?,?,?,?,?,?,?);""", surname_handle, surname, prefix, primary, origin_type[0], origin_type[1], connector) export_link(db, "name", name_handle, "surname", surname_handle)
def export_child_ref_list(db, from_type, from_handle, to_type, ref_list): for child_ref in ref_list: # family -> child_ref # (False, [], [], u'b305e96e39652d8f08c', (1, u''), (1, u'')) (private, citation_list, note_list, ref, frel, mrel) = child_ref handle = create_id() db.query("""INSERT INTO child_ref (handle, ref, frel0, frel1, mrel0, mrel1, private) VALUES (?, ?, ?, ?, ?, ?, ?);""", handle, ref, frel[0], frel[1], mrel[0], mrel[1], private) export_citation_list(db, "child_ref", handle, citation_list) export_list(db, "child_ref", handle, "note", note_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "child_ref", handle)
def export_person_ref_list(db, from_type, from_handle, person_ref_list): for person_ref in person_ref_list: (private, citation_list, note_list, handle, desc) = person_ref ref_handle = create_id() db.query( """INSERT INTO person_ref ( handle, ref, description, private) VALUES (?, ?, ?, ?);""", ref_handle, handle, desc, private) export_list(db, "person_ref", ref_handle, "note", note_list) export_citation_list(db, "person_ref", ref_handle, citation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "person_ref", ref_handle)
def export_event_ref(db, from_type, from_handle, event_ref): (private, note_list, attribute_list, ref, role) = event_ref handle = create_id() db.query( """insert INTO event_ref ( handle, ref, role0, role1, private) VALUES (?,?,?,?,?);""", handle, ref, role[0], role[1], private) export_list(db, "event_ref", handle, "note", note_list) export_attribute_list(db, "event_ref", handle, attribute_list) # finally, link this to parent export_link(db, from_type, from_handle, "event_ref", handle)
def buildRepository(self, ridno, rname, tag, rtype, rhandle=None): if rhandle == None: rhandle = id.create_id() # 26-merkkinen tunniste repositoryType = RepositoryType() repositoryType.set(rtype) repository = Repository() repository.set_type(repositoryType) repository.set_handle(rhandle) repository.set_gramps_id(ridno) repository.set_name(rname) repository.set_change_time(self.chgtime) # repository.set_color("#000000") repository.add_tag(tag.get_handle()) # print ("Repository ") ; print(repository.to_struct()) return ([repository, rhandle])
def export_url_list(db, from_type, from_handle, urls): for url in urls: # (False, u'http://www.gramps-project.org/', u'loleach', (0, u'kaabgo')) (private, path, desc, type) = url handle = create_id() db.query( """insert INTO url ( handle, path, desc, type0, type1, private) VALUES (?, ?, ?, ?, ?, ?); """, handle, path, desc, type[0], type[1], private) # finally, link this to parent export_link(db, from_type, from_handle, "url", handle)
def export_repository_ref_list(db, from_type, from_handle, reporef_list): for repo in reporef_list: (note_list, ref, call_number, source_media_type, private) = repo handle = create_id() db.query( """insert INTO repository_ref ( handle, ref, call_number, source_media_type0, source_media_type1, private) VALUES (?,?,?,?,?,?);""", handle, ref, call_number, source_media_type[0], source_media_type[1], private) export_list(db, "repository_ref", handle, "note", note_list) # finally, link this to parent export_link(db, from_type, from_handle, "repository_ref", handle)
def get_or_create_family(self, family_ref, husband, wife): "Return the family object for the give family ID." # if a gramps_id and exists: LOG.debug("get_or_create_family") if family_ref.startswith("[") and family_ref.endswith("]"): id_ = self.db.fid2user_format(family_ref[1:-1]) family = self.db.get_family_from_gramps_id(id_) if family: # don't delete, only add fam_husband_handle = family.get_father_handle() fam_wife_handle = family.get_mother_handle() if husband: if husband.get_handle() != fam_husband_handle: # this husband is not the same old one! Add him! family.set_father_handle(husband.get_handle()) if wife: if wife.get_handle() != fam_wife_handle: # this wife is not the same old one! Add her! family.set_mother_handle(wife.get_handle()) LOG.debug(" returning existing family") return family # if not, create one: family = Family() # was marked with a gramps_id, but didn't exist, so we'll use it: if family_ref.startswith("[") and family_ref.endswith("]"): id_ = self.db.fid2user_format(family_ref[1:-1]) family.set_gramps_id(id_) # add it: family.set_handle(create_id()) if self.default_tag: family.add_tag(self.default_tag.handle) if husband: family.set_father_handle(husband.get_handle()) husband.add_family_handle(family.get_handle()) if wife: family.set_mother_handle(wife.get_handle()) wife.add_family_handle(family.get_handle()) if husband and wife: family.set_relationship(FamilyRelType.MARRIED) self.db.add_family(family, self.trans) if husband: self.db.commit_person(husband, self.trans) if wife: self.db.commit_person(wife, self.trans) self.fam_count += 1 return family
def export_event_ref(db, from_type, from_handle, event_ref): (private, note_list, attribute_list, ref, role) = event_ref handle = create_id() db.query("""insert INTO event_ref ( handle, ref, role0, role1, private) VALUES (?,?,?,?,?);""", handle, ref, role[0], role[1], private) export_list(db, "event_ref", handle, "note", note_list) export_attribute_list(db, "event_ref", handle, attribute_list) # finally, link this to parent export_link(db, from_type, from_handle, "event_ref", handle)
def export_url_list(db, from_type, from_handle, urls): for url in urls: # (False, u'http://www.gramps-project.org/', u'loleach', (0, u'kaabgo')) (private, path, desc, type) = url handle = create_id() db.query("""insert INTO url ( handle, path, desc, type0, type1, private) VALUES (?, ?, ?, ?, ?, ?); """, handle, path, desc, type[0], type[1], private) # finally, link this to parent export_link(db, from_type, from_handle, "url", handle)
def export_media_ref(db, from_type, from_handle, media): (private, citation_list, note_list, attribute_list, ref, role) = media # handle is the media_ref handle # ref is the media handle handle = create_id() if role is None: role = (-1, -1, -1, -1) db.query("""INSERT into media_ref ( handle, ref, role0, role1, role2, role3, private) VALUES (?,?,?,?,?,?,?);""", handle, ref, role[0], role[1], role[2], role[3], private) export_list(db, "media_ref", handle, "note", note_list) export_attribute_list(db, "media_ref", handle, attribute_list) export_citation_list(db, "media_ref", handle, citation_list) # And finally, make a link from parent to new object export_link(db, from_type, from_handle, "media_ref", handle)
def export_repository_ref_list(db, from_type, from_handle, reporef_list): for repo in reporef_list: (note_list, ref, call_number, source_media_type, private) = repo handle = create_id() db.query("""insert INTO repository_ref ( handle, ref, call_number, source_media_type0, source_media_type1, private) VALUES (?,?,?,?,?,?);""", handle, ref, call_number, source_media_type[0], source_media_type[1], private) export_list(db, "repository_ref", handle, "note", note_list) # finally, link this to parent export_link(db, from_type, from_handle, "repository_ref", handle)
def _parse_family(self, line_number, row, col): "Parse the content of a family line" family_ref = rd(line_number, row, col, "family") if family_ref is None: LOG.warn("no family reference found for family on line %d" % line_number) return # required child = rd(line_number, row, col, "child") source = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") gender = rd(line_number, row, col, "gender") child = self.lookup("person", child) family = self.lookup("family", family_ref) if family is None: LOG.warn("no matching family reference found for family " "on line %d" % line_number) return if child is None: LOG.warn("no matching child reference found for family " "on line %d" % line_number) return # is this child already in this family? If so, don't add LOG.debug("children: %s", [ref.ref for ref in family.get_child_ref_list()]) LOG.debug("looking for: %s", child.get_handle()) if child.get_handle() not in [ref.ref for ref in family.get_child_ref_list()]: # add child to family LOG.debug(" adding child [%s] to family [%s]", child.get_gramps_id(), family.get_gramps_id()) childref = ChildRef() childref.set_reference_handle(child.get_handle()) family.add_child_ref( childref) self.db.commit_family(family, self.trans) child.add_parent_family_handle(family.get_handle()) if gender: # replace 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 child.set_gender(gender) if source: # add, if new dummy_new, source = self.get_or_create_source(source) self.find_and_set_citation(child, source) # put note on child if note: # append notes, if previous notes previous_notes_list = child.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) child.add_note(new_note.handle) self.db.commit_person(child, self.trans)
def _parse_marriage(self, line_number, row, col): "Parse the content of a Marriage,Husband,Wife line." marriage_ref = rd(line_number, row, col, "marriage") husband = rd(line_number, row, col, "husband") wife = rd(line_number, row, col, "wife") marriagedate = rd(line_number, row, col, "date") marriageplace = rd(line_number, row, col, "place") marriageplace_id = rd(line_number, row, col, "place_id") marriagesource = rd(line_number, row, col, "source") note = rd(line_number, row, col, "note") wife = self.lookup("person", wife) husband = self.lookup("person", husband) if husband is None and wife is None: # might have children, so go ahead and add LOG.warn("no parents on line %d; adding family anyway" % line_number) family = self.get_or_create_family(marriage_ref, husband, wife) # adjust gender, if not already provided if husband: # this is just a guess, if unknown if husband.get_gender() == Person.UNKNOWN: husband.set_gender(Person.MALE) self.db.commit_person(husband, self.trans) if wife: # this is just a guess, if unknown if wife.get_gender() == Person.UNKNOWN: wife.set_gender(Person.FEMALE) self.db.commit_person(wife, self.trans) if marriage_ref: self.storeup("family", marriage_ref.lower(), family) if marriagesource: # add, if new new, marriagesource = self.get_or_create_source(marriagesource) if marriageplace and marriageplace_id: raise Error("Error in marriage: can't have a place and place_id") if marriageplace: # add, if new new, marriageplace = self.get_or_create_place(marriageplace) elif marriageplace_id: # better exist already, locally or in database: marriageplace = self.lookup("place", marriageplace_id) if marriagedate: marriagedate = _dp.parse(marriagedate) if marriagedate or marriageplace or marriagesource or note: # add, if new; replace, if different new, marriage = self.get_or_create_event(family, EventType.MARRIAGE, marriagedate, marriageplace, marriagesource) if new: mar_ref = EventRef() mar_ref.set_reference_handle(marriage.get_handle()) family.add_event_ref(mar_ref) self.db.commit_family(family, self.trans) # only add note to event: # append notes, if previous notes if note: previous_notes_list = marriage.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.EVENT: 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.EVENT) new_note.set(note) if self.default_tag: new_note.add_tag(self.default_tag.handle) self.db.add_note(new_note, self.trans) marriage.add_note(new_note.handle) self.db.commit_event(marriage, self.trans)
def process_family(request, context, handle, act, add_to=None): # view, edit, save """ Process act on person. Can return a redirect. """ context["tview"] = _("Family") context["tviews"] = _("Familes") if handle == "add": act = "add" if "action" in request.POST: act = request.POST.get("action") # Handle: edit, view, add, create, save, delete, share, save-share if act == "share": # Adds a person to an existing family item, handle = add_to context["pickform"] = PickForm("Pick family", Family, (), request.POST) context["object_handle"] = handle context["object_type"] = "person" return render_to_response("pick.html", context) elif act == "save-share": item, handle = add_to pickform = PickForm("Pick family", Family, (), request.POST) if pickform.data["picklist"]: person = Person.objects.get(handle=handle) # to add ref_handle = pickform.data["picklist"] ref_obj = Family.objects.get(handle=ref_handle) if item == "child": dji.add_child_ref_default(ref_obj, person) # add person to family #person.parent_families.add(ref_obj) # add family to child pfo = MyParentFamilies(person=person, family=ref_obj, order=len(person.parent_families.all())+1) pfo.save() elif item == "spouse": if person.gender_type.name == "Female": ref_obj.mother = person elif person.gender_type.name == "Male": ref_obj.father = person else: ref_obj.father = person # FIXME: Unknown gender, add to open #person.families.add(ref_obj) # add family to person pfo = MyFamilies(person=person, family=ref_obj, order=len(person.families.all())+1) pfo.save() ref_obj.save() person.save() return redirect("/%s/%s%s#tab-references" % ("person", handle, build_search(request))) else: context["pickform"] = pickform context["object_handle"] = handle context["object_type"] = "person" return render_to_response("pick.html", context) elif act == "add": family = Family( gramps_id=dji.get_next_id(Family, "F"), family_rel_type=FamilyRelType.objects.get( val=FamilyRelType._DEFAULT[0])) if add_to: what, phandle = add_to person = Person.objects.get(handle=phandle) gender = person.gender_type.name # Male, Female, Unknown if what == "spouse": if gender == "Male": family.father = person elif gender == "Female": family.mother = person else: # You have to pick one! family.father = person elif what == "child": pass # FIXME: can't show child in table? # Table from children_table else: # unknown what! raise Exception("can't add_to: '%s'" % what) familyform = FamilyForm(instance=family) familyform.model = family elif act in ["view", "edit"]: family = Family.objects.get(handle=handle) familyform = FamilyForm(instance=family) familyform.model = family elif act == "save": # editing an existing family family = Family.objects.get(handle=handle) old_family_mother = family.mother old_family_father = family.father familyform = FamilyForm(request.POST, instance=family) familyform.model = family if familyform.is_valid(): update_last_changed(family, request.user.username) family = familyform.save() # Remove family from previous mother/father if changed if familyform.cleaned_data["mother"] != old_family_mother and old_family_mother: MyFamilies.objects.get(person=old_family_mother, family=family).delete() if familyform.cleaned_data["father"] != old_family_father and old_family_father: MyFamilies.objects.get(person=old_family_father, family=family).delete() # Add family to newly selected mother/father if needed: if familyform.cleaned_data["mother"]: if family not in familyform.cleaned_data["mother"].families.all(): #family.mother.families.add(family) pfo = MyFamilies(person=familyform.cleaned_data["mother"], family=family, order=len(familyform.cleaned_data["mother"].families.all())+1) pfo.save() if familyform.cleaned_data["father"]: if family not in familyform.cleaned_data["father"].families.all(): #family.father.families.add(family) pfo = MyFamilies(person=family.father, family=family, order=len(familyform.cleaned_data["father"].families.all())+1) pfo.save() familyform.save() act = "view" else: act = "edit" elif act == "create": family = Family(family_rel_type=FamilyRelType.objects.get( val=FamilyRelType._DEFAULT[0]), handle=create_id()) familyform = FamilyForm(request.POST, instance=family) familyform.model = family if familyform.is_valid(): update_last_changed(family, request.user.username) family = familyform.save() if family.mother: #family.mother.families.add(family) pfo = MyFamilies(person=family.mother, family=family, order=len(family.mother.families.all())+1) pfo.save() if family.father: #family.father.families.add(family) pfo = MyFamilies(person=family.father, family=family, order=len(family.father.families.all())+1) pfo.save() family.save_cache() if add_to: # add child or spouse to family item, handle = add_to person = Person.objects.get(handle=handle) if item == "child": dji.add_child_ref_default(family, person) # add person to family ##person.parent_families.add(family) # add family to child pfo = MyParentFamilies(person=person, family=family, order=len(person.parent_families.all())+1) pfo.save() #elif item == "spouse": # already added by selecting person.save() return redirect("/%s/%s%s#tab-references" % ("person", handle, build_search(request))) act = "view" else: act = "add" elif act == "delete": family = Family.objects.get(handle=handle) family.delete() return redirect("/family/") else: raise Exception("Unhandled act: '%s'" % act) context["familyform"] = familyform context["object"] = family context["family"] = family context["action"] = act view_template = "view_family_detail.html" return render_to_response(view_template, context)
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)