File: custom_identifier.py

package info (click to toggle)
django-haystack 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: python: 23,475; xml: 1,708; sh: 74; makefile: 71
file content (14 lines) | stat: -rw-r--r-- 350 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import hashlib


def get_identifier_method(key):
    """
    Custom get_identifier method used for testing the
    setting HAYSTACK_IDENTIFIER_MODULE
    """

    if hasattr(key, "get_custom_haystack_id"):
        return key.get_custom_haystack_id()
    else:
        key_bytes = key.encode("utf-8")
        return hashlib.md5(key_bytes).hexdigest()