diff options
author | Palaparthy Adityachandra | 2020-03-17 15:06:18 +0530 |
---|---|---|
committer | GitHub | 2020-03-17 15:06:18 +0530 |
commit | 15ce39acb70056bdfb9820efa634d704a963cb84 (patch) | |
tree | b54a2d7493be2ba3e9249ae4412c9c231ffaef6b /yaksh/views.py | |
parent | a5e2fb409beebdc33fdb7c230dd50559509fd4c0 (diff) | |
parent | a2186d263aa8927a47fdb9f3a23ad39841b64b33 (diff) | |
download | online_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.py | 25 |
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 |