-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/improve forms UI #687
Fix/improve forms UI #687
Changes from 12 commits
8e9ab89
73eab98
b563da5
074d1d7
846fc3b
f1432e0
6acf1a3
1197e75
9899ca7
07091be
9c4f05b
314e4e9
716cbbc
6ea6b68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"): | ||
|
@@ -288,15 +296,14 @@ def get_form_errors(proposal: Proposal) -> list: | |
InterventionForm, | ||
ObservationForm, | ||
SessionUpdateForm, | ||
SessionOverviewForm, | ||
), | ||
): | ||
kwargs["study"] = obj.study | ||
|
||
instance = form_class(**kwargs) | ||
|
||
for field, error in instance.errors.items(): | ||
if field in instance.fields: | ||
if field in instance.fields or field == "__all__": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, can't believe we weren't doing this yet. |
||
troublesome_pages.append( | ||
{ | ||
"url": url, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,17 +217,36 @@ 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): | ||
""" | ||
Check for conditional requirements: | ||
- at least one of the fields has to be checked | ||
""" | ||
cleaned_data = super(StudyDesignForm, self).clean() | ||
if not cleaned_data: | ||
msg = _("Je dient minstens één van de opties te selecteren") | ||
self.add_error("study_types", forms.ValidationError(msg, code="required")) | ||
|
||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recently learned (guess from who) that you're not supposed to write "één" in Dutch if there's no chance of ambiguity. Same with "Tijd om er één aan te maken!", by the book it shouldn't have accents. |
||
) | ||
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): | ||
|
@@ -285,7 +304,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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This View is still getting a |
||
|
||
super(StudyEndForm, self).__init__(*args, **kwargs) | ||
|
||
|
@@ -302,7 +320,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"] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ | |
</table> | ||
{% else %} | ||
<div class="alert alert-info" role="alert"> | ||
{% trans "Deze sessie bevat nog geen taken. Klik op het podloodje om taken aan te maken!" %} | ||
{% trans "Deze sessie bevat nog geen taken. Tijd om er één aan te maken!" %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Translation hasn't been updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking we create a seperate issue for translation ... Because a lot of stuff is not translated or not up to date ... |
||
</div> | ||
{% endif %} | ||
{% if can_edit_tasks %} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file, SessionOverviewForm should not be in the following list:
As it has Study as its object already, so
obj.study
doesn't exist and throws an exception.Not on-topic for this PR, feel free to convert this to a separate issue.