MCPcopy Index your code
hub / github.com/django-haystack/django-haystack / convert

Method convert

haystack/fields.py:260–284  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

258 return "%s,%s" % (pnt_lat, pnt_lng)
259
260 def convert(self, value):
261 from django.contrib.gis.geos import Point
262
263 from haystack.utils.geo import ensure_point
264
265 if value is None:
266 return None
267
268 if hasattr(value, "geom_type"):
269 value = ensure_point(value)
270 return value
271
272 if isinstance(value, str):
273 lat, lng = value.split(",")
274 elif isinstance(value, (list, tuple)):
275 # GeoJSON-alike
276 lat, lng = value[1], value[0]
277 elif isinstance(value, dict):
278 lat = value.get("lat", 0)
279 lng = value.get("lon", 0)
280 else:
281 raise TypeError("Unable to extract coordinates from %r" % value)
282
283 value = Point(float(lng), float(lat))
284 return value
285
286
287class NgramField(CharField):

Callers

nothing calls this directly

Calls 2

ensure_pointFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected