model = Question
# exclude = ['user', 'question', 'status', 'validated', 'date_submitted']
+
class AnswerForm(ModelForm):
def __init__(self, *args, **kwargs):
model = Answer
exclude = ['user', 'question', 'validated', 'date_submitted', 'date_validated']
hidden_fields = ['status']
-
-
-
# "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy,
-# modify and redistribute granted by the license, users are provided only
+# modify and redistribute granted by th e license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
return self.date_modified - self.date
else:
return None
+
+
+class QuizValidation(models.Model):
+
+ user = models.ForeignKey(User, related_name="quiz_validation", verbose_name=_('user'))
+ quiz = models.ForeignKey(Quiz, related_name="quiz_validation", verbose_name=_('quiz'),
+ blank=True, null=True, on_delete=models.SET_NULL)
+ validated = models.BooleanField(_('validated'))
+ date_validated = models.DateTimeField(_('date validated'), auto_now_add=True, null=True)
+
+ def __unicode__(self):
+ return ' - '.join([unicode(self.quiz), self.user.username, unicode(self.date_submitted)])
+
+ def validate(self):
+ self.validated = True
+ self.save()
+
+ def reject(self):
+ self.validated = False
+ self.save()
+
+ class Meta(MetaCore):
+ db_table = app_label + '_' + 'quiz_validation'
+ verbose_name = _('Quiz validation')
+ ordering = ['-date_validated']
<table class="listing" width="100%">
<tbody>
<tr>
- <td class="border-top" width="35%">
+ <td class="border-top" width="95%">
{% if seminar.quiz %}
<a href="{% url teleforma-quiz seminar.id seminar.quiz.url %}">{{ seminar.quiz.title }}</a>
{% endif %}
</td>
+ <td width="5%" align="center">
+ {% if quiz|quiz_validated:user %}
+ <img src="{{ STATIC_URL }}telemeta/images/ok.png" style="vertical-align:middle" alt="" title="{% trans "Validated" %}" />
+ {% endif %}
+ </td>
</tr>
</tbody>
</table>
else:
return ''
+@register.filter
+def quiz_validated(quiz, user):
+ validations = QuizValidation.objects.filter(quiz=quiz, user=user, validated=True)
+ if validations:
+ return validations[0].date_validated
+ else:
+ return ''
+
@register.filter
def summary(text, N):
t = text[:N]
return int(progress[0]*100.0/progress[1])
else:
return 100
-
-
return context
def final_result_user(self):
+ user = self.get_user()
self.seminar = self.quiz.seminar.all()[0]
+ validation_form = QuizValidationForm(user=user, seminar=self.seminar)
+
results = {
'quiz': self.quiz,
'score': self.sitting.get_current_score,
'sitting': self.sitting,
'previous': self.previous,
'seminar': self.seminar,
+ 'form': validation_form,
}
self.sitting.mark_quiz_complete()
if self.quiz.exam_paper is False:
self.sitting.delete()
- return render(self.request, 'quiz/result.html', results)
+ if self.sitting.get_percent_correct >= self.quiz.pass_mark:
+ validation = QuizValidation(user=user, quiz=self.seminar.quiz, validated=True)
+ validation.save()
+ return render(self.request, 'quiz/result.html', results)