def __init__(self, dbstate, uistate, clicked): self.clicked_func = clicked self.filter_id = widgets.BasicEntry() self.filter_father = widgets.BasicEntry() self.filter_mother = widgets.BasicEntry() self.filter_child = widgets.BasicEntry() self.filter_event = Event() self.filter_event.set_type((EventType.CUSTOM, '')) self.etype = Gtk.ComboBox(has_entry=True) self.family_stub = Family() self.family_stub.set_relationship((FamilyRelType.CUSTOM, '')) self.rtype = Gtk.ComboBox(has_entry=True) self.event_menu = widgets.MonitoredDataType(self.etype, self.filter_event.set_type, self.filter_event.get_type) self.rel_menu = widgets.MonitoredDataType( self.rtype, self.family_stub.set_relationship, self.family_stub.get_relationship) self.filter_note = widgets.BasicEntry() self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions')) self.tag = Gtk.ComboBox() self.generic = Gtk.ComboBox() SidebarFilter.__init__(self, dbstate, uistate, "Family")
def read_family_line(self, line, fields): self.current_husband_handle = None self.current_child_birthplace_handle = None self.current_child_source_handle = None self.current_family = Family() self.db.add_family(self.current_family, self.trans) #self.db.commit_family(self.current_family,self.trans) self.fkeys.append(self.current_family.get_handle()) idx = 1 LOG.debug("\nHusband:") (idx, husband) = self.parse_person(fields, idx, Person.MALE, None) if husband: self.current_husband_handle = husband.get_handle() self.current_family.set_father_handle(husband.get_handle()) self.db.commit_family(self.current_family, self.trans) husband.add_family_handle(self.current_family.get_handle()) self.db.commit_person(husband, self.trans) LOG.debug("Marriage:") idx = self.parse_marriage(fields, idx) LOG.debug("Wife:") (idx, wife) = self.parse_person(fields, idx, Person.FEMALE, None) if wife: self.current_family.set_mother_handle(wife.get_handle()) self.db.commit_family(self.current_family, self.trans) wife.add_family_handle(self.current_family.get_handle()) self.db.commit_person(wife, self.trans) return None
def __add_family(self, father, mother, trans): family = Family() family.set_father_handle(father.handle) family.set_mother_handle(mother.handle) fam_handle = self.db.add_family(family, trans) father.add_family_handle(fam_handle) mother.add_family_handle(fam_handle) self.db.commit_person(father, trans) self.db.commit_person(mother, trans) return family
def add_parent_family(self, obj, event, handle): if button_activated(event, _LEFT_BUTTON): family = Family() person = self.dbstate.db.get_person_from_handle(self.get_handle()) ref = ChildRef() ref.ref = person.handle family.add_child_ref(ref) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def post(self, path): if "/" in path: handle, action = path.split("/") else: handle, action = path, "view" if handle == "add": family = Family() family.handle = handle = create_id() else: family = self.database.get_family_from_handle(handle) form = FamilyForm(self.database, _, instance=family) form.save(handler=self) self.redirect("/family/%(handle)s" % {"handle": handle})
def log(self, ltype, action, handles): for handle in set(handles): if self.last_log == (ltype, action, handle): continue self.last_log = (ltype, action, handle) self.timestamp() # Translators: needed for French, ignore otherwise self.append_text(_("%s: ") % _(action)) if action == 'Deleted': transaction = self.dbstate.db.transaction if ltype == 'Person': name = 'a person' if transaction is not None: for i in transaction.get_recnos(reverse=True): (obj_type, trans_type, hndl, old_data, dummy) = \ transaction.get_record(i) if isinstance(hndl, bytes): hndl = str(hndl, "utf-8") if (obj_type == PERSON_KEY and trans_type == TXNDEL and hndl == handle): person = Person() person.unserialize(old_data) name = name_displayer.display(person) break elif ltype == 'Family': name = 'a family' if transaction is not None: for i in transaction.get_recnos(reverse=True): (obj_type, trans_type, hndl, old_data, dummy) = \ transaction.get_record(i) if isinstance(hndl, bytes): hndl = str(hndl, "utf-8") if (obj_type == FAMILY_KEY and trans_type == TXNDEL and hndl == handle): family = Family() family.unserialize(old_data) name = family_name(family, self.dbstate.db, name) break self.append_text(name) else: if ltype == 'Person': person = self.dbstate.db.get_person_from_handle(handle) name = name_displayer.display(person) elif ltype == 'Family': family = self.dbstate.db.get_family_from_handle(handle) name = family_name(family, self.dbstate.db, 'a family') self.link(name, ltype, handle) self.append_text("\n")
def add_parents(self, *obj): family = Family() person = self.dbstate.db.get_person_from_handle(self.handle) if not person: return ref = ChildRef() ref.ref = person.handle family.add_child_ref(ref) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def add_family(self, obj, event, handle): if button_activated(event, _LEFT_BUTTON): family = Family() person = self.dbstate.db.get_person_from_handle(self.get_handle()) if not person: return if person.gender == Person.MALE: family.set_father_handle(person.handle) else: family.set_mother_handle(person.handle) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def add_spouse(self, *obj): family = Family() person = self.dbstate.db.get_person_from_handle(self.handle) if not person: return if person.gender == Person.MALE: family.set_father_handle(person.handle) else: family.set_mother_handle(person.handle) try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
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 get(self, path=""): """ HANDLE HANDLE/edit|delete /add b2cfa6ca1e174b1f63d/remove/eventref/1 """ page = int(self.get_argument("page", 1)) search = self.get_argument("search", "") if "/" in path: handle, action = path.split("/", 1) else: handle, action = path, "view" if handle: if handle == "add": family = Family() action = "edit" else: family = self.database.get_family_from_handle(handle) if family: self.render( "family.html", **self.get_template_dict(tview=_("family detail"), page=page, action=action, form=FamilyForm(self.database, _, instance=family), logform=None)) return else: self.clear() self.set_status(404) self.finish("<html><body>No such family</body></html>") return self.render( "page_view.html", **self.get_template_dict( tview=_("family view"), page=page, search=search, form=FamilyForm(self.database, _, table="Family"), ))
def add(self, *obj): family = Family() try: EditFamily(self.dbstate, self.uistate, [], family) except WindowActiveError: pass
def empty_object(self): return Family()
def __add_clicked(self, obj): family = Family() EditFamily(self.dbstate, self.uistate, self.track, family, self.__added)
def _process(self, count, total, sql): # --------------------------------- # Process note # --------------------------------- notes = sql.query("""select * from note;""") for note in notes: (handle, gid, text, _format, note_type1, note_type2, change, private) = note styled_text = [text, []] markups = sql.query( """select * from link where from_handle = ? """ """and to_type = 'markup';""", handle) for markup_link in markups: _from_type, _from_handle, _to_type, to_handle = markup_link markup_detail = sql.query( """select * from markup where handle = ?;""", to_handle) for markup in markup_detail: (_mhandle, markup0, markup1, value, start_stop_list) = markup ss_list = eval(start_stop_list) styled_text[1] += [((markup0, markup1), value, ss_list)] tags = self.get_links(sql, "note", handle, "tag") g_note = Note() g_note.unserialize( (handle, gid, styled_text, _format, (note_type1, note_type2), change, tags, bool(private))) self.db.add_note(g_note, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process event # --------------------------------- events = sql.query("""select * from event;""") for event in events: (handle, gid, the_type0, the_type1, description, change, private) = event note_list = self.get_note_list(sql, "event", handle) citation_list = self.get_citation_list(sql, "event", handle) media_list = self.get_media_list(sql, "event", handle) attribute_list = self.get_attribute_list(sql, "event", handle) date_handle = self.get_link(sql, "event", handle, "date") date = self.get_date(sql, date_handle) place_handle = self.get_link(sql, "event", handle, "place") place = self.get_place_from_handle(sql, place_handle) tags = self.get_links(sql, "event", handle, "tag") data = (handle, gid, (the_type0, the_type1), date, description, place, citation_list, note_list, media_list, attribute_list, change, tags, bool(private)) g_event = Event() g_event.unserialize(data) self.db.add_event(g_event, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process person # --------------------------------- people = sql.query("""select * from person;""") for person in people: if person is None: continue ( handle, # 0 gid, # 1 gender, # 2 death_ref_handle, # 5 birth_ref_handle, # 6 change, # 17 private, # 19 ) = person primary_name = self.get_names(sql, "person", handle, True) # one alternate_names = self.get_names(sql, "person", handle, False) event_ref_list = self.get_event_ref_list(sql, "person", handle) family_list = self.get_family_list(sql, "person", handle) parent_family_list = self.get_parent_family_list( sql, "person", handle) media_list = self.get_media_list(sql, "person", handle) address_list = self.get_address_list(sql, "person", handle, with_parish=False) attribute_list = self.get_attribute_list(sql, "person", handle) urls = self.get_url_list(sql, "person", handle) lds_ord_list = self.get_lds_list(sql, "person", handle) pcitation_list = self.get_citation_list(sql, "person", handle) pnote_list = self.get_note_list(sql, "person", handle) person_ref_list = self.get_person_ref_list(sql, "person", handle) death_ref_index = lookup(death_ref_handle, event_ref_list) birth_ref_index = lookup(birth_ref_handle, event_ref_list) tags = self.get_links(sql, "person", handle, "tag") data = ( handle, # 0 gid, # 1 gender, # 2 primary_name, # 3 alternate_names, # 4 death_ref_index, # 5 birth_ref_index, # 6 event_ref_list, # 7 family_list, # 8 parent_family_list, # 9 media_list, # 10 address_list, # 11 attribute_list, # 12 urls, # 13 lds_ord_list, # 14 pcitation_list, # 15 pnote_list, # 16 change, # 17 tags, bool(private), # 19 person_ref_list, ) # 20 g_pers = Person() g_pers.unserialize(data) self.db.add_person(g_pers, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process family # --------------------------------- families = sql.query("""select * from family;""") for family in families: (handle, gid, father_handle, mother_handle, the_type0, the_type1, change, private) = family child_ref_list = self.get_child_ref_list(sql, "family", handle) event_ref_list = self.get_event_ref_list(sql, "family", handle) media_list = self.get_media_list(sql, "family", handle) attribute_list = self.get_attribute_list(sql, "family", handle) lds_seal_list = self.get_lds_list(sql, "family", handle) citation_list = self.get_citation_list(sql, "family", handle) note_list = self.get_note_list(sql, "family", handle) tags = self.get_links(sql, "family", handle, "tag") data = (handle, gid, father_handle, mother_handle, child_ref_list, (the_type0, the_type1), event_ref_list, media_list, attribute_list, lds_seal_list, citation_list, note_list, change, tags, private) g_fam = Family() g_fam.unserialize(data) self.db.add_family(g_fam, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process repository # --------------------------------- repositories = sql.query("""select * from repository;""") for repo in repositories: (handle, gid, the_type0, the_type1, name, change, private) = repo note_list = self.get_note_list(sql, "repository", handle) address_list = self.get_address_list(sql, "repository", handle, with_parish=False) urls = self.get_url_list(sql, "repository", handle) tags = self.get_links(sql, "repository", handle, "tag") data = (handle, gid, (the_type0, the_type1), name, note_list, address_list, urls, change, tags, private) g_rep = Repository() g_rep.unserialize(data) self.db.add_repository(g_rep, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process place # --------------------------------- places = sql.query("""select * from place;""") for place in places: count += 1 (handle, gid, title, value, the_type0, the_type1, code, long, lat, lang, change, private) = place # We could look this up by "place_main", but we have the handle: #main_loc = self.get_main_location(sql, handle, with_parish=True) alt_loc_list = self.get_location_list(sql, "place_alt", handle, with_parish=True) urls = self.get_url_list(sql, "place", handle) media_list = self.get_media_list(sql, "place", handle) citation_list = self.get_citation_list(sql, "place", handle) note_list = self.get_note_list(sql, "place", handle) tags = self.get_links(sql, "place", handle, "tag") place_type = (the_type0, the_type1) alt_place_name_list = self.get_alt_place_name_list(sql, handle) place_ref_list = self.get_place_ref_list(sql, handle) data = (handle, gid, title, long, lat, place_ref_list, PlaceName(value=value, lang=lang).serialize(), alt_place_name_list, place_type, code, alt_loc_list, urls, media_list, citation_list, note_list, change, tags, private) g_plac = Place() g_plac.unserialize(data) self.db.commit_place(g_plac, self.trans) self.callback(100 * count / total) # --------------------------------- # Process citation # --------------------------------- citations = sql.query("""select * from citation;""") for citation in citations: (handle, gid, confidence, page, source_handle, change, private) = citation date_handle = self.get_link(sql, "citation", handle, "date") date = self.get_date(sql, date_handle) note_list = self.get_note_list(sql, "citation", handle) media_list = self.get_media_list(sql, "citation", handle) datamap = self.get_datamap_list(sql, "citation", handle) tags = self.get_links(sql, "citation", handle, "tag") data = (handle, gid, date, page, confidence, source_handle, note_list, media_list, datamap, change, tags, private) g_cit = Citation() g_cit.unserialize(data) self.db.commit_citation(g_cit, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process source # --------------------------------- sources = sql.query("""select * from source;""") for source in sources: (handle, gid, title, author, pubinfo, abbrev, change, private) = source note_list = self.get_note_list(sql, "source", handle) media_list = self.get_media_list(sql, "source", handle) datamap = self.get_datamap_list(sql, "source", handle) reporef_list = self.get_repository_ref_list(sql, "source", handle) tags = self.get_links(sql, "source", handle, "tag") data = (handle, gid, title, author, pubinfo, note_list, media_list, abbrev, change, datamap, reporef_list, tags, private) g_src = Source() g_src.unserialize(data) self.db.commit_source(g_src, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process media # --------------------------------- media = sql.query("""select * from media;""") for med in media: (handle, gid, path, mime, desc, checksum, change, private) = med attribute_list = self.get_attribute_list(sql, "media", handle) citation_list = self.get_citation_list(sql, "media", handle) note_list = self.get_note_list(sql, "media", handle) date_handle = self.get_link(sql, "media", handle, "date") date = self.get_date(sql, date_handle) tags = self.get_links(sql, "media", handle, "tag") data = (handle, gid, path, mime, desc, checksum, attribute_list, citation_list, note_list, change, date, tags, private) g_med = Media() g_med.unserialize(data) self.db.commit_media(g_med, self.trans) count += 1 self.callback(100 * count / total) # --------------------------------- # Process tag # --------------------------------- tags = sql.query("""select * from tag;""") for tag in tags: (handle, name, color, priority, change) = tag data = (handle, name, color, priority, change) g_tag = Tag() g_tag.unserialize(data) self.db.commit_tag(g_tag, self.trans) count += 1 self.callback(100 * count / total)