From 66c881ff2769560258b3d72a12aedd0df17b9d27 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 6 May 2020 21:24:37 +0530 Subject: Add Reject button to reject selected students - A reject button to reject selected students in Enroll Students page on a Requested Students tab. - Improve the views and urls for enrolling and rejecting students in the course. --- yaksh/templates/yaksh/course_students.html | 154 ++++++++++++++--------------- yaksh/urls.py | 34 ++++--- yaksh/views.py | 115 ++++++++++++--------- 3 files changed, 165 insertions(+), 138 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/course_students.html b/yaksh/templates/yaksh/course_students.html index 2052a69..e8ca800 100644 --- a/yaksh/templates/yaksh/course_students.html +++ b/yaksh/templates/yaksh/course_students.html @@ -3,7 +3,7 @@
- Upload Users  + Upload Users
@@ -48,60 +48,59 @@
- Requested Students  + Requested Students
- {% if requested %} + {% if requested_users %}
-   - Select all + Select all
-
+ {% csrf_token %} - - - - - + + + + + - {% for request in requested %} + {% for user in requested_users %} - - - {% with request.profile as request_profile %} - - - + + + {% with user.profile as user_profile %} + + + {% endwith %} {% endfor %}
Full Name Email Roll Number Institute Department Full Name Email Roll Number Institute Department Enroll/Reject
{{ forloop.counter }}. - + {{request.get_full_name}} {{request.email}} {{request_profile.roll_number}} {{request_profile.institute}} {{request_profile.department}}{{user.get_full_name}} {{user.email}} {{user_profile.roll_number}} {{user_profile.institute}} {{user_profile.department}} - - - Enroll - - - Reject + + + Enroll + + + + Reject +
-
+ + + +
{% else %} @@ -116,45 +115,43 @@
- {% if enrolled %} + {% if enrolled_users %}
-   - Select all + Select all
-
+ {% csrf_token %} - - - - - + + + + + - {% for enroll in enrolled %} + {% for user in enrolled_users %} - - - {% with enroll.profile as enroll_profile %} - - - + + + {% with user.profile as user_profile %} + + + {% endwith %}
Full Name Email Roll Number Institute Department Full Name Email Roll Number Institute Department Reject
{{ forloop.counter }}. - + {{ enroll.get_full_name|title }} {{enroll.email}} {{enroll_profile.roll_number}} {{enroll_profile.institute}} {{enroll_profile.department}} {{ user.get_full_name|title }} {{user.email}} {{user_profile.roll_number}} {{user_profile.institute}} {{user_profile.department}} - + Reject @@ -163,10 +160,8 @@ {% endfor %}
-
+ +
{% else %} @@ -182,56 +177,53 @@
- {% if rejected %} + {% if rejected_users %}
-   - Select all + Select all
-
+ {% csrf_token %} - - - - - + + + + + - {% for reject in rejected %} + {% for user in rejected_users %} - - - {% with reject.profile as reject_profile %} - - - + + + {% with user.profile as user_profile %} + + + {% endwith %} {% endfor %}
Full Name Email Roll Number Institute Department Full Name Email Roll Number Institute Department Enroll
{{ forloop.counter }}. - + {{reject.get_full_name|title}} {{reject.email}} {{reject_profile.roll_number}} {{reject_profile.institute}} {{reject_profile.department}}{{user.get_full_name|title}} {{user.email}} {{user_profile.roll_number}} {{user_profile.institute}} {{user_profile.department}} - - - Enroll + + + Enroll +

- + +
diff --git a/yaksh/urls.py b/yaksh/urls.py index 149e4d6..97bd42e 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -122,30 +122,38 @@ urlpatterns = [ name='edit_course'), url(r'manage/course_detail/(?P\d+)/$', views.course_detail, name='course_detail'), - url(r'manage/enroll/(?P\d+)/(?P\d+)/$', views.enroll, - name="enroll_user"), + + url(r'manage/enroll/(?P\d+)/$', views.enroll_reject_user, + name="enroll_reject_user"), + url(r'manage/enroll/(?P\d+)/(?P\d+)/$', + views.enroll_user, name="enroll_user"), + url(r'manage/reject/(?P\d+)/(?P\d+)/$', + views.reject_user, name="reject_user"), + url(r'manage/enrolled/reject/(?P\d+)/(?P\d+)/$', + views.reject_user, {'was_enrolled': True}, + name="reject_enrolled_user"), + url(r'manage/enrolled/reject/(?P\d+)/$', + views.enroll_reject_user, {'was_enrolled': True}, + name="reject_enrolled_users"), url(r'manage/enroll/rejected/(?P\d+)/(?P\d+)/$', - views.enroll, {'was_rejected': True}, name="enroll_rejected"), + views.enroll_user, {'was_rejected': True}, + name="enroll_rejected_user"), + url(r'manage/enroll/rejected/(?P\d+)/$', + views.enroll_reject_user, {'was_rejected': True}, + name="enroll_rejected_users"), + url(r'manage/upload_users/(?P\d+)/$', views.upload_users, name="upload_users"), url(r'manage/send_mail/(?P\d+)/$', views.send_mail, name="send_mail"), - url(r'manage/reject/(?P\d+)/(?P\d+)/$', views.reject, - name="reject_user"), - url(r'manage/enrolled/reject/(?P\d+)/(?P\d+)/$', - views.reject, {'was_enrolled': True}, name="reject_user"), + url(r'manage/toggle_status/(?P\d+)/$', views.toggle_course_status, name="toggle_course_status"), url(r'^questions/filter$', views.questions_filter, name="questions_filter"), url(r'^editprofile/$', views.edit_profile, name='edit_profile'), url(r'^viewprofile/$', views.view_profile, name='view_profile'), - url(r'^manage/enroll/(?P\d+)/$', views.enroll, - name="enroll_users"), - url(r'manage/enroll/rejected/(?P\d+)/$', - views.enroll, {'was_rejected': True}, name="enroll_rejected"), - url(r'manage/enrolled/reject/(?P\d+)/$', - views.reject, {'was_enrolled': True}, name="reject_users"), + url(r'^manage/searchteacher/(?P\d+)/$', views.search_teacher, name="search_teacher"), url(r'^manage/addteacher/(?P\d+)/$', views.add_teacher, diff --git a/yaksh/views.py b/yaksh/views.py index 397e7c8..c716be4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1113,12 +1113,55 @@ def course_detail(request, course_id): @login_required @email_verified -def enroll(request, course_id, user_id=None, was_rejected=False): +def enroll_user(request, course_id, user_id=None, was_rejected=False): 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) + course = get_object_or_404(Course, id=course_id) + if not course.is_active_enrollment(): + msg = ( + 'Enrollment for this course has been closed,' + ' please contact your ' + 'instructor/administrator.' + ) + messages.warning(request, msg) + return redirect('yaksh:course_students', 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') + + 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) + + +@login_required +@email_verified +def reject_user(request, course_id, user_id=None, was_enrolled=False): + user = request.user + print(was_enrolled) + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + course = get_object_or_404(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') + 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) + + +@login_required +@email_verified +def enroll_reject_user(request, + course_id, was_enrolled=False, was_rejected=False): + user = request.user + if not is_moderator(user): + raise Http404('You are not allowed to view this page') + course = get_object_or_404(Course, id=course_id) + if not course.is_active_enrollment(): msg = ( 'Enrollment for this course has been closed,' @@ -1126,23 +1169,32 @@ def enroll(request, course_id, user_id=None, was_rejected=False): 'instructor/administrator.' ) messages.warning(request, msg) - return my_redirect(reverse('yaksh:course_students', args=[course_id])) + return redirect('yaksh:course_students', 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') if request.method == 'POST': - enroll_ids = request.POST.getlist('check') - else: - enroll_ids = [user_id] - if not enroll_ids: - messages.warning(request, "Please select atleast one student") - return my_redirect(reverse('yaksh:course_students', args=[course_id])) - - users = User.objects.filter(id__in=enroll_ids) - course.enroll(was_rejected, *users) - messages.success(request, "Enrolled student(s) successfully") - return my_redirect(reverse('yaksh:course_students', args=[course_id])) + if 'enroll' in request.POST: + 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) + 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) + 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) + 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) @login_required @@ -1176,31 +1228,6 @@ def send_mail(request, course_id, user_id=None): return my_render_to_response(request, 'yaksh/course_detail.html', context) -@login_required -@email_verified -def reject(request, course_id, user_id=None, was_enrolled=False): - 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('This course does not belong to you') - - if request.method == 'POST': - reject_ids = request.POST.getlist('check') - else: - reject_ids = [user_id] - if not reject_ids: - messages.warning(request, "Please select atleast one student") - return my_redirect(reverse('yaksh:course_students', args=[course_id])) - - users = User.objects.filter(id__in=reject_ids) - course.reject(was_enrolled, *users) - messages.success(request, "Rejected students successfully") - return my_redirect(reverse('yaksh:course_students', args=[course_id])) - - @login_required @email_verified def toggle_course_status(request, course_id): @@ -3215,11 +3242,11 @@ def course_students(request, 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 = course.get_enrolled() - requested = course.get_requests() - rejected = course.get_rejected() - context = {"enrolled": enrolled, "requested": requested, "course": course, - "rejected": rejected, "is_students": True} + 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) -- cgit