2025-07-28 09:52:17 +03:30
|
|
|
import random
|
|
|
|
|
import string
|
2025-05-27 15:09:22 +03:30
|
|
|
import typing
|
2025-07-08 11:59:58 +03:30
|
|
|
from apps.authorization.models import UserRelations
|
2025-05-27 15:09:22 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def detect_file_extension(file_name: str) -> typing.AnyStr:
|
|
|
|
|
""" detect extension of a file like: jpg, png, pdf """
|
|
|
|
|
extended = file_name.split('.')
|
|
|
|
|
return extended[1]
|
2025-07-08 11:59:58 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_organization_by_user(user: object = None) -> typing.Any:
|
2025-07-28 09:52:17 +03:30
|
|
|
""" get organization object by request user """
|
2025-07-08 11:59:58 +03:30
|
|
|
organization = UserRelations.objects.select_related('organization').get(user=user).organization
|
|
|
|
|
return organization
|
2025-07-28 09:52:17 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_code(length=6):
|
|
|
|
|
""" generate 6 digit code """
|
|
|
|
|
return ''.join(random.choices(string.digits, k=length))
|