|
|
@ -2,6 +2,8 @@ from django.db.models import Q |
|
|
from rest_framework import viewsets |
|
|
from rest_framework import viewsets |
|
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser |
|
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser |
|
|
from rest_framework.authentication import TokenAuthentication |
|
|
from rest_framework.authentication import TokenAuthentication |
|
|
|
|
|
from rest_framework.decorators import action |
|
|
|
|
|
from rest_framework.response import Response |
|
|
from apps.course.models import ( |
|
|
from apps.course.models import ( |
|
|
Course, |
|
|
Course, |
|
|
CourseCategory, |
|
|
CourseCategory, |
|
|
@ -89,6 +91,23 @@ class AdminChapterViewSet(viewsets.ModelViewSet): |
|
|
queryset = queryset.filter(course_id=course_id) |
|
|
queryset = queryset.filter(course_id=course_id) |
|
|
return queryset.order_by('priority', 'id') |
|
|
return queryset.order_by('priority', 'id') |
|
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['post']) |
|
|
|
|
|
def reorder(self, request): |
|
|
|
|
|
""" |
|
|
|
|
|
Reorders chapters in bulk. |
|
|
|
|
|
Format: {"chapter_ids": [id1, id2, ...]} |
|
|
|
|
|
""" |
|
|
|
|
|
chapter_ids = request.data.get('chapter_ids', []) |
|
|
|
|
|
if not chapter_ids: |
|
|
|
|
|
return Response({'error': 'chapter_ids list is required'}, status=400) |
|
|
|
|
|
|
|
|
|
|
|
from django.db import transaction |
|
|
|
|
|
with transaction.atomic(): |
|
|
|
|
|
for idx, c_id in enumerate(chapter_ids): |
|
|
|
|
|
CourseChapter.objects.filter(id=c_id).update(priority=idx + 1) |
|
|
|
|
|
|
|
|
|
|
|
return Response({'status': 'success'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdminCourseLessonViewSet(viewsets.ModelViewSet): |
|
|
class AdminCourseLessonViewSet(viewsets.ModelViewSet): |
|
|
""" |
|
|
""" |
|
|
@ -119,6 +138,23 @@ class AdminCourseLessonViewSet(viewsets.ModelViewSet): |
|
|
if lesson: |
|
|
if lesson: |
|
|
lesson.delete() |
|
|
lesson.delete() |
|
|
|
|
|
|
|
|
|
|
|
@action(detail=False, methods=['post']) |
|
|
|
|
|
def reorder(self, request): |
|
|
|
|
|
""" |
|
|
|
|
|
Reorders lessons in bulk. |
|
|
|
|
|
Format: {"lesson_ids": [id1, id2, ...]} |
|
|
|
|
|
""" |
|
|
|
|
|
lesson_ids = request.data.get('lesson_ids', []) |
|
|
|
|
|
if not lesson_ids: |
|
|
|
|
|
return Response({'error': 'lesson_ids list is required'}, status=400) |
|
|
|
|
|
|
|
|
|
|
|
from django.db import transaction |
|
|
|
|
|
with transaction.atomic(): |
|
|
|
|
|
for idx, l_id in enumerate(lesson_ids): |
|
|
|
|
|
CourseLesson.objects.filter(id=l_id).update(priority=idx + 1) |
|
|
|
|
|
|
|
|
|
|
|
return Response({'status': 'success'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdminCourseAttachmentViewSet(viewsets.ModelViewSet): |
|
|
class AdminCourseAttachmentViewSet(viewsets.ModelViewSet): |
|
|
""" |
|
|
""" |
|
|
|