aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/caf/forms.py
diff options
context:
space:
mode:
authorMR Lemon <matt@matthewlemon>2020-04-21 16:09:32 +0100
committerMR Lemon <matt@matthewlemon>2020-04-21 16:09:32 +0100
commit271409371dc71b6c9108b2e56cb82ff8ce74415f (patch)
tree7302833703b22d2e0c8fe5cef2a181da59a26c6d /ctrack/caf/forms.py
parent563ccf1d64a3bdc81d6d1fe9c45b95684d5a3868 (diff)
can now add a system from a CAF detail page
Diffstat (limited to 'ctrack/caf/forms.py')
-rw-r--r--ctrack/caf/forms.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py
index f470dae..f79e56a 100644
--- a/ctrack/caf/forms.py
+++ b/ctrack/caf/forms.py
@@ -16,6 +16,37 @@ CAFCreateInlineFormset = inlineformset_factory(
CAF, ApplicableSystem, fields=("name", "organisation"), extra=2)
+class ApplicableSystemCreateFromCafForm(forms.Form):
+ name = forms.CharField(max_length=255)
+ description = forms.CharField(widget=forms.Textarea)
+ organisation = forms.ModelChoiceField(queryset=Organisation.objects.all())
+ caf = forms.ModelChoiceField(queryset=CAF.objects.all())
+
+ def __init__(self, *args, **kwargs):
+ # We must pop the kwargs before we pass to super()
+ # https://stackoverflow.com/a/8973101
+ caf_id = kwargs.pop("caf_id")
+ org_id = kwargs.pop("org_id")
+ super().__init__(*args, **kwargs)
+ caf = CAF.objects.get(pk=caf_id)
+ cancel_redirect = reverse("caf:detail", args=[caf_id])
+ self.fields['caf'].queryset = CAF.objects.filter(pk=caf_id)
+ self.helper = FormHelper(self)
+ self.helper.layout = Layout(
+ Fieldset(
+ f"Create a new system for {caf}",
+ Field("name", css_class="for-control form-control-sm"),
+ Field("description", cass_class="form-control form-control-sm"),
+ Hidden("caf", caf_id),
+ Hidden("organisation", org_id),
+ ),
+ ButtonHolder(
+ Submit("submit", "Submit", css_class="btn-primary"),
+ Button("cancel", "Cancel", onclick=f"location.href='{cancel_redirect}';", css_class="btn-danger")
+ )
+ )
+
+
class ApplicableSystemCreateFromOrgForm(forms.Form):
name = forms.CharField(max_length=255)
description = forms.CharField(widget=forms.Textarea)