diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-10 17:02:15 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-10 17:02:15 +0100 |
commit | c7e1faecabf81cbabf0241a226624c8ed562c98c (patch) | |
tree | b3daa89cdcdcc2c518d8177a572413acd093d56a /ctrack/register/forms.py | |
parent | d4431a7c4a31b05356fd1efc9e5cc91dda58ad4b (diff) |
started to test forms! love testing forms
Diffstat (limited to 'ctrack/register/forms.py')
-rw-r--r-- | ctrack/register/forms.py | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 3f13d33..16c82f0 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -6,7 +6,29 @@ from django.urls import reverse from ctrack.caf.models import CAF from ctrack.organisations.models import Person, Organisation -from ctrack.register.models import EngagementEvent, EngagementType +from ctrack.register.models import EngagementEvent, EngagementType, MeetingEvent + + +class AddMeetingForm(forms.ModelForm): + class Meta: + model = MeetingEvent + fields = [ + "type_descriptor", + "short_description", + "datetime", + "comments", + "location", + ] + + def __init__(self, *args, **kwargs): + self.user = kwargs.pop("user") + super().__init__(*args, **kwargs) + + def save(self): + form = super().save(commit=False) + form.user = self.user + form.save() + return form class EngagementEventCreateForm(forms.ModelForm): @@ -16,8 +38,12 @@ class EngagementEventCreateForm(forms.ModelForm): org = CAF.objects.get(pk=caf).organisation cancel_redirect = reverse("caf:detail", args=[caf]) self.fields["related_caf"].initial = caf - self.fields["participants"].queryset = Person.objects.filter(organisation__pk=org.pk) - self.fields["type"].queryset = EngagementType.objects.all().order_by("descriptor") + self.fields["participants"].queryset = Person.objects.filter( + organisation__pk=org.pk + ) + self.fields["type"].queryset = EngagementType.objects.all().order_by( + "descriptor" + ) self.helper = FormHelper(self) self.helper.layout = Layout( Field("type"), @@ -48,7 +74,9 @@ class EngagementEventCreateForm(forms.ModelForm): selectable_people = Person.objects.filter(organisation__slug=org_slug) self.fields["participants"].queryset = selectable_people self.fields["participants"].initial = selectable_people.first() - self.fields["type"].queryset = EngagementType.objects.all().order_by("descriptor") + self.fields["type"].queryset = EngagementType.objects.all().order_by( + "descriptor" + ) self.fields["related_caf"].queryset = org.caf_set.all() self.fields["related_caf"].label = "Related CAFs" self.helper = FormHelper(self) |