def post(self, path): if "/" in path: handle, action = path.split("/") else: handle, action = path, "view" if handle == "add": place = Place() place.handle = handle = create_id() else: place = self.database.get_place_from_handle(handle) form = PlaceForm(self.database, _, instance=place) form.save(handler=self) self.redirect("/place/%(handle)s" % {"handle": handle})
def __generate_hierarchy(self, place, handle, original_enclosing_places): # Generates the hierarchy. # Returns the place at the top of the hierarchy or None if no hierarchy was generated original_name = place.get_name().get_value() if original_name == "": original_name = place.get_title() separator = ',' if self.spaces.get_active(): separator = None if ' ' not in original_name: return else: if ',' not in original_name: return names = [ name.strip() for name in original_name.split(separator) if name.strip() ] if self.reverse.get_active(): names.reverse() place_name = PlaceName() place_name.set_value(names[0]) place.set_name(place_name) place.set_title('') parent_handle = None top_place = place for name, handle, new_place in self.find_hierarchy( names, original_enclosing_places)[:-1]: if handle is None: new_place = Place() place_name = PlaceName() place_name.set_value(name) new_place.set_name(place_name) if parent_handle is None: top_place = new_place if parent_handle is not None: placeref = PlaceRef() placeref.ref = parent_handle new_place.add_placeref(placeref) parent_handle = self.dbstate.db.add_place( new_place, self.trans) else: if parent_handle is None: top_place = new_place parent_handle = handle if parent_handle is not None: placeref = PlaceRef() placeref.ref = parent_handle place.set_placeref_list([placeref ]) # this removes any previous parent return top_place
def run(self): """ Generate the hierarchy. """ with self.user.progress(_("Generating hierarchy"), '', self.db.get_number_of_places()) as step: for handle in self.db.get_place_handles(): step() place = self.db.get_place_from_handle(handle) if (int(place.get_type()) != PlaceType.UNKNOWN or ',' not in place.get_title()): # Only process places with a type of Unknown. continue names = [ name.strip() for name in place.get_title().split(',') if name.strip() ] place_name = PlaceName() place_name.set_value(names[0]) place.set_name(place_name) place.set_title('') parent_handle = None for name, handle in self.find_hierarchy(names)[:-1]: if handle is None: new_place = Place() place_name = PlaceName() place_name.set_value(name) new_place.set_name(place_name) if parent_handle is None: new_place.set_type(PlaceType.COUNTRY) if parent_handle is not None: placeref = PlaceRef() placeref.ref = parent_handle new_place.add_placeref(placeref) with DbTxn(_("Add Place"), self.db) as trans: parent_handle = self.db.add_place(new_place, trans) else: parent_handle = handle if parent_handle is not None: placeref = PlaceRef() placeref.ref = parent_handle place.add_placeref(placeref) with DbTxn(_("Edit Place"), self.db) as trans: self.db.commit_place(place, trans)
def test_editreference(self): dbstate = DbState() dbstate.db = self.db source = Place() source.gramps_id = "P0001" self.db.place_map[source.handle] = source editor = MockEditReference(dbstate, uistate=None, track=[], source=source, source_ref=None, update=None) with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED: editor.check_for_duplicate_id("Place") self.assertTrue(MockED.called)
def __add_place(self, name, type_num, parent, title, trans): """ Add a missing place to the database. """ place = Place() place.name = name place.title = title place.place_type = PlaceType(7 - type_num) if parent is not None: placeref = PlaceRef() placeref.ref = handle2internal(parent) place.set_placeref_list([placeref]) handle = self.db.add_place(place, trans) self.db.commit_place(place, trans) return handle
def __execute(self, obj): with DbTxn(_("Processing marriages"), self.dbstate.db) as self.trans: selected_handles = self.uistate.viewmanager.active_page.selected_handles( ) num_places = len(selected_handles) for eventhandle in selected_handles: event = self.dbstate.db.get_event_from_handle(eventhandle) print(event) if not event.get_type().is_marriage(): continue placehandle = event.get_place_handle() place = self.dbstate.db.get_place_from_handle(placehandle) pname = place.get_name().value places = self.__match2(pname) if not places: continue print(places) place1, husb_place, wife_place = places family_handles = list( self.dbstate.db.find_backlink_handles( eventhandle, ['Family'])) print(family_handles) for objtype, family_handle in family_handles: family = self.dbstate.db.get_family_from_handle( family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if not father_handle or not mother_handle: continue father = self.dbstate.db.get_person_from_handle( father_handle) father_name = father.get_primary_name().get_name() mother = self.dbstate.db.get_person_from_handle( mother_handle) mother_name = mother.get_primary_name().get_name() print(father_name, mother_name) self.__add_resi_event(father, husb_place, event.get_date_object()) self.__add_resi_event(mother, wife_place, event.get_date_object()) pn = PlaceName() pn.set_value(place1) newplace = Place() newplace.set_name(pn) newplacehandle = self.dbstate.db.add_place( newplace, self.trans) event.set_place_handle(newplacehandle) event.set_description("marriage") self.dbstate.db.commit_event(event, self.trans) self.dbstate.db.commit_place(place, self.trans)
def add_place_from_kml(self, menu, event, lat, lon): """ Add new place(s) from a kml file 1 - ask for a kml file ? 2 - Read the kml file. 3 - create the place(s) with name and title found in the kml marker. """ dummy_menu = menu dummy_event = event dummy_lat = lat dummy_lon = lon # Ask for the kml file filtering = Gtk.FileFilter() filtering.add_pattern("*.kml") kml = Gtk.FileChooserDialog(_("Select a kml file used to add places"), action=Gtk.FileChooserAction.OPEN, parent=self.uistate.window, buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL, _('_Apply'), Gtk.ResponseType.OK)) mpath = HOME_DIR kml.set_current_folder(os.path.dirname(mpath)) kml.set_filter(filtering) status = kml.run() if status == Gtk.ResponseType.OK: val = kml.get_filename() if val: kmlfile = Kml(val) points = kmlfile.add_points() for place in points: (name, coords) = place latlong = coords.pop() (lat, lon) = latlong place_name = PlaceName() place_name.set_value(name) new_place = Place() new_place.set_name(place_name) new_place.set_title(name) new_place.set_latitude(str(lat)) new_place.set_longitude(str(lon)) try: EditPlace(self.dbstate, self.uistate, [], new_place) except WindowActiveError: pass kml.destroy()
def get_or_create_place(self, place_name): "Return the requested place object tuple-packed with a new indicator." if place_name.startswith("[") and place_name.endswith("]"): place = self.lookup("place", place_name) return (0, place) LOG.debug("get_or_create_place: looking for: %s", place_name) for place_handle in self.db.iter_place_handles(): place = self.db.get_place_from_handle(place_handle) place_title = place_displayer.display(self.db, place) if place_title == place_name: return (0, place) place = Place() place.set_title(place_name) place.name = PlaceName(value=place_name) self.db.add_place(place, self.trans) return (1, place)
def __add_place(self, parent, plat, plon): """ Add a new place using longitude and latitude of location centered on the map """ self.select_fct.close() new_place = Place() new_place.set_latitude(str(plat)) new_place.set_longitude(str(plon)) if parent: if isinstance(parent, Place): placeref = PlaceRef() placeref.ref = parent new_place.add_placeref(placeref) elif isinstance(parent, gi.overrides.Gtk.TreeModelRow): # We are here because we selected a place from geocoding # parent[0] : country # parent[1] : state # parent[2] : town # parent[3] : name value = PlaceSelection.untag_text(parent[2], 1) plname = PlaceName() plname.set_value(value) handle = self.place_exists(value) if handle: # The town already exists. We create a place with name placeref = PlaceRef() placeref.ref = handle new_place.add_placeref(placeref) value = PlaceSelection.untag_text(parent[3], 1) plname.set_value(value) new_place.set_name(plname) else: found = None for place in self.dbstate.db.iter_places(): found = place if place.name.get_value() == parent: break placeref = PlaceRef() placeref.ref = found.get_handle() new_place.add_placeref(placeref) try: EditPlace(self.dbstate, self.uistate, [], new_place) self.add_marker(None, None, plat, plon, None, True, 0) except WindowActiveError: pass
def process_note(self,notehandle): if notehandle in self.notehandles: return # already found thru a place note = self.db.get_note_from_handle(notehandle) notetext = note.get() if notetext.startswith(self.tag): info = json.loads(notetext.split(maxsplit=1)[1]) id = info["id"] if id in self.places: #print("note {id} already found: {info}".format(**locals())) return # already found thru a place, should not get here! place = Place() self.set_info(place,info) placehandle = self.db.add_place(place,self.trans) self.db.commit_place(place, self.trans) self.places[id] = (placehandle,info) self.notehandles.add(notehandle) log(2,info,notehandle)
def __add_place(self, name, type_num, parent, title, trans): """ Add a missing place to the database. """ place = Place() place_name = PlaceName() place_name.set_value(name) place.name = place_name place.title = title place.place_type = PlaceType(7 - type_num) if parent is not None: placeref = PlaceRef() placeref.ref = parent.decode('utf-8') place.set_placeref_list([placeref]) handle = self.db.add_place(place, trans) self.db.commit_place(place, trans) return handle
def __get_place(self, gov_id, type_dic, preferred_lang): gov_url = 'http://gov.genealogy.net/semanticWeb/about/' + quote(gov_id) response = urlopen(gov_url) data = response.read() dom = parseString(data) top = dom.getElementsByTagName('gov:GovObject') place = Place() place.gramps_id = gov_id if not len(top) : return place, [] count = 0 for element in top[0].getElementsByTagName('gov:hasName'): count += 1 place_name = self.__get_hasname(element) if count == 1: place.set_name(place_name) else: if place_name.lang == preferred_lang: place.add_alternative_name(place.get_name()) place.set_name(place_name) else: place.add_alternative_name(place_name) for element in top[0].getElementsByTagName('gov:hasType'): curr_lang = place.get_name().get_language() place_type = self.__get_hastype(element,curr_lang, type_dic, preferred_lang) place.set_type(place_type) for element in top[0].getElementsByTagName('gov:position'): latitude, longitude = self.__get_position(element) place.set_latitude(latitude) place.set_longitude(longitude) ref_list = [] for element in top[0].getElementsByTagName('gov:isPartOf'): ref, date = self.__get_ispartof(element) ref_list.append((ref, date)) for element in top[0].getElementsByTagName('gov:isLocatedIn'): ref, date = self.__get_ispartof(element) ref_list.append((ref, date)) for element in top[0].getElementsByTagName('gov:hasURL'): url = self.__get_hasurl(element) place.add_url(url) return place, ref_list
def __get_level0(self): countries = [] with self.dbstate.db.get_place_cursor() as cursor: pair = cursor.first() while pair: (handle, data) = pair print(pair) place = Place() place.unserialize(data) placetype = place.get_type().value print(placetype) # if getattr(PlaceType, place['type']).upper() == PlaceType.COUNTRY: if placetype == PlaceType.COUNTRY: print("Country found") countries.append(place) pair = cursor.next() # print(countries) return countries
def add(self, obj): """ Add a new place. Use the currently selected rows as parent places. """ parent_list = [] for handle in self.selected_handles(): placeref = PlaceRef() placeref.ref = handle parent_list.append(placeref) place = Place() if len(parent_list) > 0: place.placeref_list = parent_list try: EditPlace(self.dbstate, self.uistate, [], place) except WindowActiveError: pass
def __add_place(self, parent, plat, plon): """ Add a new place using longitude and latitude of location centered on the map """ self.select_fct.close() new_place = Place() new_place.set_latitude(str(plat)) new_place.set_longitude(str(plon)) if parent: placeref = PlaceRef() placeref.ref = parent new_place.add_placeref(placeref) try: EditPlace(self.dbstate, self.uistate, [], new_place) self.add_marker(None, None, plat, plon, None, True, 0) except WindowActiveError: pass
def addPlace(pname, ptype, refPlace=None): place = Place() placeName = PlaceName() placeName.set_value(pname) place.set_name(placeName) # place.set_change_time(chgtime) place.set_type(ptype) place.add_tag(tags[ptype]) if refPlace != None: placeRef = PlaceRef() placeRef.set_reference_handle(refPlace.get_handle()) place.add_placeref(placeRef) # tag.set_color("#EF2929") with DbTxn(_("Add Place"), db) as trans: phandle = db.add_place(place, trans) LOG.debug('Place added: ' + place.get_name().get_value() + ' ' + phandle) return place
def __add_resi_event(self, person, placename, date_object): pn = PlaceName() pn.set_value(placename) place = Place() place.set_name(pn) placehandle = self.dbstate.db.add_place(place, self.trans) e = Event() e.set_type(EventType.RESIDENCE) e.set_date_object(date_object) e.set_place_handle(placehandle) e.set_description("marriage") eventhandle = self.dbstate.db.add_event(e, self.trans) eref = EventRef() eref.ref = eventhandle person.add_event_ref(eref) self.dbstate.db.commit_person(person, self.trans)
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": place = Place() action = "edit" else: place = self.database.get_place_from_handle(handle) if place: self.render( "place.html", **self.get_template_dict(tview=_("place detail"), action=action, page=page, search=search, form=PlaceForm(self.database, _, instance=place), logform=None)) return else: self.clear() self.set_status(404) self.finish("<html><body>No such place</body></html>") return self.render( "page_view.html", **self.get_template_dict( tview=_("place view"), page=page, search=search, form=PlaceForm(self.database, _, table="Place"), ))
def test_editreference(self): dbstate = DbState() db = dbstate.make_database("bsddb") path = "/tmp/edit_ref_test" try: os.mkdir(path) except: pass db.write_version(path) db.load(path) dbstate.change_database(db) source = Place() source.gramps_id = "P0001" dbstate.db.place_map[source.handle] = source.serialize() editor = MockEditReference(dbstate, uistate=None, track=[], source=source, source_ref=None, update=None) with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED: editor.check_for_duplicate_id("Place") self.assertTrue(MockED.called)
def __addPlace(self, pname, ptype, altNames=None, refPlace=None, tag=None): place = Place() placeName = PlaceName() placeName.set_value(pname) place.set_name(placeName) if altNames: place.set_alternative_names(altNames) place.set_type(ptype) if tag: place.add_tag(tag) if refPlace: placeRef = PlaceRef() placeRef.set_reference_handle(refPlace.get_handle()) place.add_placeref(placeRef) with DbTxn(_("Add Place"), self.dbstate.db) as trans: handle = self.dbstate.db.add_place(place, trans) place = self.dbstate.db.get_place_from_handle(handle) self.dbstate.db.commit_place(place, trans) return place
def __init__(self, dbstate, uistate, clicked): self.clicked_func = clicked self.filter_id = widgets.BasicEntry() self.filter_title = widgets.BasicEntry() self.filter_name = widgets.BasicEntry() self.filter_place = Place() self.filter_place.set_type((PlaceType.CUSTOM, '')) self.ptype = Gtk.ComboBox(has_entry=True) self.place_menu = widgets.MonitoredDataType(self.ptype, self.filter_place.set_type, self.filter_place.get_type) self.filter_code = widgets.BasicEntry() 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, "Place")
def addPlace(priName, altNames, ptype, refPlace=None): place = Place() placeName = PlaceName() placeName.set_value(priName[0]) placeName.set_language(priName[1]) place.set_name(placeName) if len(altNames) > 0: place.set_alternative_names(altNames) # place.set_change_time(chgtime) place.set_type(ptype) # place.add_tag(tags[ptype]) place.add_tag(reftag) if refPlace != None: placeRef = PlaceRef() placeRef.set_reference_handle(refPlace.get_handle()) place.add_placeref(placeRef) # tag.set_color("#EF2929") with DbTxn(_("Add Place"), db) as trans: phandle = db.add_place(place, trans) LOG.debug('Place added: ' + place.get_name().get_value() + ' ' + phandle) return place
def test_editreference(self): dbstate = DbState() db = make_database("sqlite") path = "/tmp/edit_ref_test" try: os.mkdir(path) except: pass db.load(path) dbstate.change_database(db) source = Place() source.gramps_id = "P0001" with DbTxn("test place", dbstate.db) as trans: dbstate.db.add_place(source, trans) editor = MockEditReference(dbstate, uistate=None, track=[], source=source, source_ref=None, update=None) with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED: editor.check_for_duplicate_id("Place") self.assertTrue(MockED.called)
def __addPlace(self, pname, ptype, altNames=None, refPlace=None, tag=None): place = Place() placeName = PlaceName() placeName.set_value(pname) # placeName.set_language(priName[1]) place.set_name(placeName) print(pname) if altNames: place.set_alternative_names(altNames) # place.set_change_time(chgtime) place.set_type(ptype) print(ptype) if tag: place.add_tag(tag) if refPlace: placeRef = PlaceRef() placeRef.set_reference_handle(refPlace.get_handle()) place.add_placeref(placeRef) with DbTxn(_("Add Place"), self.dbstate.db) as trans: handle = self.dbstate.db.add_place(place, trans) place = self.dbstate.db.get_place_from_handle(handle) self.dbstate.db.commit_place(place, trans) # print('Place added: ' + place.get_name().get_value() + ' ' + phandle) return place
def add(self, obj): try: EditPlace(self.dbstate, self.uistate, [], Place()) except WindowActiveError: pass
def get_place_from_wikidata(entity_id): parents = set() entity = WikidataItem(get_entity_dict_from_api(entity_id)) claims_groups = entity.get_truthy_claim_groups() place = Place() place.set_gramps_id(entity_id) name = PlaceName() name.set_language('sv') name.set_value(entity.get_label('sv')) place.set_name(name=name) place.set_title(entity.get_label('sv')) for lang in ['sv', 'en', 'de', 'fi', 'no', 'nn', 'da', 'se']: wiki_name = entity.get_label(lang) if len(wiki_name): place_name = PlaceName() place_name.set_language(lang) place_name.set_value(wiki_name) place.add_alternative_name(name=place_name) for alias in entity.get_aliases(lang): alt_name = PlaceName() alt_name.set_language(lang) alt_name.set_value(alias) place.add_alternative_name(name=alt_name) for link in entity.get_sitelinks(lang).values(): wikipedia_url = Url() wikipedia_url.set_path(link['url']) wikipedia_url.set_type('Wikipedia entry') wikipedia_url.set_description('Wikipedia %s:%s' % (link["title"], link["site"])) place.add_url(wikipedia_url) # Instance of -> PlaceType if PROPERTY_INSTANCE_OF in claims_groups: for claim in claims_groups[PROPERTY_INSTANCE_OF]: instance_of = claim.mainsnak.datavalue.value['id'] if ITEM_PARISH == instance_of: place.set_type(PlaceType.PARISH) elif ITEM_SOCKEN == instance_of: place.set_type(PlaceType.PARISH) elif ITEM_ISLAND == instance_of: place.set_type(PlaceType.UNKNOWN) # No islands in Gramps elif ITEM_MUNICIPALITY_OF_SWEDEN == instance_of: place.set_type(PlaceType.MUNICIPALITY) elif ITEM_MUNICIPALITY == instance_of: place.set_type(PlaceType.MUNICIPALITY) elif ITEM_COUNTRY == instance_of: place.set_type(PlaceType.COUNTRY) elif ITEM_SOVEREIGN_STATE == instance_of: place.set_type(PlaceType.COUNTRY) elif ITEM_STATE_OF_US == instance_of: place.set_type(PlaceType.STATE) elif ITEM_FEDERAL_STATE == instance_of: place.set_type(PlaceType.STATE) elif ITEM_COUNTY == instance_of: place.set_type(PlaceType.COUNTY) elif ITEM_COUNTY_OF_SWEDEN == instance_of: place.set_type(PlaceType.COUNTY) elif ITEM_FORMER_COUNTY_OF_SWEDEN == instance_of: place.set_type(PlaceType.COUNTY) elif ITEM_PROVINCE_OF_SWEDEN == instance_of: place.set_type(PlaceType.PROVINCE) elif ITEM_PROVINCE == instance_of: place.set_type(PlaceType.PROVINCE) elif ITEM_ADM_REGION == instance_of: place.set_type(PlaceType.REGION) elif ITEM_NEIGHBORHOOD == instance_of: place.set_type(PlaceType.NEIGHBORHOOD) elif ITEM_DISTRICT == instance_of: place.set_type(PlaceType.DISTRICT) elif ITEM_BOROUGH == instance_of: place.set_type(PlaceType.BOROUGH) elif ITEM_TOWN == instance_of: place.set_type(PlaceType.TOWN) elif ITEM_LARGE_VILLAGE == instance_of: place.set_type(PlaceType.VILLAGE) elif ITEM_VILLAGE == instance_of: place.set_type(PlaceType.VILLAGE) elif ITEM_URBAN_AREA_IN_SWEDEN == instance_of: place.set_type(PlaceType.VILLAGE) elif ITEM_HAMLET == instance_of: place.set_type(PlaceType.HAMLET) elif ITEM_FARM == instance_of: place.set_type(PlaceType.FARM) elif ITEM_BUILDING == instance_of: place.set_type(PlaceType.BUILDING) if PROPERTY_COORDINATE_LOCATION in claims_groups: for claim in claims_groups[PROPERTY_COORDINATE_LOCATION]: datavalue = claim.mainsnak.datavalue place.set_latitude(str(datavalue.value['latitude'])) place.set_longitude(str(datavalue.value['longitude'])) extract_located_in(claims_groups, PROPERTY_LOCATED_IN_PRESENT, parents) extract_located_in(claims_groups, PROPERTY_LOCATED_IN_ADM, parents) extract_located_in(claims_groups, PROPERTY_LOCATED, parents) return place, parents
def empty_object(self): return Place()
def column_title(self, data): place = Place() place.unserialize(data) return place_displayer.display(self.db, place)
def on_res_ok_clicked(self, dummy): """ Accept changes displayed and commit to place. Also find or create a new enclosing place from parent. """ # do the names namelist = [] for row in self.alt_store: if row[0] == 'P': self.place.name = self.newplace.names[row[4]] elif row[0] == '\u2714': namelist.append(self.newplace.names[row[4]]) self.place.alt_names = namelist # Lat/lon/ID/code/type self.place.lat = self.top.get_object('latitude').get_text() self.place.long = self.top.get_object('longitude').get_text() self.place.gramps_id = self.top.get_object('grampsid').get_text() self.place.code = self.top.get_object('postal').get_text() self.place.place_type.set(self.type_combo.get_values()) # Add in URLs if wanted if self.keepweb: for url in self.newplace.links: self.place.add_url(url) # Enclose in the next level place next_place = False parent = None if not self.keep_enclosure or not self.place.placeref_list: if self.newplace.parent_ids: # we might have a parent with geo id 'GEO12345' parent = self.dbstate.db.get_place_from_gramps_id( self.newplace.parent_ids[0]) if not parent and self.newplace.parent_names: # make one, will have to be examined/cleaned later parent = Place() parent.title = ', '.join(self.newplace.parent_names) name = PlaceName() name.value = parent.title parent.name = name parent.gramps_id = self.newplace.parent_ids[0] with DbTxn( _("Add Place (%s)") % parent.title, self.dbstate.db) as trans: self.dbstate.db.add_place(parent, trans) next_place = True if parent: if located_in(self.dbstate.db, parent.handle, self.place.handle): # attempting to create a place loop, not good! ErrorDialog(_('Place cycle detected'), msg2=_("The place you chose is enclosed in the" " place you are workin on!\n" "Please cancel and choose another " "place."), parent=self.uistate.window) return # check to see if we already have the enclosing place already_there = False for pref in self.place.placeref_list: if parent.handle == pref.ref: already_there = True break if not already_there: placeref = PlaceRef() placeref.set_reference_handle(parent.handle) self.place.set_placeref_list([placeref]) # Add in Citation/Source if wanted if self.addcitation and self.newplace.geoid: src_hndl = self.find_or_make_source() cit = Citation() cit.set_reference_handle(src_hndl) cit.set_page("GeoNames ID: %s" % self.newplace.geoid.replace('GEO', '')) with DbTxn(_("Add Citation (%s)") % "GeoNames", self.dbstate.db) as trans: self.dbstate.db.add_citation(cit, trans) self.place.add_citation(cit.handle) # We're finally ready to commit the updated place with DbTxn(_("Edit Place (%s)") % self.place.title, self.dbstate.db) as trans: self.dbstate.db.commit_place(self.place, trans) # Jump to enclosing place to clean it if necessary if next_place: self.set_active('Place', parent.handle) self.place = parent # if geoparse fails, leave us at main view if self.newplace.parent_ids and \ self.geoparse(self.newplace.parent_ids[0], _(", ").join(self.newplace.parent_names), self.newplace.parent_ids, self.newplace.parent_names): # geoparse worked, lets put up the results view self.gui.get_child().remove(self.mainwin) self.gui.get_child().add(self.results_win) self.res_gui() return self.reset_main() if self.gui.get_child().get_child() == self.results_win: self.gui.get_child().remove(self.results_win) self.gui.get_child().add(self.mainwin)
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)