|
|
|
@ -221,7 +221,7 @@ class MyCourseListAPIView(ListAPIView): |
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
|
""" |
|
|
|
Optimized queryset for user's courses with select_related and prefetch_related |
|
|
|
Optimized queryset for user's courses (as student and professor) with select_related and prefetch_related |
|
|
|
""" |
|
|
|
queryset = Course.objects.select_related( |
|
|
|
'category', |
|
|
|
@ -234,8 +234,11 @@ class MyCourseListAPIView(ListAPIView): |
|
|
|
|
|
|
|
request = self.request |
|
|
|
filters = request.query_params |
|
|
|
student = self.request.user |
|
|
|
qs = queryset.filter(participants__student=student) |
|
|
|
user = self.request.user |
|
|
|
|
|
|
|
# Include courses where user is a student OR the professor |
|
|
|
qs = queryset.filter(Q(participants__student=user) | Q(professor=user)).distinct() |
|
|
|
|
|
|
|
completed_only = filters.get('completed', '').lower() == 'true' |
|
|
|
if completed_only == True: |
|
|
|
# نمایش دورههایی که همه درسهایشان توسط کاربر تکمیل شدهاند |
|
|
|
@ -243,7 +246,7 @@ class MyCourseListAPIView(ListAPIView): |
|
|
|
total_lessons=Count('lessons', distinct=True), |
|
|
|
completed_lessons=Count( |
|
|
|
'lessons__completions', |
|
|
|
filter=Q(lessons__completions__student=student), |
|
|
|
filter=Q(lessons__completions__student=user), |
|
|
|
distinct=True |
|
|
|
) |
|
|
|
).filter(total_lessons=F('completed_lessons')) |
|
|
|
@ -253,7 +256,7 @@ class MyCourseListAPIView(ListAPIView): |
|
|
|
total_lessons=Count('lessons', distinct=True), |
|
|
|
completed_lessons=Count( |
|
|
|
'lessons__completions', |
|
|
|
filter=Q(lessons__completions__student=student), |
|
|
|
filter=Q(lessons__completions__student=user), |
|
|
|
distinct=True |
|
|
|
) |
|
|
|
).filter(total_lessons__gt=F('completed_lessons')) |
|
|
|
@ -262,7 +265,7 @@ class MyCourseListAPIView(ListAPIView): |
|
|
|
certificate = filters.get('certificate', '').lower() == 'true' |
|
|
|
if certificate: |
|
|
|
qs = qs.exclude( |
|
|
|
course_certificates__student=student, |
|
|
|
course_certificates__student=user, |
|
|
|
course_certificates__status__in=['pending', 'approved'] |
|
|
|
) |
|
|
|
|
|
|
|
|