diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-05 10:36:34 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-05 10:36:34 +0100 |
commit | 04e8fa22dc488cb03a0c1ac3013bf65ebe0aac0e (patch) | |
tree | a4327d10ed2ae2d5b8504d81087b2f5e6563ee23 /ctrack/register/forms.py | |
parent | 80a7c8e991c7127bcf5c77b8a47d75d95ea8ce34 (diff) |
very bad implementation for form to create event from caf page...
Diffstat (limited to '')
-rw-r--r-- | ctrack/register/forms.py | 92 |
1 files changed, 62 insertions, 30 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index 4da9be9..4f91bd8 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -4,43 +4,75 @@ from django import forms from django.shortcuts import get_object_or_404 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 class EngagementEventCreateForm(forms.ModelForm): - def __init__(self, org_slug, user, *args, **kwargs): + def __init__(self, user, caf=None, org_slug=None, *args, **kwargs): super().__init__(*args, **kwargs) - org = get_object_or_404(Organisation, slug=org_slug) - cancel_redirect = reverse("core:home") - self.fields["participants"].queryset = Person.objects.filter(organisation__slug=org_slug) - 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) - self.helper.layout = Layout( - Field("type"), - "short_description", - "participants", - "related_caf", - # "user", - Hidden("user", "none"), - "date", - "end_date", - "response_date_requested", - "response_received", - "document_link", - "comments", - ButtonHolder( - Submit("submit", "Submit", css_class="btn-primary"), - Button( - "cancel", - "Cancel", - onclick=f"location.href='{cancel_redirect}';", - css_class="btn-danger", + if caf: + org = CAF.objects.get(pk=caf).organisation + cancel_redirect = reverse("core:home") + 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.helper = FormHelper(self) + self.helper.layout = Layout( + Field("type"), + "short_description", + "participants", + "related_caf", + # "user", + Hidden("user", "none"), + "date", + "end_date", + "response_date_requested", + "response_received", + "document_link", + "comments", + ButtonHolder( + Submit("submit", "Submit", css_class="btn-primary"), + Button( + "cancel", + "Cancel", + onclick=f"location.href='{cancel_redirect}';", + css_class="btn-danger", + ), ), - ), - ) + ) + else: + org = get_object_or_404(Organisation, slug=org_slug) + cancel_redirect = reverse("core:home") + self.fields["participants"].queryset = Person.objects.filter(organisation__slug=org_slug) + 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) + self.helper.layout = Layout( + Field("type"), + "short_description", + "participants", + "related_caf", + # "user", + Hidden("user", "none"), + "date", + "end_date", + "response_date_requested", + "response_received", + "document_link", + "comments", + ButtonHolder( + Submit("submit", "Submit", css_class="btn-primary"), + Button( + "cancel", + "Cancel", + onclick=f"location.href='{cancel_redirect}';", + css_class="btn-danger", + ), + ), + ) def save(self, commit=True): ee = super().save(commit=False) |