From 8e9ab89efac7dd0962a913f098b0f8199b0c07c6 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Wed, 21 Aug 2024 14:32:47 +0200 Subject: [PATCH 01/14] fix: bug with double error message --- studies/forms.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/studies/forms.py b/studies/forms.py index 3b364dd16..8f69e5ed0 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -225,9 +225,11 @@ def clean(self): - at least one of the fields has to be checked """ cleaned_data = super(StudyDesignForm, self).clean() + #This solution is a bit funky, but by using add_error(), it appends our + #error msg to a built-in required error message. if not cleaned_data: - msg = _("Je dient minstens één van de opties te selecteren") - self.add_error("study_types", forms.ValidationError(msg, code="required")) + msg = _("Je dient minstens één van de opties te selecteren.") + self.errors["study_types"]=[msg] class StudyConsentForm(ConditionalModelForm): From 73eab9894515efa180344f96e3ad6a69cfcb731f Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Wed, 21 Aug 2024 14:33:38 +0200 Subject: [PATCH 02/14] feat: create block for form rendering --- main/templates/base/fetc_form_base.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main/templates/base/fetc_form_base.html b/main/templates/base/fetc_form_base.html index b8db75a29..2b6f026ba 100644 --- a/main/templates/base/fetc_form_base.html +++ b/main/templates/base/fetc_form_base.html @@ -31,7 +31,10 @@ {% endblock %} - {{ form }} + {% block auto-form-render %} + {{ form }} + {% endblock %} + {% block form-buttons %} {% block post-form-pre-buttons %}{% endblock %} From b563da50903e08cd961ffb7483eda2891ebd80f7 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Wed, 21 Aug 2024 14:34:32 +0200 Subject: [PATCH 03/14] feat: Ensure form isnt rendered to avoid ugly error message --- tasks/templates/tasks/session_overview.html | 4 ++++ tasks/templates/tasks/session_start.html | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tasks/templates/tasks/session_overview.html b/tasks/templates/tasks/session_overview.html index d8ddf93d7..bb43e4432 100644 --- a/tasks/templates/tasks/session_overview.html +++ b/tasks/templates/tasks/session_overview.html @@ -16,6 +16,10 @@

{% trans "Overzicht van alle sessies en taken" %}

{% include "tasks/session_list.html" %} {% endblock %} +{% block auto-form-render %} + +{% endblock %} + {% block form-buttons %} {% include "base/form_buttons.html" %} {% endblock %} diff --git a/tasks/templates/tasks/session_start.html b/tasks/templates/tasks/session_start.html index 8e4007bb8..9a86cc093 100644 --- a/tasks/templates/tasks/session_start.html +++ b/tasks/templates/tasks/session_start.html @@ -31,3 +31,7 @@

{% trans "Het takenonderzoek en/of interviews" %}

{% endblocktrans %}

{% endblock %} + +{% block auto-form-render %} + +{% endblock %} From 074d1d7c81f5881ba44841e5bbf3b1113c0c27d6 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Wed, 21 Aug 2024 14:35:06 +0200 Subject: [PATCH 04/14] fix: slight UI improvements to task_list and session_list --- tasks/templates/tasks/session_list.html | 4 ++-- tasks/templates/tasks/task_list.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/templates/tasks/session_list.html b/tasks/templates/tasks/session_list.html index 5992d9942..e396bdcde 100644 --- a/tasks/templates/tasks/session_list.html +++ b/tasks/templates/tasks/session_list.html @@ -32,10 +32,10 @@

{% include "tasks/task_list.html" %} {% empty %} - + {% endfor %} {% if can_edit_sessions %} -
+
{% trans "Nieuwe sessie tevoegen" %} diff --git a/tasks/templates/tasks/task_list.html b/tasks/templates/tasks/task_list.html index 775eaf635..2c3fb7239 100644 --- a/tasks/templates/tasks/task_list.html +++ b/tasks/templates/tasks/task_list.html @@ -48,7 +48,7 @@ {% else %} {% endif %} {% if can_edit_tasks %} From 846fc3ba7e79481e1102a211d009ff7271f1172a Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Thu, 22 Aug 2024 09:59:39 +0200 Subject: [PATCH 05/14] fix: ensure non-field-errors are caught by validation --- proposals/utils/validate_proposal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proposals/utils/validate_proposal.py b/proposals/utils/validate_proposal.py index 77b3d1690..c6671e71d 100644 --- a/proposals/utils/validate_proposal.py +++ b/proposals/utils/validate_proposal.py @@ -296,7 +296,7 @@ def get_form_errors(proposal: Proposal) -> list: instance = form_class(**kwargs) for field, error in instance.errors.items(): - if field in instance.fields: + if field in instance.fields or field == "__all__": troublesome_pages.append( { "url": url, From f1432e0321714425d45720490f9263d614e34131 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Thu, 22 Aug 2024 10:04:24 +0200 Subject: [PATCH 06/14] fix: refine SessionEndForm errors --- tasks/forms.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/tasks/forms.py b/tasks/forms.py index 1137cea2f..e312d231e 100644 --- a/tasks/forms.py +++ b/tasks/forms.py @@ -162,14 +162,10 @@ class Meta: model = Session fields = ["tasks_duration"] - _soft_validation_fields = [ - "tasks_duration", - ] def __init__(self, *args, **kwargs): """ - Set the tasks_duration label - - Set the tasks_duration as required """ super(SessionEndForm, self).__init__(*args, **kwargs) @@ -177,29 +173,24 @@ def __init__(self, *args, **kwargs): label = tasks_duration.label % self.instance.net_duration() tasks_duration.label = mark_safe(label) - def is_initial_visit(self) -> bool: - return True - def clean(self): cleaned_data = super(SessionEndForm, self).clean() - self.mark_soft_required(cleaned_data, "tasks_duration") - - return cleaned_data - - def clean_tasks_duration(self): - """ - Check that the net duration is at least equal to the gross duration - """ tasks_duration = self.cleaned_data.get("tasks_duration") - if tasks_duration and tasks_duration < self.instance.net_duration(): - raise forms.ValidationError( + if tasks_duration is not None and tasks_duration < self.instance.net_duration(): + self.add_error("tasks_duration", _("Totale sessieduur moet minstens gelijk zijn aan netto sessieduur."), - code="comparison", ) - return tasks_duration + if self.instance.tasks_number == 0: + self.add_error(None, + _( + "Sessie {} bevat nog geen taken. Voeg minstens één taak toe." + ).format(self.instance.order), + ) + + return cleaned_data class SessionOverviewForm(SoftValidationMixin, ModelForm): From 6acf1a3bf3d7c311ba7a7fe9179200009164636e Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Thu, 22 Aug 2024 10:27:54 +0200 Subject: [PATCH 07/14] fix: formatting --- main/templates/base/fetc_form_base.html | 4 +--- studies/forms.py | 6 +++--- tasks/forms.py | 13 +++++++------ tasks/templates/tasks/session_overview.html | 4 +--- tasks/templates/tasks/session_start.html | 4 +--- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/main/templates/base/fetc_form_base.html b/main/templates/base/fetc_form_base.html index 2b6f026ba..4ad468896 100644 --- a/main/templates/base/fetc_form_base.html +++ b/main/templates/base/fetc_form_base.html @@ -31,9 +31,7 @@
{% endblock %} - {% block auto-form-render %} - {{ form }} - {% endblock %} + {% block auto-form-render %}{{ form }}{% endblock %} {% block form-buttons %} {% block post-form-pre-buttons %}{% endblock %} diff --git a/studies/forms.py b/studies/forms.py index 8f69e5ed0..5a59de2e0 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -225,11 +225,11 @@ def clean(self): - at least one of the fields has to be checked """ cleaned_data = super(StudyDesignForm, self).clean() - #This solution is a bit funky, but by using add_error(), it appends our - #error msg to a built-in required error message. + # This solution is a bit funky, but by using add_error(), it appends our + # error msg to a built-in required error message. if not cleaned_data: msg = _("Je dient minstens één van de opties te selecteren.") - self.errors["study_types"]=[msg] + self.errors["study_types"] = [msg] class StudyConsentForm(ConditionalModelForm): diff --git a/tasks/forms.py b/tasks/forms.py index e312d231e..9671e5149 100644 --- a/tasks/forms.py +++ b/tasks/forms.py @@ -162,7 +162,6 @@ class Meta: model = Session fields = ["tasks_duration"] - def __init__(self, *args, **kwargs): """ - Set the tasks_duration label @@ -179,15 +178,17 @@ def clean(self): tasks_duration = self.cleaned_data.get("tasks_duration") if tasks_duration is not None and tasks_duration < self.instance.net_duration(): - self.add_error("tasks_duration", + self.add_error( + "tasks_duration", _("Totale sessieduur moet minstens gelijk zijn aan netto sessieduur."), ) if self.instance.tasks_number == 0: - self.add_error(None, - _( - "Sessie {} bevat nog geen taken. Voeg minstens één taak toe." - ).format(self.instance.order), + self.add_error( + None, + _("Sessie {} bevat nog geen taken. Voeg minstens één taak toe.").format( + self.instance.order + ), ) return cleaned_data diff --git a/tasks/templates/tasks/session_overview.html b/tasks/templates/tasks/session_overview.html index bb43e4432..6f5419303 100644 --- a/tasks/templates/tasks/session_overview.html +++ b/tasks/templates/tasks/session_overview.html @@ -16,9 +16,7 @@

{% trans "Overzicht van alle sessies en taken" %}

{% include "tasks/session_list.html" %} {% endblock %} -{% block auto-form-render %} - -{% endblock %} +{% block auto-form-render %}{% endblock %} {% block form-buttons %} {% include "base/form_buttons.html" %} diff --git a/tasks/templates/tasks/session_start.html b/tasks/templates/tasks/session_start.html index 9a86cc093..d67885efe 100644 --- a/tasks/templates/tasks/session_start.html +++ b/tasks/templates/tasks/session_start.html @@ -32,6 +32,4 @@

{% trans "Het takenonderzoek en/of interviews" %}

{% endblock %} -{% block auto-form-render %} - -{% endblock %} +{% block auto-form-render %}{% endblock %} From 1197e75d44d1cac3e91b3448a8f4911057f8cb98 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 13:03:37 +0200 Subject: [PATCH 08/14] fix: remove SessionOverviewForm from study kwarg list --- proposals/utils/validate_proposal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/proposals/utils/validate_proposal.py b/proposals/utils/validate_proposal.py index c6671e71d..4ebfae74f 100644 --- a/proposals/utils/validate_proposal.py +++ b/proposals/utils/validate_proposal.py @@ -288,7 +288,6 @@ def get_form_errors(proposal: Proposal) -> list: InterventionForm, ObservationForm, SessionUpdateForm, - SessionOverviewForm, ), ): kwargs["study"] = obj.study From 9899ca7139b2b5264ad4f5fcfc54d2b8c44e596c Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 13:03:57 +0200 Subject: [PATCH 09/14] feat: add SessionEndForm to validation --- proposals/utils/validate_proposal.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/proposals/utils/validate_proposal.py b/proposals/utils/validate_proposal.py index 4ebfae74f..1133447d2 100644 --- a/proposals/utils/validate_proposal.py +++ b/proposals/utils/validate_proposal.py @@ -11,7 +11,7 @@ from interventions.forms import InterventionForm from observations.forms import ObservationForm -from studies.forms import StudyForm, StudyDesignForm +from studies.forms import StudyForm, StudyDesignForm, StudyEndForm from tasks.forms import SessionUpdateForm, SessionEndForm, TaskForm, SessionOverviewForm from ..forms import ( ProposalForm, @@ -134,6 +134,14 @@ def _build_forms(proposal: Proposal) -> OrderedDict: study, ) + end_key = "{}_end".format(key_base) + forms[end_key] = ( + StudyEndForm, + reverse("studies:design_end", args=[study.pk]), + _("Trajectoverzicht (traject {})").format(study.order), + study, + ) + if study.has_intervention: intervention_key = "{}_intervention".format(key_base) if hasattr(study, "intervention"): From 07091be5114d71c3ca9da284e92260b73e1a67a6 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 13:30:23 +0200 Subject: [PATCH 10/14] fix: bugfix on StudyEndForm --- studies/forms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/studies/forms.py b/studies/forms.py index 5a59de2e0..36f88a174 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -287,7 +287,6 @@ def __init__(self, *args, **kwargs): - Remove empty label from deception/negativity/stressful/risk field and reset the choices - mark_safe the labels of negativity/stressful/risk """ - self.study = kwargs.pop("study", None) super(StudyEndForm, self).__init__(*args, **kwargs) @@ -304,7 +303,7 @@ def __init__(self, *args, **kwargs): self.fields["stressful"].label = mark_safe(self.fields["stressful"].label) self.fields["risk"].label = mark_safe(self.fields["risk"].label) - if not self.study.has_sessions: + if not self.instance.has_sessions: del self.fields["deception"] del self.fields["deception_details"] From 9c4f05ba68d5fbd0b5556265b27cdaabead33bb7 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 13:57:00 +0200 Subject: [PATCH 11/14] fix: improve StudyDesignForm validationability --- studies/forms.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/studies/forms.py b/studies/forms.py index 36f88a174..fb8699e01 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -217,7 +217,12 @@ class StudyDesignForm(TemplatedModelForm): class Meta: model = Study - fields = [] + fields = ["has_intervention", "has_observation", "has_sessions",] + widgets = { + "has_intervention": forms.HiddenInput(), + "has_observation": forms.HiddenInput(), + "has_sessions": forms.HiddenInput(), + } def clean(self): """ @@ -225,11 +230,17 @@ def clean(self): - at least one of the fields has to be checked """ cleaned_data = super(StudyDesignForm, self).clean() + # This solution is a bit funky, but by using add_error(), it appends our # error msg to a built-in required error message. - if not cleaned_data: - msg = _("Je dient minstens één van de opties te selecteren.") - self.errors["study_types"] = [msg] + if not "study_types" in cleaned_data: + error = forms.ValidationError(_("Je dient minstens één van de opties te selecteren."), code="required") + self.errors["study_types"] = error + + #this checks the hidden fields, and could be used for validating this + #form elsewhere + if not any(cleaned_data.values()): + self.add_error(None, _("Er is nog geen onderzoekstype geselecteerd.")) class StudyConsentForm(ConditionalModelForm): @@ -348,7 +359,6 @@ def clean(self): f1_value_list=[YesNoDoubt.YES, YesNoDoubt.DOUBT], ) - class StudyUpdateAttachmentsForm(forms.ModelForm): class Meta: model = Documents From 314e4e9c3cb9d09169b62184b9d9f344d7b9b827 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 14:44:38 +0200 Subject: [PATCH 12/14] fix: formatting --- studies/forms.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/studies/forms.py b/studies/forms.py index fb8699e01..42decc16e 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -217,7 +217,11 @@ class StudyDesignForm(TemplatedModelForm): class Meta: model = Study - fields = ["has_intervention", "has_observation", "has_sessions",] + fields = [ + "has_intervention", + "has_observation", + "has_sessions", + ] widgets = { "has_intervention": forms.HiddenInput(), "has_observation": forms.HiddenInput(), @@ -234,11 +238,13 @@ def clean(self): # This solution is a bit funky, but by using add_error(), it appends our # error msg to a built-in required error message. if not "study_types" in cleaned_data: - error = forms.ValidationError(_("Je dient minstens één van de opties te selecteren."), code="required") + error = forms.ValidationError( + _("Je dient minstens één van de opties te selecteren."), code="required" + ) self.errors["study_types"] = error - - #this checks the hidden fields, and could be used for validating this - #form elsewhere + + # this checks the hidden fields, and could be used for validating this + # form elsewhere if not any(cleaned_data.values()): self.add_error(None, _("Er is nog geen onderzoekstype geselecteerd.")) @@ -359,6 +365,7 @@ def clean(self): f1_value_list=[YesNoDoubt.YES, YesNoDoubt.DOUBT], ) + class StudyUpdateAttachmentsForm(forms.ModelForm): class Meta: model = Documents From 716cbbc6660ec53a0fe2aa6e694dd80d0f5a4289 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Tue, 3 Sep 2024 15:42:21 +0200 Subject: [PATCH 13/14] fix: remove the study kwarg from view too, woops --- studies/views/study_views.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/studies/views/study_views.py b/studies/views/study_views.py index fe4dfc0d2..c9efe4e65 100644 --- a/studies/views/study_views.py +++ b/studies/views/study_views.py @@ -150,12 +150,6 @@ def get_context_data(self, **kwargs): context["proposal"] = self.object.proposal return context - def get_form_kwargs(self): - """Sets the Study as a form kwarg""" - kwargs = super(StudyEnd, self).get_form_kwargs() - kwargs["study"] = self.object - return kwargs - def get_next_url(self): """ If there is another Study in this Proposal, continue to that one. From 6ea6b68f303ff5a32f5ac2d4dac8d1f22f97ecd8 Mon Sep 17 00:00:00 2001 From: Edo Storm Date: Wed, 4 Sep 2024 14:11:06 +0200 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20replace=20=C3=A9=C3=A9n=20with=20e?= =?UTF-8?q?en?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- studies/forms.py | 2 +- tasks/templates/tasks/session_list.html | 2 +- tasks/templates/tasks/task_list.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/studies/forms.py b/studies/forms.py index 42decc16e..aac7cadbf 100644 --- a/studies/forms.py +++ b/studies/forms.py @@ -239,7 +239,7 @@ def clean(self): # error msg to a built-in required error message. if not "study_types" in cleaned_data: error = forms.ValidationError( - _("Je dient minstens één van de opties te selecteren."), code="required" + _("Je dient minstens een van de opties te selecteren."), code="required" ) self.errors["study_types"] = error diff --git a/tasks/templates/tasks/session_list.html b/tasks/templates/tasks/session_list.html index e396bdcde..d0ec4ba12 100644 --- a/tasks/templates/tasks/session_list.html +++ b/tasks/templates/tasks/session_list.html @@ -32,7 +32,7 @@

{% include "tasks/task_list.html" %}

{% empty %} - + {% endfor %} {% if can_edit_sessions %}
diff --git a/tasks/templates/tasks/task_list.html b/tasks/templates/tasks/task_list.html index 2c3fb7239..231b8f401 100644 --- a/tasks/templates/tasks/task_list.html +++ b/tasks/templates/tasks/task_list.html @@ -48,7 +48,7 @@ {% else %} {% endif %} {% if can_edit_tasks %}