|
|
|
@ -3,6 +3,7 @@ from decimal import Decimal |
|
|
|
import math |
|
|
|
from django.db import models |
|
|
|
from django.db.models import TextChoices |
|
|
|
from django.utils.text import slugify |
|
|
|
from django.utils.translation import gettext_lazy as _ |
|
|
|
|
|
|
|
from apps.account.models import ProfessorUser |
|
|
|
@ -77,7 +78,7 @@ def get_localized_field(lang, field_value): |
|
|
|
|
|
|
|
|
|
|
|
def course_file_upload_to(instance, filename): |
|
|
|
return os.path.join(f"courses/{instance.slug}/videos/{filename}") |
|
|
|
return os.path.join(f"courses/{get_course_storage_slug(instance)}/videos/{filename}") |
|
|
|
|
|
|
|
|
|
|
|
def attachment_file_upload_to(instance, filename): |
|
|
|
@ -85,7 +86,35 @@ def attachment_file_upload_to(instance, filename): |
|
|
|
|
|
|
|
|
|
|
|
def course_attachment_file_upload_to(instance, filename): |
|
|
|
return os.path.join(f"courses/{instance.course.slug}/attachments/{filename}") |
|
|
|
return os.path.join( |
|
|
|
f"courses/{get_course_storage_slug(instance.course)}/attachments/{filename}" |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
def get_course_storage_slug(instance): |
|
|
|
slug_source = instance.slug |
|
|
|
|
|
|
|
if isinstance(slug_source, list): |
|
|
|
for lang in ("en", "fa", "ru"): |
|
|
|
for item in slug_source: |
|
|
|
if isinstance(item, dict) and item.get("language_code") == lang: |
|
|
|
localized_slug = item.get("title") or item.get("value") or item.get("text") or item.get("name") |
|
|
|
safe_slug = slugify(str(localized_slug or "")) |
|
|
|
if safe_slug: |
|
|
|
return safe_slug |
|
|
|
|
|
|
|
safe_slug = slugify(extract_text_from_json(slug_source)) |
|
|
|
if safe_slug: |
|
|
|
return safe_slug |
|
|
|
|
|
|
|
safe_title = slugify(extract_text_from_json(instance.title)) |
|
|
|
if safe_title: |
|
|
|
return safe_title |
|
|
|
|
|
|
|
if instance.pk: |
|
|
|
return f"course-{instance.pk}" |
|
|
|
|
|
|
|
return "course-draft" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|