-
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
Merged
Merged
Fix/improve forms UI #687
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8e9ab89
fix: bug with double error message
EdoStorm96 73eab98
feat: create block for form rendering
EdoStorm96 b563da5
feat: Ensure form isnt rendered to avoid ugly error message
EdoStorm96 074d1d7
fix: slight UI improvements to task_list and session_list
EdoStorm96 846fc3b
fix: ensure non-field-errors are caught by validation
EdoStorm96 f1432e0
fix: refine SessionEndForm errors
EdoStorm96 6acf1a3
fix: formatting
EdoStorm96 1197e75
fix: remove SessionOverviewForm from study kwarg list
EdoStorm96 9899ca7
feat: add SessionEndForm to validation
EdoStorm96 07091be
fix: bugfix on StudyEndForm
EdoStorm96 9c4f05b
fix: improve StudyDesignForm validationability
EdoStorm96 314e4e9
fix: formatting
EdoStorm96 716cbbc
fix: remove the study kwarg from view too, woops
EdoStorm96 6ea6b68
fix: replace één with een
EdoStorm96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 een 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): | ||
|
@@ -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"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.