diff options
author | Prabhu Ramachandran | 2017-01-18 16:13:53 +0530 |
---|---|---|
committer | GitHub | 2017-01-18 16:13:53 +0530 |
commit | e75d5e67bc129c0d55ce94496ef4636c80dba0eb (patch) | |
tree | 9e610b5436165458be16ae7aa45857b292643bd8 /yaksh/views.py | |
parent | c3205b84ebd1796d98e140952802cdc0baad19a7 (diff) | |
parent | 1f66352c1f26eb0688ae0884781e6a6a66d43b18 (diff) | |
download | online_test-e75d5e67bc129c0d55ce94496ef4636c80dba0eb.tar.gz online_test-e75d5e67bc129c0d55ce94496ef4636c80dba0eb.tar.bz2 online_test-e75d5e67bc129c0d55ce94496ef4636c80dba0eb.zip |
Merge pull request #181 from maheshgudi/mcq_bugfix
Course CSV Download and Correct option(s) in view answerpaper
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 4be2fc1..1dc7ea2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1001,7 +1001,6 @@ def download_csv(request, questionpaper_id): writer.writerow(row) return response - @login_required def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): """Present an interface with which we can easily grade a user's papers @@ -1282,3 +1281,39 @@ def regrade(request, course_id, question_id=None, answerpaper_id=None, questionp answerpaper = get_object_or_404(AnswerPaper, pk=answerpaper_id) details.append(answerpaper.regrade(question_id)) return grader(request, extra_context={'details': details}) + +@login_required +def download_course_csv(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('The question paper does not belong to your course') + students = course.get_only_students().values("id", "first_name", "last_name") + quizzes = Quiz.objects.filter(course=course, is_trial=False) + + for student in students: + total_course_marks = 0.0 + user_course_marks = 0.0 + for quiz in quizzes: + quiz_best_marks = AnswerPaper.objects.get_user_best_of_attempts_marks\ + (quiz, student["id"]) + user_course_marks += quiz_best_marks + total_course_marks += quiz.questionpaper_set.values_list\ + ("total_marks", flat=True)[0] + student["{}".format(quiz.description)] = quiz_best_marks + student["total_scored"] = user_course_marks + student["out_of"] = total_course_marks + + + response = HttpResponse(content_type='text/csv') + response['Content-Disposition'] = 'attachment; filename="{0}.csv"'.format( + (course.name).lower().replace('.', '')) + header = ['first_name', 'last_name']+[quiz.description for quiz in quizzes]\ + + ['total_scored', 'out_of'] + writer = csv.DictWriter(response,fieldnames=header, extrasaction='ignore') + writer.writeheader() + for student in students: + writer.writerow(student) + return response |