]> git.parisson.com Git - teleforma.git/commitdiff
add quiz validation workflow
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 22 Jan 2016 13:08:58 +0000 (14:08 +0100)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Fri, 22 Jan 2016 13:08:58 +0000 (14:08 +0100)
teleforma/forms.py
teleforma/models/pro.py
teleforma/templates/teleforma/inc/quiz_list.html
teleforma/templatetags/teleforma_tags.py
teleforma/views/pro.py

index a5380d7a10bc5b3891334d3d500cc3e62e031aaf..5333366aba5c690525862ceecda7955287dd7951 100644 (file)
@@ -16,6 +16,7 @@ class QuestionForm(ModelForm):
         model = Question
         # exclude = ['user', 'question', 'status', 'validated', 'date_submitted']
 
+
 class AnswerForm(ModelForm):
 
     def __init__(self, *args, **kwargs):
@@ -29,6 +30,3 @@ class AnswerForm(ModelForm):
         model = Answer
         exclude = ['user', 'question', 'validated', 'date_submitted', 'date_validated']
         hidden_fields = ['status']
-
-
-
index c5b5557c8b965d8d017fa2dd6487624474067e03..dd70707d9c5f2e005a7e869a758bdc63909a81a7 100755 (executable)
@@ -12,7 +12,7 @@
 # "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.
@@ -331,3 +331,28 @@ class SeminarRevision(models.Model):
             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']
index 5511c86ad65f2cd032278863e42c8ec473279318..144fff79239bc85c325acecf31069c7b3a38ee94 100644 (file)
@@ -4,11 +4,16 @@
 <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>
index fca28a2f77b794701c165828da289c236cbe0b73..60a9bb557cfed4849bf70c558479af2e414bf780 100644 (file)
@@ -241,6 +241,14 @@ def validated(question, user):
     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]
@@ -328,5 +336,3 @@ def quiz_progress(progress):
         return int(progress[0]*100.0/progress[1])
     else:
         return 100
-
-
index 75b3cffb27e8c9edc35a3ee7ce42454d5ca9fade..2d63412ca75ef520bdbd1abde53d18378133273f 100644 (file)
@@ -788,7 +788,10 @@ class QuizQuestionView(SeminarAccessMixin, SeminarRevisionMixin, QuizTake):
         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,
@@ -797,6 +800,7 @@ class QuizQuestionView(SeminarAccessMixin, SeminarRevisionMixin, QuizTake):
             'sitting': self.sitting,
             'previous': self.previous,
             'seminar': self.seminar,
+            'form': validation_form,
         }
 
         self.sitting.mark_quiz_complete()
@@ -810,5 +814,8 @@ class QuizQuestionView(SeminarAccessMixin, SeminarRevisionMixin, QuizTake):
         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)