forked from jazzband/django-formtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
ManagementForm
to validate current_step
Previously, bots could and would stuff this form value with all kinds of nonsense, triggering a server error (and subsequent alert emails). Supersedes jazzband#47
- Loading branch information
Showing
3 changed files
with
32 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
class ManagementForm(forms.Form): | ||
""" | ||
``ManagementForm`` is used to keep track of the current wizard step. | ||
""" | ||
def __init__(self, steps, **kwargs): | ||
self.steps = steps | ||
super().__init__(**kwargs) | ||
|
||
template_name = "django/forms/p.html" # Remove when Django 5.0 is minimal version. | ||
current_step = forms.CharField(widget=forms.HiddenInput) | ||
|
||
def clean_current_step(self): | ||
data = self.cleaned_data['current_step'] | ||
if data not in self.steps: | ||
raise ValidationError("Invalid step name.") | ||
return data |
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