-
Notifications
You must be signed in to change notification settings - Fork 224
Ensure description if risk_technical
#1148
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -566,48 +566,68 @@ class RadioWidget(forms.widgets.RadioSelect): | |
| class ExperimentRisksForm(ChangeLogMixin, forms.ModelForm): | ||
| RADIO_OPTIONS = ((False, "No"), (True, "Yes")) | ||
|
|
||
| def coerce_truthy(value): | ||
| if value.lower() == "true": | ||
| return True | ||
| elif value.lower() == "false": | ||
| return False | ||
|
|
||
| # Radio Buttons | ||
| risk_internal_only = forms.ChoiceField( | ||
| risk_internal_only = forms.TypedChoiceField( | ||
| label=Experiment.RISK_INTERNAL_ONLY_LABEL, | ||
| help_text=Experiment.RISK_INTERNAL_ONLY_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
|
Collaborator
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 think you can just say
Author
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. The value getting passed to these is a string of either |
||
| empty_value=None, | ||
| ) | ||
| risk_partner_related = forms.ChoiceField( | ||
| risk_partner_related = forms.TypedChoiceField( | ||
| label=Experiment.RISK_PARTNER_RELATED_LABEL, | ||
| help_text=Experiment.RISK_PARTNER_RELATED_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
| risk_brand = forms.ChoiceField( | ||
| risk_brand = forms.TypedChoiceField( | ||
| label=Experiment.RISK_BRAND_LABEL, | ||
| help_text=Experiment.RISK_BRAND_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
| risk_fast_shipped = forms.ChoiceField( | ||
| risk_fast_shipped = forms.TypedChoiceField( | ||
| label=Experiment.RISK_FAST_SHIPPED_LABEL, | ||
| help_text=Experiment.RISK_FAST_SHIPPED_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
| risk_confidential = forms.ChoiceField( | ||
| risk_confidential = forms.TypedChoiceField( | ||
| label=Experiment.RISK_CONFIDENTIAL_LABEL, | ||
| help_text=Experiment.RISK_CONFIDENTIAL_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
| risk_release_population = forms.ChoiceField( | ||
| risk_release_population = forms.TypedChoiceField( | ||
| label=Experiment.RISK_RELEASE_POPULATION_LABEL, | ||
| help_text=Experiment.RISK_RELEASE_POPULATION_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
| risk_technical = forms.ChoiceField( | ||
| risk_technical = forms.TypedChoiceField( | ||
| label=Experiment.RISK_TECHNICAL_LABEL, | ||
| help_text=Experiment.RISK_TECHNICAL_HELP_TEXT, | ||
| choices=RADIO_OPTIONS, | ||
| widget=RadioWidget, | ||
| coerce=coerce_truthy, | ||
| empty_value=None, | ||
| ) | ||
|
|
||
| # Optional Risk Descriptions | ||
|
|
@@ -690,6 +710,27 @@ class Meta: | |
| "qa_status", | ||
| ) | ||
|
|
||
| def clean(self): | ||
| cleaned_data = super().clean() | ||
| if ( | ||
| "risk_technical" in cleaned_data | ||
| and "risk_technical_description" in cleaned_data | ||
| ): | ||
| # Both checked, now we need to do an invariance check on these | ||
| # two. This is to match what's done with jQuery in the form: | ||
| # the 'risk_technical_description' needs to be required | ||
| # if 'risk_technical' is ``True``. | ||
| if cleaned_data.get("risk_technical"): | ||
| if not cleaned_data["risk_technical_description"]: | ||
| msg = ( | ||
| f"This is required if " | ||
| f"'{Experiment.RISK_TECHNICAL_LABEL}' is true." | ||
| ) | ||
| raise forms.ValidationError( | ||
| {"risk_technical_description": msg} | ||
| ) | ||
| return cleaned_data | ||
|
|
||
|
|
||
| class ExperimentReviewForm( | ||
| ExperimentConstants, ChangeLogMixin, forms.ModelForm | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.