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 __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 test_editreference(self): dbstate = DbState() db = make_database("bsddb") path = "/tmp/edit_ref_test" try: os.mkdir(path) except: pass 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 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 __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:hasURL'): url = self.__get_hasurl(element) place.add_url(url) return place, ref_list
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 __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, [] types = [] for element in top[0].getElementsByTagName('gov:hasName'): place_name = self.__get_hasname(element) place.add_name(place_name) for element in top[0].getElementsByTagName('gov:hasType'): place_type = self.__get_hastype(element, type_dic, preferred_lang) types.append(place_type) types.sort(key=lambda typ: typ.date.get_sort_value(), reverse=True) place.set_types(types) 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:hasURL'): url = self.__get_hasurl(element) place.add_url(url) return place, ref_list
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 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)