summaryrefslogtreecommitdiff
path: root/exam/management/commands
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-23 14:58:16 +0530
committerPrabhu Ramachandran2011-11-23 14:58:16 +0530
commit30f56443790841901f15b5ab435f97fba1c81d85 (patch)
tree006abd7932ca468661f5481e998c6a79f3058ecd /exam/management/commands
parentba2097a382b581dacced5cb9bd70087396a054f0 (diff)
downloadonline_test-30f56443790841901f15b5ab435f97fba1c81d85.tar.gz
online_test-30f56443790841901f15b5ab435f97fba1c81d85.tar.bz2
online_test-30f56443790841901f15b5ab435f97fba1c81d85.zip
ENH: Cleanup and adding error/comments for answers
Adding error and marks field to each answer. Adding a new comment field to the question paper and also a profile field for convenience. Changing the views, templates and dump scripts to use the models rather than Python code. This cleans things up a lot more. The user data logged and printed is also way more comprehensive, paving the way for easy online grading as well in the next phase of changes.
Diffstat (limited to 'exam/management/commands')
-rw-r--r--exam/management/commands/dump_user_data.py63
-rw-r--r--exam/management/commands/results2csv.py27
2 files changed, 54 insertions, 36 deletions
diff --git a/exam/management/commands/dump_user_data.py b/exam/management/commands/dump_user_data.py
index f14e144..f081565 100644
--- a/exam/management/commands/dump_user_data.py
+++ b/exam/management/commands/dump_user_data.py
@@ -8,34 +8,45 @@ from exam.models import User
data_template = Template('''\
===============================================================================
-Data for {{ user_data.name.title }} ({{ user_data.username }})
+Data for {{ data.user.get_full_name.title }} ({{ data.user.username }})
-Name: {{ user_data.name.title }}
-Username: {{ user_data.username }}
-Roll number: {{ user_data.rollno }}
-Email: {{ user_data.email }}
-Position: {{ user_data.position }}
-Department: {{ user_data.department }}
-Institute: {{ user_data.institute }}
-Date joined: {{ user_data.date_joined }}
-Last login: {{ user_data.last_login }}
-{% for paper in user_data.papers %}
-Paper: {{ paper.name }}
------------------------------------------
-Total marks: {{ paper.total }}
-Questions correctly answered: {{ paper.answered }}
-Total attempts at questions: {{ paper.attempts }}
-Start time: {{ paper.start_time }}
-User IP address: {{ paper.user_ip }}
-{% if paper.answers %}
+Name: {{ data.user.get_full_name.title }}
+Username: {{ data.user.username }}
+{% if data.profile %}\
+Roll number: {{ data.profile.roll_number }}
+Position: {{ data.profile.position }}
+Department: {{ data.profile.department }}
+Institute: {{ data.profile.institute }}
+{% endif %}\
+Email: {{ data.user.email }}
+Date joined: {{ data.user.date_joined }}
+Last login: {{ data.user.last_login }}
+{% for paper in data.papers %}
+Paper: {{ paper.quiz.description }}
+---------------------------------------
+Marks obtained: {{ paper.get_total_marks }}
+Questions correctly answered: {{ paper.get_answered_str }}
+Total attempts at questions: {{ paper.answers.count }}
+Start time: {{ paper.start_time }}
+User IP address: {{ paper.user_ip }}
+{% if paper.answers.count %}
Answers
-------
-{% for question, answer in paper.answers.items %}
-Question: {{ question }}
-{{ answer|safe }}
-{% endfor %} \
-{% endif %} {# if paper.answers #} \
-{% endfor %} {# for paper in user_data.papers #}
+{% for question, answers in paper.get_question_answers.items %}
+Question: {{ question.id }}. {{ question.summary }} (Points: {{ question.points }})
+{% for answer in answers %}\
+###############################################################################
+{{ answer.answer|safe }}
+# Autocheck: {{ answer.error|safe }}
+# Marks: {{ answer.marks }}
+{% endfor %}{# for answer in answers #}\
+{% endfor %}{# for question, answers ... #}\
+
+Teacher comments
+-----------------
+{{ paper.comments|default:"None" }}
+{% endif %}{# if paper.answers.count #}\
+{% endfor %}{# for paper in data.papers #}
''')
@@ -60,7 +71,7 @@ def dump_user_data(unames, stdout):
for user in users:
data = get_user_data(user.username)
- context = Context({'user_data': data})
+ context = Context({'data': data})
result = data_template.render(context)
stdout.write(result)
diff --git a/exam/management/commands/results2csv.py b/exam/management/commands/results2csv.py
index f1da1a8..2993745 100644
--- a/exam/management/commands/results2csv.py
+++ b/exam/management/commands/results2csv.py
@@ -7,16 +7,22 @@ from django.core.management.base import BaseCommand
from django.template import Template, Context
# Local imports.
-from exam.views import get_quiz_data
-from exam.models import Quiz
+from exam.models import Quiz, QuestionPaper
result_template = Template('''\
-"name","username","rollno","email","answered","total","attempts","position","department","institute"
-{% for paper in paper_list %}\
-"{{ paper.name }}","{{ paper.username }}","{{ paper.rollno }}",\
-"{{ paper.email }}","{{ paper.answered }}",{{ paper.total }},\
-{{ paper.attempts }},"{{ paper.position }}",\
-"{{ paper.department }}","{{ paper.institute }}"
+"name","username","rollno","email","answered","total","attempts","position",\
+"department","institute"
+{% for paper in papers %}\
+"{{ paper.user.get_full_name.title }}",\
+"{{ paper.user.username }}",\
+"{{ paper.profile.roll_number }}",\
+"{{ paper.user.email }}",\
+"{{ paper.get_answered_str }}",\
+{{ paper.get_total_marks }},\
+{{ paper.answers.count }},\
+"{{ paper.profile.position }}",\
+"{{ paper.profile.department }}",\
+"{{ paper.profile.institute }}"
{% endfor %}\
''')
@@ -39,12 +45,13 @@ def results2csv(filename, stdout):
else:
quiz = qs[0]
- paper_list = get_quiz_data(quiz.id)
+ papers = QuestionPaper.objects.filter(quiz=quiz,
+ user__profile__isnull=False)
stdout.write("Saving results of %s to %s ... "%(quiz.description,
basename(filename)))
# Render the data and write it out.
f = open(filename, 'w')
- context = Context({'paper_list': paper_list})
+ context = Context({'papers': papers})
f.write(result_template.render(context))
f.close()