base setup
This commit is contained in:
18
at_django_boilerplate/utils/hash_utils.py
Executable file
18
at_django_boilerplate/utils/hash_utils.py
Executable file
@@ -0,0 +1,18 @@
|
||||
import hashlib
|
||||
from hashids import Hashids
|
||||
from django.conf import settings
|
||||
|
||||
def hexdigest(text):
|
||||
text_hash = hashlib.sha256(text.encode()).hexdigest()
|
||||
return text_hash
|
||||
|
||||
|
||||
|
||||
|
||||
HASHIDS = Hashids(salt=settings.SECRET_KEY, min_length=12) # or 8
|
||||
|
||||
def encode_id(pk):
|
||||
return HASHIDS.encode(pk)
|
||||
|
||||
def decode_slug(slug):
|
||||
return HASHIDS.decode(slug)[0] if HASHIDS.decode(slug) else None
|
||||
Reference in New Issue
Block a user