From cdab789f4e06f8484ef1c79ca66f37bb971be454 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 24 May 2021 17:37:48 +0530 Subject: Fix minor ui issue in moderator interface - Move 'Deactivate course' to the end of the dropdown. - First page of 'Manage Course' shows enrollments. --- yaksh/views.py | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 4a6f462..4a97d1a 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1182,7 +1182,6 @@ def courses(request): @email_verified def course_detail(request, course_id): user = request.user - if not is_moderator(user): raise Http404('You are not allowed to view this page') @@ -1190,9 +1189,18 @@ def course_detail(request, course_id): if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') - return my_render_to_response( - request, 'yaksh/course_detail.html', {'course': course} - ) + enrolled_users = course.get_enrolled() + requested_users = course.get_requests() + rejected_users = course.get_rejected() + context = { + "enrolled_users": enrolled_users, + "requested_users": requested_users, + "course": course, + "rejected_users": rejected_users, + "is_students": True + } + + return my_render_to_response(request, 'yaksh/course_detail.html', context) @login_required @@ -3346,29 +3354,6 @@ def download_course(request, course_id): return response -@login_required -@email_verified -def course_students(request, course_id): - user = request.user - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - course = get_object_or_404(Course, pk=course_id) - if not course.is_creator(user) and not course.is_teacher(user): - raise Http404("You are not allowed to view {0}".format( - course.name)) - enrolled_users = course.get_enrolled() - requested_users = course.get_requests() - rejected_users = course.get_rejected() - context = { - "enrolled_users": enrolled_users, - "requested_users": requested_users, - "course": course, - "rejected_users": rejected_users, - "is_students": True - } - return my_render_to_response(request, 'yaksh/course_detail.html', context) - - @login_required @email_verified def course_teachers(request, course_id): -- cgit From 07fb1660472c40fac358adbeba402052e88db912 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 25 May 2021 17:02:46 +0530 Subject: Fix failing tests --- yaksh/views.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 4a97d1a..5761f37 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1218,7 +1218,7 @@ def enroll_user(request, course_id, user_id=None, was_rejected=False): 'instructor/administrator.' ) messages.warning(request, msg) - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -1226,7 +1226,7 @@ def enroll_user(request, course_id, user_id=None, was_rejected=False): user = User.objects.get(id=user_id) course.enroll(was_rejected, user) messages.success(request, 'Enrolled student successfully') - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) @login_required @@ -1241,7 +1241,7 @@ def reject_user(request, course_id, user_id=None, was_enrolled=False): user = User.objects.get(id=user_id) course.reject(was_enrolled, user) messages.success(request, "Rejected students successfully") - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) @login_required @@ -1260,7 +1260,7 @@ def enroll_reject_user(request, 'instructor/administrator.' ) messages.warning(request, msg) - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') @@ -1270,21 +1270,21 @@ def enroll_reject_user(request, enroll_ids = request.POST.getlist('check') if not enroll_ids: messages.warning(request, "Please select atleast one student") - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) users = User.objects.filter(id__in=enroll_ids) course.enroll(was_rejected, *users) messages.success(request, "Enrolled student(s) successfully") - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) if 'reject' in request.POST: reject_ids = request.POST.getlist('check') if not reject_ids: messages.warning(request, "Please select atleast one student") - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) users = User.objects.filter(id__in=reject_ids) course.reject(was_enrolled, *users) messages.success(request, "Rejected students successfully") - return redirect('yaksh:course_students', course_id=course_id) - return redirect('yaksh:course_students', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) + return redirect('yaksh:course_detail', course_id=course_id) @login_required @@ -2441,13 +2441,13 @@ def upload_users(request, course_id): if request.method == 'POST': if 'csv_file' not in request.FILES: messages.warning(request, "Please upload a CSV file.") - return my_redirect(reverse('yaksh:course_students', + return my_redirect(reverse('yaksh:course_detail', args=[course_id])) csv_file = request.FILES['csv_file'] is_csv_file, dialect = is_csv(csv_file) if not is_csv_file: messages.warning(request, "The file uploaded is not a CSV file.") - return my_redirect(reverse('yaksh:course_students', + return my_redirect(reverse('yaksh:course_detail', args=[course_id])) required_fields = ['firstname', 'lastname', 'email'] try: @@ -2456,7 +2456,7 @@ def upload_users(request, course_id): dialect=dialect) except TypeError: messages.warning(request, "Bad CSV file") - return my_redirect(reverse('yaksh:course_students', + return my_redirect(reverse('yaksh:course_detail', args=[course_id])) stripped_fieldnames = [ field.strip().lower() for field in reader.fieldnames] @@ -2464,11 +2464,11 @@ def upload_users(request, course_id): if field not in stripped_fieldnames: msg = "The CSV file does not contain the required headers" messages.warning(request, msg) - return my_redirect(reverse('yaksh:course_students', + return my_redirect(reverse('yaksh:course_detail', args=[course_id])) reader.fieldnames = stripped_fieldnames _read_user_csv(request, reader, course) - return my_redirect(reverse('yaksh:course_students', args=[course_id])) + return my_redirect(reverse('yaksh:course_detail', args=[course_id])) def _read_user_csv(request, reader, course): -- cgit From d81699719c35a24fc2c7917b8d147e332929ce31 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 14 Jun 2021 15:44:59 +0530 Subject: prefetch students, requests, rejected --- yaksh/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 5761f37..3727514 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1185,7 +1185,9 @@ def course_detail(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page') - course = get_object_or_404(Course, pk=course_id) + course = Course.objects.prefetch_related( + 'students', 'requests', 'rejected' + ).get(id=course_id) if not course.is_creator(user) and not course.is_teacher(user): raise Http404('This course does not belong to you') -- cgit