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

Method convert

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

Source from the content-addressed store, hash-verified

387 return self.convert(super().prepare(obj))
388
389 def convert(self, value):
390 if value is None:
391 return None
392
393 if isinstance(value, str):
394 match = DATE_REGEX.search(value)
395
396 if match:
397 data = match.groupdict()
398 return datetime.date(
399 int(data["year"]), int(data["month"]), int(data["day"])
400 )
401 else:
402 raise SearchFieldError(
403 "Date provided to '%s' field doesn't appear to be a valid date string: '%s'"
404 % (self.instance_name, value)
405 )
406
407 return value
408
409
410class DateTimeField(SearchField):

Callers 2

prepareMethod · 0.95
test_convertMethod · 0.95

Calls 2

SearchFieldErrorClass · 0.90
searchMethod · 0.45

Tested by 1

test_convertMethod · 0.76