This commit is contained in:
Markos Gogoulos
2025-12-29 20:32:56 +02:00
parent 995faedb08
commit 8c8f737460
2 changed files with 39 additions and 2 deletions

View File

@@ -276,18 +276,34 @@ class MediaList(APIView):
# Handle LTI category assignment if publish_to_category parameter is provided
publish_to_category = request.data.get('publish_to_category', '').strip()
print("=" * 80)
print("MEDIA UPLOAD - CATEGORY ASSIGNMENT")
print(f"publish_to_category parameter: '{publish_to_category}'")
print(f"User: {request.user.username}")
if publish_to_category:
from ..models import Category
try:
category = Category.objects.get(uid=publish_to_category)
print(f"Category found: {category.title} (uid={category.uid})")
# Check if user has upload access to this category
if request.user.has_member_access_to_category(category):
has_access = request.user.has_member_access_to_category(category)
print(f"User has member access to category: {has_access}")
if has_access:
media.category.add(category)
print(f"SUCCESS: Added media '{media.title}' to category '{category.title}'")
else:
print(f"SKIPPED: User does not have member access to category '{category.title}'")
except Category.DoesNotExist:
# Category doesn't exist, silently ignore
print(f"ERROR: Category with uid='{publish_to_category}' does not exist")
pass
else:
print("No publish_to_category parameter provided")
print("=" * 80)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)