Coverage for website/events/forms.py: 97.30%
27 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from django import forms
3from documents.forms import DocumentFileInput
4from events.models.documents import EventDocument
6from .models import RegistrationInformationField
9class FieldsForm(forms.Form):
10 """Form that outputs the correct widgets for the information fields."""
12 def __init__(self, *args, **kwargs):
13 self.information_fields = kwargs.pop("fields")
14 super().__init__(*args, **kwargs)
16 for key, field in self.information_fields.items():
17 field_type = field["type"]
19 if field_type == RegistrationInformationField.BOOLEAN_FIELD:
20 self.fields[key] = forms.BooleanField(required=False)
21 elif field_type == RegistrationInformationField.INTEGER_FIELD:
22 self.fields[key] = forms.IntegerField(required=field["required"])
23 elif field_type == RegistrationInformationField.TEXT_FIELD: 23 ↛ 28line 23 didn't jump to line 28 because the condition on line 23 was always true
24 self.fields[key] = forms.CharField(
25 required=field["required"], max_length=5000
26 )
28 self.fields[key].label = field["label"]
29 self.fields[key].help_text = field["description"]
30 self.fields[key].initial = field["value"]
32 def field_values(self):
33 for key in self.information_fields:
34 yield key, self.cleaned_data[key]
37class EventDocumentForm(forms.ModelForm):
38 """Form that overrides the widgets for the files."""
40 class Meta:
41 model = EventDocument
42 fields = (
43 "name",
44 "file",
45 "members_only",
46 "owner",
47 )
48 widgets = {
49 "file": DocumentFileInput,
50 }