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

Method convert

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

Source from the content-addressed store, hash-verified

420 return self.convert(super().prepare(obj))
421
422 def convert(self, value):
423 if value is None:
424 return None
425
426 if isinstance(value, str):
427 match = DATETIME_REGEX.search(value)
428
429 if match:
430 data = match.groupdict()
431 return datetime.datetime(
432 int(data["year"]),
433 int(data["month"]),
434 int(data["day"]),
435 int(data["hour"]),
436 int(data["minute"]),
437 int(data["second"]),
438 )
439 else:
440 raise SearchFieldError(
441 "Datetime provided to '%s' field doesn't appear to be a valid datetime string: '%s'"
442 % (self.instance_name, value)
443 )
444
445 return value
446
447
448class MultiValueField(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