def testGazetteerQueryWithStartDateEndDateAD(self): if settings.USE_GAZETTEER: # Return all places that existed at some point between these dates - # Should be three [Paradise1, Paradise2, Paradise5) results = getGazetteerResults("Paradis", start_date="2010-01-01", end_date="2011-07-21") for result in results: self.assertTrue(result["placename"] in ["Paradise1", "Paradise2", "Paradise5"]) self.assertEqual(len(results), 3)
def testGazetteerQueryWithStartDateBC(self): if settings.USE_GAZETTEER: # Return all places that existed on this date - # Should be one [Paradise3) results = getGazetteerResults("Paradis", start_date="2010-07-20 BC") self.assertEqual(len(results), 1) for result in results: self.assertTrue(result["placename"] in ["Paradise4"])
def testGazetteerQueryWithStartDateAD(self): if settings.USE_GAZETTEER: # Return all places that existed on this date - # Should be two [Paradise1, Paradise5) results = getGazetteerResults("Paradis", start_date="2011-01-01") self.assertEqual(len(results), 2) for result in results: self.assertTrue(result["placename"] in ["Paradise1", "Paradise5"])
def read(self, request, place_name, map = None, layer = None, start_date = None, end_date = None, project=None, services=None): if place_name.isdigit(): posts = getGazetteerEntry(place_name) else: posts = getGazetteerResults(place_name, map, layer, start_date, end_date, project) if services is not None: posts.extend(getExternalServiceResults(place_name,services)) return posts
def search(request, place_name, map=None, layer=None, start_date=None, end_date=None, project=None, services=None, user=None, format='json'): """ Search the Gazetteer and return results in JSON or XML format. """ if not format: out_format = 'json' else: out_format = format.lower() if out_format not in ('xml', 'json'): out_format = 'json' if place_name.isdigit(): posts = getGazetteerEntry(place_name) else: posts = getGazetteerResults(place_name, map, layer, start_date, end_date, project, user) if services is not None: posts.extend(getExternalServiceResults(place_name, services)) if out_format == 'json': return HttpResponse(json.dumps(posts, sort_keys=True, indent=4), content_type="application/json") elif out_format == 'xml': return HttpResponse(dicttoxml([{'resource': post} for post in posts], attr_type=False, custom_root='response'), content_type="application/xml")
def testGazetteerQueryNoDatesOneResult(self): if settings.USE_GAZETTEER: results = getGazetteerResults("Paradise1") self.assertEqual(len(results), 1)