summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/templates/yaksh/course_students.html154
-rw-r--r--yaksh/urls.py34
-rw-r--r--yaksh/views.py115
3 files changed, 165 insertions, 138 deletions
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 @@
<div id="accordian-upload" class="card">
<div class="card-header">
<a class="card-link" data-toggle="collapse" href="#upload_users_csv">
- Upload Users&nbsp;<i class="fa fa-angle-down"></i>
+ Upload Users <i class="fa fa-angle-down"></i>
</a>
</div>
</div>
@@ -48,60 +48,59 @@
<div id="accordian-request" class="card">
<div class="card-header">
<a class="card-link" data-toggle="collapse" href="#requested">
- Requested Students&nbsp;<i class="fa fa-angle-down"></i>
+ Requested Students <i class="fa fa-angle-down"></i>
</a>
</div>
</div>
<div id="requested" class="collapse show" data-parent="#accordion-request">
- {% if requested %}
+ {% if requested_users %}
<br>
- <input type="checkbox" class="checkall"/>&nbsp;
- <font size="5">Select all</font>
+ <input type="checkbox" class="checkall"/> Select all
<div id="enroll-all">
- <form action="{% url 'yaksh:enroll_users' course.id %}" method="post">
+ <form action="{% url 'yaksh:enroll_reject_user' course.id %}" method="post">
{% csrf_token %}
<table id="requested_table" class="tablesorter table table-striped table-responsive-sm course-detail" data-sortlist="[1,0]">
<thead>
<th></th>
- <th>Full Name&nbsp;<i class="fa fa-sort"></i></th>
- <th>Email&nbsp;<i class="fa fa-sort"></i></th>
- <th>Roll Number&nbsp;<i class="fa fa-sort"></i></th>
- <th>Institute&nbsp;<i class="fa fa-sort"></i></th>
- <th>Department&nbsp;<i class="fa fa-sort"></i></th>
+ <th>Full Name <i class="fa fa-sort"></i></th>
+ <th>Email <i class="fa fa-sort"></i></th>
+ <th>Roll Number <i class="fa fa-sort"></i></th>
+ <th>Institute <i class="fa fa-sort"></i></th>
+ <th>Department <i class="fa fa-sort"></i></th>
<th>Enroll/Reject</th>
</thead>
<tbody>
- {% for request in requested %}
+ {% for user in requested_users %}
<tr>
<td>
{{ forloop.counter }}.
- <input type="checkbox" name="check" value="{{ request.id }}">
+ <input type="checkbox" name="check" value="{{ user.id }}">
</td>
- <td>{{request.get_full_name}}</td>
- <td> {{request.email}}</td>
- {% with request.profile as request_profile %}
- <td> {{request_profile.roll_number}}</td>
- <td> {{request_profile.institute}}</td>
- <td> {{request_profile.department}}</td>
+ <td>{{user.get_full_name}}</td>
+ <td> {{user.email}}</td>
+ {% with user.profile as user_profile %}
+ <td> {{user_profile.roll_number}}</td>
+ <td> {{user_profile.institute}}</td>
+ <td> {{user_profile.department}}</td>
{% endwith %}
<td>
- <a class="btn btn-success"
- href="{% url 'yaksh:enroll_user' course.id request.id %}">
- <i class="fa fa-plus-square"></i>
- Enroll </a>
- <a class="btn btn-danger"
- href="{% url 'yaksh:reject_user' course.id request.id %}">
- <i class="fa fa-minus-square"></i>
- Reject </a>
+ <a class="btn btn-success" href="{% url 'yaksh:enroll_user' course.id user.id %}">
+ <i class="fa fa-plus-square"></i>
+ Enroll
+ </a>
+ <a class="btn btn-danger" href="{% url 'yaksh:reject_user' course.id user.id %}">
+ <i class="fa fa-minus-square"></i>
+ Reject
+ </a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
- <button class="btn btn-success btn-lg" type="submit" name='enroll' value='enroll'>
- <i class="fa fa-plus-square"></i>
- Enroll Selected
- </button> <br>
+ <input class="btn btn-success btn-lg" type="submit" name='enroll' value='enroll selected'>
+ </input>
+ <input class="btn btn-danger btn-lg" type="submit" name='reject' value='reject selected'>
+ </input>
</form>
</div>
{% else %}
@@ -116,45 +115,43 @@
<div id="accordian-enrolled" class="card">
<div class="card-header">
<a class="card-link" data-toggle="collapse" href="#enrolled">
- Enrolled Students&nbsp;<i class="fa fa-angle-down"></i>
+ Enrolled Students <i class="fa fa-angle-down"></i>
</a>
</div>
</div>
<div id="enrolled" class="collapse hide" data-parent="#accordion-enrolled">
- {% if enrolled %}
+ {% if enrolled_users %}
<br>
- <input type="checkbox" class="reject"/>&nbsp;
- <font size="5">Select all</font>
+ <input type="checkbox" class="reject"/> Select all
<div id="reject">
- <form action="{% url 'yaksh:reject_users' course.id %}" method="post" id="reject-form">
+ <form action="{% url 'yaksh:reject_enrolled_users' course.id %}" method="post" id="reject-form">
{% csrf_token %}
<table id="enrolled_table" class="tablesorter table table-striped table-responsive-sm course-detail" data-sortlist="[1,0]" style="width: 100%">
<thead>
<th></th>
- <th>Full Name&nbsp;<i class="fa fa-sort"></i></th>
- <th>Email&nbsp;<i class="fa fa-sort"></i></th>
- <th>Roll Number&nbsp;<i class="fa fa-sort"></i></th>
- <th>Institute&nbsp;<i class="fa fa-sort"></i></th>
- <th>Department&nbsp;<i class="fa fa-sort"></i></th>
+ <th>Full Name <i class="fa fa-sort"></i></th>
+ <th>Email <i class="fa fa-sort"></i></th>
+ <th>Roll Number <i class="fa fa-sort"></i></th>
+ <th>Institute <i class="fa fa-sort"></i></th>
+ <th>Department <i class="fa fa-sort"></i></th>
<th>Reject</th>
</thead>
<tbody>
- {% for enroll in enrolled %}
+ {% for user in enrolled_users %}
<tr>
<td>
{{ forloop.counter }}.
- <input type="checkbox" name="check" value="{{ enroll.id }}">
+ <input type="checkbox" name="check" value="{{ user.id }}">
</td>
- <td> {{ enroll.get_full_name|title }} </td>
- <td> {{enroll.email}}</td>
- {% with enroll.profile as enroll_profile %}
- <td> {{enroll_profile.roll_number}}</td>
- <td> {{enroll_profile.institute}}</td>
- <td> {{enroll_profile.department}}</td>
+ <td> {{ user.get_full_name|title }} </td>
+ <td> {{user.email}}</td>
+ {% with user.profile as user_profile %}
+ <td> {{user_profile.roll_number}}</td>
+ <td> {{user_profile.institute}}</td>
+ <td> {{user_profile.department}}</td>
{% endwith %}
<td>
- <a class="btn btn-danger"
- href="{% url 'yaksh:reject_user' course.id enroll.id %}">
+ <a class="btn btn-danger" href="{% url 'yaksh:reject_enrolled_user' course.id user.id %}">
<i class="fa fa-minus-square"></i>
Reject
</a>
@@ -163,10 +160,8 @@
{% endfor %}
</tbody>
</table>
- <button class="btn btn-danger btn-lg" type="submit" name='reject' value='reject'>
- <i class="fa fa-minus-square"></i>
- Reject Selected
- </button> <br>
+ <input class="btn btn-danger btn-lg" type="submit" name='reject' value='reject selected'>
+ </input>
</form>
</div>
{% else %}
@@ -182,56 +177,53 @@
<div id="accordian-rejected" class="card">
<div class="card-header">
<a class="card-link" data-toggle="collapse" href="#rejected">
- Rejected Students&nbsp;<i class="fa fa-angle-down"></i>
+ Rejected Students <i class="fa fa-angle-down"></i>
</a>
</div>
</div>
<div id="rejected" class="collapse hide" data-parent="#accordion-rejected">
- {% if rejected %}
+ {% if rejected_users %}
<br>
- <input type="checkbox" class="enroll"/>&nbsp;
- <font size="5">Select all</font>
+ <input type="checkbox" class="enroll"/> Select all
<div id="enroll">
- <form action="{% url 'yaksh:enroll_rejected' course.id %}" method="post">
+ <form action="{% url 'yaksh:enroll_rejected_users' course.id %}" method="post">
{% csrf_token %}
<table id="rejected_table" class="tablesorter table table-striped table-responsive-sm course-detail" data-sortlist="[1,0]">
<thead>
- <th>Full Name&nbsp;<i class="fa fa-sort"></i></th>
- <th>Email&nbsp;<i class="fa fa-sort"></i></th>
- <th>Roll Number&nbsp;<i class="fa fa-sort"></i></th>
- <th>Institute&nbsp;<i class="fa fa-sort"></i></th>
- <th>Department&nbsp;<i class="fa fa-sort"></i></th>
+ <th>Full Name <i class="fa fa-sort"></i></th>
+ <th>Email <i class="fa fa-sort"></i></th>
+ <th>Roll Number <i class="fa fa-sort"></i></th>
+ <th>Institute <i class="fa fa-sort"></i></th>
+ <th>Department <i class="fa fa-sort"></i></th>
<th>Enroll</th>
</thead>
<tbody>
- {% for reject in rejected %}
+ {% for user in rejected_users %}
<tr>
<td>
{{ forloop.counter }}.
- <input type="checkbox" name="check" value="{{ reject.id }}">
+ <input type="checkbox" name="check" value="{{ user.id }}">
</td>
- <td>{{reject.get_full_name|title}}</td>
- <td> {{reject.email}}</td>
- {% with reject.profile as reject_profile %}
- <td> {{reject_profile.roll_number}}</td>
- <td> {{reject_profile.institute}}</td>
- <td> {{reject_profile.department}}</td>
+ <td>{{user.get_full_name|title}}</td>
+ <td> {{user.email}}</td>
+ {% with user.profile as user_profile %}
+ <td> {{user_profile.roll_number}}</td>
+ <td> {{user_profile.institute}}</td>
+ <td> {{user_profile.department}}</td>
{% endwith %}
<td>
- <a class="btn btn-success"
- href="{% url 'yaksh:enroll_rejected' course.id reject.id %}">
- <i class="fa fa-plus-square"></i>
- Enroll </a>
+ <a class="btn btn-success" href="{% url 'yaksh:enroll_rejected_user' course.id user.id %}">
+ <i class="fa fa-plus-square"></i>
+ Enroll
+ </a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<br>
- <button class="btn btn-success btn-lg" type="submit" name='enroll' value='enroll'>
- <i class="fa fa-plus-square"></i>
- Enroll Selected
- </button>
+ <input class="btn btn-success btn-lg" type="submit" name='enroll' value='enroll selected'>
+ </input>
<br>
</form>
</div>
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<course_id>\d+)/$', views.course_detail,
name='course_detail'),
- url(r'manage/enroll/(?P<course_id>\d+)/(?P<user_id>\d+)/$', views.enroll,
- name="enroll_user"),
+
+ url(r'manage/enroll/(?P<course_id>\d+)/$', views.enroll_reject_user,
+ name="enroll_reject_user"),
+ url(r'manage/enroll/(?P<course_id>\d+)/(?P<user_id>\d+)/$',
+ views.enroll_user, name="enroll_user"),
+ url(r'manage/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$',
+ views.reject_user, name="reject_user"),
+ url(r'manage/enrolled/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$',
+ views.reject_user, {'was_enrolled': True},
+ name="reject_enrolled_user"),
+ url(r'manage/enrolled/reject/(?P<course_id>\d+)/$',
+ views.enroll_reject_user, {'was_enrolled': True},
+ name="reject_enrolled_users"),
url(r'manage/enroll/rejected/(?P<course_id>\d+)/(?P<user_id>\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<course_id>\d+)/$',
+ views.enroll_reject_user, {'was_rejected': True},
+ name="enroll_rejected_users"),
+
url(r'manage/upload_users/(?P<course_id>\d+)/$', views.upload_users,
name="upload_users"),
url(r'manage/send_mail/(?P<course_id>\d+)/$', views.send_mail,
name="send_mail"),
- url(r'manage/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$', views.reject,
- name="reject_user"),
- url(r'manage/enrolled/reject/(?P<course_id>\d+)/(?P<user_id>\d+)/$',
- views.reject, {'was_enrolled': True}, name="reject_user"),
+
url(r'manage/toggle_status/(?P<course_id>\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<course_id>\d+)/$', views.enroll,
- name="enroll_users"),
- url(r'manage/enroll/rejected/(?P<course_id>\d+)/$',
- views.enroll, {'was_rejected': True}, name="enroll_rejected"),
- url(r'manage/enrolled/reject/(?P<course_id>\d+)/$',
- views.reject, {'was_enrolled': True}, name="reject_users"),
+
url(r'^manage/searchteacher/(?P<course_id>\d+)/$', views.search_teacher,
name="search_teacher"),
url(r'^manage/addteacher/(?P<course_id>\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
@@ -1178,31 +1230,6 @@ def send_mail(request, course_id, user_id=None):
@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):
user = request.user
if not is_moderator(user):
@@ -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)