class Essay_Question(Question):
- def check_if_correct(self):
+ def check_if_correct(self, guess):
return False
def get_answers(self):
explanation="Wow!")
def test_always_false(self):
- self.assertEqual(self.essay.check_if_correct(), False)
+ self.assertEqual(self.essay.check_if_correct('spam'), False)
self.assertEqual(self.essay.get_answers(), False)
self.assertEqual(self.essay.get_answers_list(), False)
from .models import Quiz, Category, Progress, Question
from multichoice.models import MCQuestion, Answer
from true_false.models import TF_Question
-
+from essay.models import Essay_Question
class AnswerInline(admin.TabularInline):
model = Answer
search_fields = ('content', 'explanation')
filter_horizontal = ('quiz',)
+class EssayQuestionAdmin(admin.ModelAdmin):
+ list_display = ('content', 'category', )
+ list_filter = ('category',)
+ fields = ('content', 'category', 'quiz', 'explanation', )
+ search_fields = ('content', 'explanation')
+ filter_horizontal = ('quiz',)
+
admin.site.register(Quiz, QuizAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(MCQuestion, MCQuestionAdmin)
admin.site.register(Progress, ProgressAdmin)
admin.site.register(TF_Question, TFQuestionAdmin)
+admin.site.register(Essay_Question, EssayQuestionAdmin)
default=False,
help_text="If yes, the result of each"
" attempt by a user will be"
- " stored.")
+ " stored. Necessary for"
+ " marking.")
single_attempt = models.BooleanField(blank=False,
default=False,
current = json.loads(self.user_answers)
current[question.id] = guess
self.user_answers = json.dumps(current)
+ self.save()
def questions_with_user_answers(self):
output = {}
user_answers = json.loads(self.user_answers)
- questions = self.quiz.question_set.all().select_subclasses()
- for question in questions:
+ for question in self.quiz.question_set.all().select_subclasses():
output[question] = user_answers[unicode(question.id)]
return output
-{% if user_was_incorrect %}
- <div class="alert alert-error">
- <strong>You answered the above question incorrectly</strong>
- </div>
-{% endif %}
+{% if previous.answers %}
+
+ {% if user_was_incorrect %}
+ <div class="alert alert-error">
+ <strong>You answered the above question incorrectly</strong>
+ </div>
+ {% endif %}
-<table class="table table-striped table-bordered">
- <tbody>
- {% for answer in previous.answers %}
- {% if answer.correct %}
- <tr class="success">
- <td>{{ answer.content }}</td>
- <td><strong>This is the correct answer</strong></td>
- {% else %}
- <tr>
- <td>{{ answer.content }}</td>
- <td>
- {% if previous.question_type.MCQuestion %}
- {% if answer.id|add:"0" == previous.previous_answer|add:"0" %}
- This was your answer.
- {% endif %}
- {% endif %}
- </td>
- {% endif %}
- </tr>
- {% endfor %}
- </tbody>
-</table>
+ <table class="table table-striped table-bordered">
+ <tbody>
+ {% for answer in previous.answers %}
+ {% if answer.correct %}
+ <tr class="success">
+ <td>{{ answer.content }}</td>
+ <td><strong>This is the correct answer</strong></td>
+ {% else %}
+ <tr>
+ <td>{{ answer.content }}</td>
+ <td>
+ {% if previous.question_type.MCQuestion %}
+ {% if answer.id|add:"0" == previous.previous_answer|add:"0" %}
+ This was your answer.
+ {% endif %}
+ {% endif %}
+ </td>
+ {% endif %}
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+{% endif %}
<ul class="list-group">
- {{ form }}
- <!-- {% for answer in form.answers %} -->
-<!-- <li class="list-group-item"> -->
- <!-- {{ answer }} -->
-<!-- </li> -->
-<!-- {% endfor %} -->
+ {% for answer in form.answers %}
+ <li class="list-group-item">
+ {{ answer }}
+ </li>
+ {% endfor %}
</ul>
<input type="submit" value="Check" class="btn btn-large btn-block btn-warning" >
<thead>
<tr>
<th>Question</th>
+ <th>User answer</th>
<th></th>
</tr>
</thead>
-
+n
<tbody>
-{% for question in questions %}
+{% for question, user_name in questions.items %}
<tr>
<td>{{ question.content }}</td>
+ <td>{{ user_name }}</td>
<td>
{% if question.id in incorrect %}
<p>incorrect</p>
{% block content %}
- {% if previous %}
+ {% if previous.answers %}
<p class="muted"><small>The previous question:</small></p>
<p>{{ previous.previous_question }}</p>
sitting2.complete = True
sitting2.save()
+ sitting1.add_user_answer(self.question1, '123')
+ # sitting1.add_user_answer(self.question2, '456')
+
def test_paper_marking_list_view(self):
response = self.client.get('/marking/')
self.assertRedirects(response, 'accounts/login/?next=/marking/',
def test_paper_marking_detail_view(self):
self.client.login(username='yoda', password='use_d@_force')
response = self.client.get('/marking/1/')
+
self.assertContains(response, 'test quiz 1')
self.assertContains(response, 'squawk')
self.assertContains(response, 'incorrect')
from .forms import QuestionForm, EssayForm
from .models import Quiz, Category, Progress, Sitting, Question
-from Essay_Question.models import Essay_Question
+from essay.models import Essay_Question
+
class QuizMarkerMixin(object):
@method_decorator(login_required)
def get_context_data(self, **kwargs):
context = super(QuizMarkingDetail, self).get_context_data(**kwargs)
- context['questions'] = context['object'].quiz.question_set.all()
+ # context['questions'] = context['object'].quiz.question_set.all()
+ context['questions'] = context['object'].questions_with_user_answers()
context['incorrect'] = context['object'].get_incorrect_questions
return context
self.quiz = get_object_or_404(Quiz, url=self.kwargs['quiz_name'])
if request.user.is_authenticated() is True:
- self.sitting = user_sitting(self.request, self.quiz)
+ self.sitting = user_sitting(request, self.quiz)
else:
- self.sitting = anon_load_sitting(self.request, self.quiz)
+ self.sitting = anon_load_sitting(request, self.quiz)
if self.sitting is False:
return render(request, 'single_complete.html')
+ return super(QuizTake, self).dispatch(request, *args, **kwargs)
+
+ def get_form(self, form_class):
if self.request.user.is_authenticated() is True:
self.question = self.sitting.get_first_question()
else:
self.question = anon_next_question(self)
- return super(QuizTake, self).dispatch(self.request, *args, **kwargs)
-
- def get_form(self, form_class):
if self.question.__class__ is Essay_Question:
form_class = EssayForm
+
return form_class(**self.get_form_kwargs())
def get_form_kwargs(self):
kwargs = super(QuizTake, self).get_form_kwargs()
+
return dict(kwargs, question=self.question)
def form_valid(self, form):
else:
self.previous = {}
+ self.sitting.add_user_answer(self.question, guess)
self.sitting.remove_first_question()
else:
self.previous = {}
self.request.session[self.quiz.anon_q_list()] =\
- (self.request.session[self.quiz.anon_q_list()][1:])
+ self.request.session[self.quiz.anon_q_list()][1:]
def anon_session_score(session, to_add=0, possible=0):