Browse Source

debug my courses

master
nwhco 1 year ago
parent
commit
15607ce937
  1. 30
      apps/course/views/course.py
  2. 2
      config/settings/base.py

30
apps/course/views/course.py

@ -130,6 +130,7 @@ class MyCourseListAPIView(ListAPIView):
) )
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
print(f'--> my-course-> {request}/ {kwargs}')
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
def get_queryset(self): def get_queryset(self):
@ -139,8 +140,9 @@ class MyCourseListAPIView(ListAPIView):
student = self.request.user student = self.request.user
qs = queryset.filter(participants__student=student) qs = queryset.filter(participants__student=student)
completed_only = filters.get('completed', '').lower() == 'true' completed_only = filters.get('completed', '').lower() == 'true'
if completed_only:
queryset = qs.annotate(
if completed_only == True:
# نمایش دوره‌هایی که همه درس‌هایشان توسط کاربر تکمیل شده‌اند
qs = qs.annotate(
total_lessons=Count('lessons', distinct=True), total_lessons=Count('lessons', distinct=True),
completed_lessons=Count( completed_lessons=Count(
'lessons__completions', 'lessons__completions',
@ -148,11 +150,25 @@ class MyCourseListAPIView(ListAPIView):
distinct=True distinct=True
) )
).filter(total_lessons=F('completed_lessons')) ).filter(total_lessons=F('completed_lessons'))
if certificate := filters.get('certificate', '').lower() == 'true':
queryset = qs.exclude(
course_certificates__student=student,
course_certificates__status__in=['pending', 'approved']
)
elif completed_only == False:
# نمایش دوره‌هایی که همه درس‌هایشان تکمیل نشده‌اند
qs = qs.annotate(
total_lessons=Count('lessons', distinct=True),
completed_lessons=Count(
'lessons__completions',
filter=Q(lessons__completions__student=student),
distinct=True
)
).filter(total_lessons__gt=F('completed_lessons'))
if 'completed' not in filters:
certificate = filters.get('certificate', '').lower() == 'true'
if certificate:
qs = qs.exclude(
course_certificates__student=student,
course_certificates__status__in=['pending', 'approved']
)
return qs return qs

2
config/settings/base.py

@ -274,7 +274,7 @@ STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static') STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
FILER_ADMIN_ICON_SIZES = ('32', '48')
# FILER_ADMIN_ICON_SIZES = ('32', '48')
FILER_ENABLE_LOGGING = True FILER_ENABLE_LOGGING = True
FILER_DEBUG = True FILER_DEBUG = True

Loading…
Cancel
Save