]> git.parisson.com Git - teleforma.git/commitdiff
Made file mandatory, added error messages on forms, minor fixes
authorGael Le Mignot <gael@pilotsystems.net>
Wed, 12 Dec 2018 13:58:46 +0000 (14:58 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Wed, 12 Dec 2018 13:58:46 +0000 (14:58 +0100)
teleforma/exam/forms.py
teleforma/exam/templates/exam/score_form.html
teleforma/exam/templates/exam/script_form.html
teleforma/exam/views.py

index 736970ed6d24b61de4d709c22b0d7d17ca849b02..b7c8183442997fa975198fca2389ac479a8cdd44 100644 (file)
@@ -18,6 +18,7 @@ class ScriptForm(ModelForm):
         nb = period.nb_script or settings.TELEFORMA_EXAM_MAX_SESSIONS
         self.fields['session'] = forms.ChoiceField(choices = get_n_choices(nb + 1),
                                                    validators = [ validate_session(nb) ])
+        self.fields['file'].required = True
 
     class Meta:
         model = Script
@@ -28,4 +29,7 @@ class ScriptForm(ModelForm):
 
 
 class ScoreForm(ScriptForm):
-    pass
+    def __init__(self, *args, **kwargs):
+        super(ScoreForm, self).__init__(*args, **kwargs)
+        self.fields['file'].required = False
+        self.fields['score'].required = True
index b6bd3c03f369a544256175c12cb0a8514fae7921..c420b9f1cd839a4d7d03afcdc4da3af5447f806e 100644 (file)
         {% if not field.html_name in create_fields %}
             <td>{{ field.label_tag.as_hidden }}</td><td>{{ field.as_hidden }}</td>
         {% else %}
-            <td>{{ field.label_tag }}:</td><td> {{ field }}</td>
+        <td>
+          {{ field.label_tag }}:
+        </td>
+        <td>
+          {{ field }}
+        </td>
+        <td>
+          {% for error in field.errors %}
+          <div class="error">
+            {{ error|escape }}
+          </div>
+          {% endfor %}          
+        </td>
         {% endif %}
         </tr>
        {% endfor %}
index d9fc10965f94a560650e735848812c2bf71fd5f4..e038a7016948ce2f3cb9beafaec83f29cff475eb 100644 (file)
         {% if not field.html_name in create_fields %}
             <td>{{ field.label_tag.as_hidden }}</td><td>{{ field.as_hidden }}</td>
         {% else %}
-            <td>{{ field.label_tag }}:</td><td> {{ field }}</td>
+        <td>
+          {{ field.label_tag }}:
+        </td>
+        <td>
+          {{ field }}
+        </td>
+        <td>
+          {% for error in field.errors %}
+          <div class="error">
+            {{ error|escape }}
+          </div>
+          {% endfor %}          
+        </td>
         {% endif %}
         </tr>
        {% endfor %}
index 5d8304cbbe1ecc4e18da4dddc300cd2ffb8aedcd..6215a0725d4b550debea20445b84c652c3157ad9 100755 (executable)
@@ -19,6 +19,12 @@ PROFESSOR = 2
 
 class ScriptMixinView(View):
 
+    def get_course_pk_list(self):
+        """
+        Get the list of pk of courses current user is allowed to access
+        """
+        return [c['course'].id for c in get_courses(self.request.user) if c['course'].has_exam_scripts]
+        
     def get_context_data(self, **kwargs):
         context = super(ScriptMixinView, self).get_context_data(**kwargs)
         self.period = Period.objects.get(id=self.kwargs['period_id'])
@@ -27,8 +33,10 @@ class ScriptMixinView(View):
         self.nb_script = self.period.nb_script or settings.TELEFORMA_EXAM_MAX_SESSIONS
         if getattr(settings, 'TELEFORMA_EXAM_SCRIPT_UPLOAD', True) and self.period.date_exam_end:
             upload = datetime.datetime.now() <= self.period.date_exam_end
-            if Script.objects.filter(period = self.period,
-                                     author = self.request.user).count() >= self.nb_script:
+            cur_scripts = Script.objects.filter(period = self.period,
+                                                author = self.request.user).count()
+            allowed_scripts = self.nb_script * len(self.get_course_pk_list())
+            if cur_scripts >= allowed_scripts:
                 upload = False
             context['upload'] = upload
         else:
@@ -238,7 +246,7 @@ class ScriptCreateView(ScriptMixinView, CreateView):
     def get_context_data(self, **kwargs):    
         context = super(ScriptCreateView, self).get_context_data(**kwargs)
         context['create_fields'] = ['course', 'session', 'type', 'file' ]
-        course_pk_list = [c['course'].id for c in get_courses(self.request.user) if c['course'].has_exam_scripts]
+        course_pk_list = self.get_course_pk_list()
         context['form'].fields['course'].queryset = Course.objects.filter(pk__in=course_pk_list)
         return context
 
@@ -367,7 +375,7 @@ class ScriptsScoreCourseView(ScriptsScoreAllView):
 class ScoreCreateView(ScriptCreateView):
 
     template_name='exam/score_form.html'
-    form_class = ScriptForm
+    form_class = ScoreForm
 
     def get_success_url(self):
         period = Period.objects.get(id=self.kwargs['period_id'])