cleaned up project forms

This commit is contained in:
Oliver Zander 2025-10-15 12:20:11 +02:00
parent d1cda4c1a9
commit c27e4c5183
1 changed files with 2 additions and 13 deletions

View File

@ -307,13 +307,12 @@ class ListForm(BaseApplicationForm, CommonOrderMixin):
self.fields['address'].initial = '' self.fields['address'].initial = ''
class ProjectRequestForm(CommonOrderMixin, forms.ModelForm): class ProjectRequestForm(BaseApplicationForm, CommonOrderMixin):
""" """
Public-facing form for < 1000 EUR project requests. Public-facing form for < 1000 EUR project requests.
Key points: Key points:
- JSONField-backed multi-selects are exposed as MultipleChoiceField with checkbox widgets. - JSONField-backed multi-selects are exposed as MultipleChoiceField with checkbox widgets.
- We return `list(...)` in clean_* so the JSONField gets a native list.
- Extra UX tweaks: textareas for long text, number inputs with min/max/step, help_texts with links via format_html. - Extra UX tweaks: textareas for long text, number inputs with min/max/step, help_texts with links via format_html.
""" """
@ -374,13 +373,6 @@ class ProjectRequestForm(CommonOrderMixin, forms.ModelForm):
'Falls du noch weitere Informationen hast, teile sie gern an dieser Stelle mit uns. Für umfangreichere Informationen, schreibe uns eine E-Mail an <a href="mailto:community@wikimedia.de">community@wikimedia.de</a>.'), 'Falls du noch weitere Informationen hast, teile sie gern an dieser Stelle mit uns. Für umfangreichere Informationen, schreibe uns eine E-Mail an <a href="mailto:community@wikimedia.de">community@wikimedia.de</a>.'),
} }
# Persist multi-selects as Python lists so JSONField stores a JSON array
def clean_categories(self):
return list(self.cleaned_data.get('categories', []))
def clean_wikimedia_projects(self):
return list(self.cleaned_data.get('wikimedia_projects', []))
class ProjectRequestAdminForm(forms.ModelForm): class ProjectRequestAdminForm(forms.ModelForm):
""" """
@ -395,7 +387,7 @@ class ProjectRequestAdminForm(forms.ModelForm):
categories = forms.MultipleChoiceField( categories = forms.MultipleChoiceField(
choices=[(c, c) for c in PROJECT_CATEGORIES], choices=[(c, c) for c in PROJECT_CATEGORIES],
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
label='Projektkategorie' label='Projektkategorie(n)'
) )
wikimedia_projects = forms.MultipleChoiceField( wikimedia_projects = forms.MultipleChoiceField(
choices=[(w, w) for w in WIKIMEDIA_CHOICES], choices=[(w, w) for w in WIKIMEDIA_CHOICES],
@ -404,9 +396,6 @@ class ProjectRequestAdminForm(forms.ModelForm):
) )
class Meta: class Meta:
model = ProjectRequest
fields = "__all__"
# Make longer texts easier to edit in the admin UI # Make longer texts easier to edit in the admin UI
widgets = { widgets = {
'description': forms.Textarea(attrs={'rows': 5}), 'description': forms.Textarea(attrs={'rows': 5}),