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 | |
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
-rw-r--r-- | yaksh/models.py | 13 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 1 | ||||
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 13 | ||||
-rw-r--r-- | yaksh/templates/yaksh/user_data.html | 9 | ||||
-rw-r--r-- | yaksh/templates/yaksh/view_answerpaper.html | 24 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 37 |
7 files changed, 88 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index ad61872..8d4f930 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -221,6 +221,12 @@ class Course(models.Model): success = False return success + def get_only_students(self): + teachers = list(self.teachers.all().values_list("id", flat=True)) + teachers.append(self.creator.id) + students = self.students.exclude(id__in=teachers) + return students + def __str__(self): return self.name @@ -900,6 +906,13 @@ class AnswerPaperManager(models.Manager): data['questionpaperid'] = questionpaper_id return data + def get_user_best_of_attempts_marks(self, quiz, user_id): + best_attempt = 0.0 + papers = self.filter(question_paper__quiz=quiz, + user=user_id).values("marks_obtained") + if papers: + best_attempt = max([marks["marks_obtained"] for marks in papers]) + return best_attempt ############################################################################### class AnswerPaper(models.Model): diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index ecd3a13..b7cc2e1 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -79,6 +79,7 @@ </div> <br/> <button class="btn btn-primary pull-right"type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz/{{course.id}}/");'>Add New Quiz</button> + <p><a href="{{URL_ROOT}}/exam/manage/courses/download_course_csv/{{course.id}}">Download CSV</a></p> </div> </div> <br><br> diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index ec8c244..b2ee7bc 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -101,7 +101,7 @@ Status : <b style="color: green;"> Passed </b><br/> {% with answers|last as answer %} <tr> <td>{{ question.id }}</td> - <td>{{ answer.marks }}</td> + <td>{{ answer.answer.marks }}</td> </tr> {% endwith %} {% endfor %} @@ -130,7 +130,14 @@ Status : <b style="color: green;"> Passed </b><br/> {% if question.type == "mcq" or question.type == "mcc" %} <h5> <u>Choices:</u></h5> {% for testcase in question.get_test_cases %} - <br/><strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> + {% if testcase.correct %} + <br/> + <strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> + <span class="label label-success"> Correct </span> + {% else %} + <br/><strong> + {{ forloop.counter }}. {{ testcase.options|safe }}</strong> + {% endif %} {% endfor %} {% else %} <h5> <u>Test cases: </u></h5> @@ -159,7 +166,7 @@ Status : <b style="color: green;"> Passed </b><br/> {% with answers|last as answer %} Marks: <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" - value="{{ answer.0.marks }}"><br><br> + value="{{ answer.answer.marks }}"><br><br> {% endwith %} <hr/> {% endfor %} {# for question, answers ... #} diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index 9c11dd9..9cc2372 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -66,7 +66,14 @@ User IP address: {{ paper.user_ip }} {% if question.type == "mcq" or question.type == "mcc" %} <h5> <u>Choices:</u></h5> {% for testcase in question.get_test_cases %} - <br/><strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> + {% if testcase.correct %} + <br/> + <strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> + <span class="label label-success"> Correct </span> + {% else %} + <br/><strong> + {{ forloop.counter }}. {{ testcase.options|safe }}</strong> + {% endif %} {% endfor %} {% else %} <h5> <u>Test cases: </u></h5> diff --git a/yaksh/templates/yaksh/view_answerpaper.html b/yaksh/templates/yaksh/view_answerpaper.html index cd607dd..5240278 100644 --- a/yaksh/templates/yaksh/view_answerpaper.html +++ b/yaksh/templates/yaksh/view_answerpaper.html @@ -40,11 +40,23 @@ <div class="panel-body"> <h5><u>Question:</u></h5> <strong>{{ question.description|safe }}</strong> {% if question.type == "mcq" or question.type == "mcc" %} - <h5> <u>Choices:</u></h5> - {% for testcase in question.get_test_cases %} - <br/><strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> - {% endfor %} - {%endif%} + <h5> <u>Choices:</u></h5> + {% for testcase in question.get_test_cases %} + {% if testcase.correct %} + <br/> + <strong>{{ forloop.counter }}. {{ testcase.options|safe }}</strong> + <span class="label label-success"> Correct</span> + {% else %} + <br/><strong> + {{ forloop.counter }}. {{ testcase.options|safe }}</strong> + {% endif %} + {% endfor %} + {% else %} + <h5> <u>Test cases: </u></h5> + {% for testcase in question.get_test_cases %} + <br/><strong>{{ forloop.counter }}. {{ testcase }}</strong> + {% endfor %} + {% endif %} </div> </div> @@ -78,7 +90,7 @@ {% endfor %} {% endif %} {% with answers|last as answer %} - <p><em><mark>Obtained Marks: {{answer.marks}}</mark></em> </p> + <p><em><mark>Obtained Marks: {{answer.answer.marks}}</mark></em> </p> {% endwith %} <hr> {% endfor %} {# for question, answers ... #} diff --git a/yaksh/urls.py b/yaksh/urls.py index bdf14ea..629f8f5 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -113,4 +113,6 @@ urlpatterns += [ views.regrade, name='regrade'), url(r'^manage/(?P<mode>[\w\-]+)/(?P<quiz_id>\d+)/$', views.test_quiz), url(r'^manage/create_demo_course/$', views.create_demo_course), + url(r'^manage/courses/download_course_csv/(?P<course_id>\d+)/$', + views.download_course_csv), ] 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 |