schon/core/utils/db.py
Egor fureunoir Gorbunov af127045ae Features: None;
Fixes: 1) Update logging configuration to align all logger instances to use "django" instead of "evibes"; 2) Remove unused logging configuration for "django.request";

Extra: 1) Add detailed error logging in GraphQL execution to include exception messages.
2025-07-06 17:22:14 +03:00

39 lines
1,019 B
Python

import logging
from django.db.models.constants import LOOKUP_SEP
from django_extensions.db.fields import AutoSlugField
from slugify import slugify
logger = logging.getLogger("django")
def unicode_slugify_function(content):
return slugify(
text=str(content),
allow_unicode=True,
max_length=88,
word_boundary=True,
save_order=True,
regex_pattern=r"(?:[^\w-]|_)+",
separator="-",
)
class TweakedAutoSlugField(AutoSlugField):
def get_slug_fields(self, model_instance, lookup_value):
if callable(lookup_value):
return f"{lookup_value(model_instance)}"
lookup_value_path = lookup_value.split(LOOKUP_SEP)
attr = model_instance
for elem in lookup_value_path:
try:
attr = getattr(attr, elem)
except AttributeError:
attr = ""
if callable(attr):
# noinspection PyCallingNonCallable
return f"{attr()}"
return attr