summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2020-03-17 15:06:18 +0530
committerGitHub2020-03-17 15:06:18 +0530
commit15ce39acb70056bdfb9820efa634d704a963cb84 (patch)
treeb54a2d7493be2ba3e9249ae4412c9c231ffaef6b /yaksh/views.py
parenta5e2fb409beebdc33fdb7c230dd50559509fd4c0 (diff)
parenta2186d263aa8927a47fdb9f3a23ad39841b64b33 (diff)
downloadonline_test-15ce39acb70056bdfb9820efa634d704a963cb84.tar.gz
online_test-15ce39acb70056bdfb9820efa634d704a963cb84.tar.bz2
online_test-15ce39acb70056bdfb9820efa634d704a963cb84.zip
Merge pull request #660 from adityacp/fix_course_progress_download_csv
Add a button to download course progress in a CSV
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 5d2d560..58fe6e2 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -3155,3 +3155,28 @@ def get_course_modules(request, course_id):
modules = course.get_learning_modules()
context = {"modules": modules, "is_modules": True, "course": course}
return my_render_to_response(request, 'yaksh/course_detail.html', context)
+
+
+@login_required
+@email_verified
+def download_course_progress(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('This course does not belong to you')
+ students = course.students.order_by("-id")
+ stud_details = [(student.get_full_name(), course.get_grade(student),
+ course.get_completion_percent(student),
+ course.get_current_unit(student))
+ for student in students]
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="{0}.csv"'.format(
+ (course.name).lower().replace(' ', '_'))
+ header = ['Name', 'Grade', 'Completion Percent', 'Current Unit']
+ writer = csv.writer(response)
+ writer.writerow(header)
+ for student in stud_details:
+ writer.writerow(student)
+ return response