Repository: e-valuation/EvaP

Issue:
Form errors not shown
When choosing the start date to be after the end date in a course edit form and trying to save the form, an error occurs but the error message is not shown and the date fields are highlighted in green.
Form errors not shown
When choosing the start date to be after the end date in a course edit form and trying to save the form, an error occurs but the error message is not shown and the date fields are highlighted in green.


Discussion:

Resolving patch:
diff --git a/evap/contributor/forms.py b/evap/contributor/forms.py
--- a/evap/contributor/forms.py
+++ b/evap/contributor/forms.py
@@ -1,15 +1,13 @@
-import logging
 import datetime
+import logging
 
 from django import forms
+from django.db.models import Q
 from django.forms.widgets import CheckboxSelectMultiple
 from django.utils.translation import ugettext_lazy as _
-from django.core.exceptions import ValidationError
-from django.db.models import Q
-
-from evap.evaluation.models import Course, UserProfile, Questionnaire, Semester
-from evap.staff.forms import ContributionForm
 from evap.evaluation.forms import UserModelMultipleChoiceField
+from evap.evaluation.models import Course, Questionnaire, Semester, UserProfile
+from evap.staff.forms import ContributionForm
 
 logger = logging.getLogger(__name__)
 
@@ -43,7 +41,8 @@ def clean(self):
         vote_end_date = self.cleaned_data.get('vote_end_date')
         if vote_start_date and vote_end_date:
             if vote_start_date >= vote_end_date:
-                raise ValidationError(_("The first day of evaluation must be before the last one."))
+                self.add_error("vote_start_date", "")
+                self.add_error("vote_end_date", _("The first day of evaluation must be before the last one."))
 
     def clean_vote_start_date(self):
         vote_start_date = self.cleaned_data.get('vote_start_date')
diff --git a/evap/staff/forms.py b/evap/staff/forms.py
--- a/evap/staff/forms.py
+++ b/evap/staff/forms.py
@@ -1,19 +1,21 @@
 import logging
 
 from django import forms
+from django.contrib.auth.models import Group
+from django.core.exceptions import SuspiciousOperation, ValidationError
 from django.db.models import Q
-from django.core.exceptions import SuspiciousOperation
 from django.forms.models import BaseInlineFormSet
-from django.utils.translation import ugettext_lazy as _
-from django.utils.text import normalize_newlines
-from django.http.request import QueryDict
-from django.core.exceptions import ValidationError
-from django.contrib.auth.models import Group
-
 from django.forms.widgets import CheckboxSelectMultiple
-from evap.evaluation.models import Contribution, Course, Question, Questionnaire, Semester, UserProfile, FaqSection, \
-                                   FaqQuestion, EmailTemplate, TextAnswer, Degree, RatingAnswerCounter, CourseType
-from evap.evaluation.forms import UserModelChoiceField, UserModelMultipleChoiceField
+from django.http.request import QueryDict
+from django.utils.text import normalize_newlines
+from django.utils.translation import ugettext_lazy as _
+from evap.evaluation.forms import (UserModelChoiceField,
+                                   UserModelMultipleChoiceField)
+from evap.evaluation.models import (Contribution, Course, CourseType, Degree,
+                                    EmailTemplate, FaqQuestion, FaqSection,
+                                    Question, Questionnaire,
+                                    RatingAnswerCounter, Semester, TextAnswer,
+                                    UserProfile)
 
 logger = logging.getLogger(__name__)
 
@@ -158,7 +160,8 @@ def clean(self):
         vote_end_date = self.cleaned_data.get('vote_end_date')
         if vote_start_date and vote_end_date:
             if vote_start_date >= vote_end_date:
-                raise ValidationError(_("The first day of evaluation must be before the last one."))
+                self.add_error("vote_start_date", "")
+                self.add_error("vote_end_date", _("The first day of evaluation must be before the last one."))
 
     def save(self, user, *args, **kw):
         self.instance.last_modified_user = user


Test patch: