aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctrack/caf/forms.py18
-rw-r--r--ctrack/caf/views.py8
2 files changed, 16 insertions, 10 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py
index c1d6595..e9eef3b 100644
--- a/ctrack/caf/forms.py
+++ b/ctrack/caf/forms.py
@@ -15,16 +15,21 @@ CAFCreateInlineFormset = inlineformset_factory(
CAF, ApplicableSystem, fields=("name", "organisation"), extra=2)
-class ApplicableSystemCreateFromOrgForm(forms.ModelForm):
+class ApplicableSystemCreateFromOrgForm(forms.Form):
+ choices = ()
+ name = forms.CharField(max_length=255)
+ description = forms.CharField(widget=forms.Textarea)
+ organisation = forms.ModelChoiceField(queryset=None)
+ caf = forms.ChoiceField(choices=(
+ choices
+ ))
- class Meta:
- model = ApplicableSystem
- fields = ["name", "description", "caf", "organisation"]
-
- def __init__(self, org_id, slug, org_name, *args, **kwargs):
+ def __init__(self, org_id, slug, org_name, org_cafs, *args, **kwargs):
super().__init__(*args, **kwargs)
cancel_redirect = reverse("organisations:detail", args=[slug])
+ ApplicableSystemCreateFromOrgForm.choices = org_cafs
self.helper = FormHelper(self)
+ self.helper.form_method = "post"
self.helper.layout = Layout(
Fieldset(
f"Create a new system for {org_name}",
@@ -38,4 +43,3 @@ class ApplicableSystemCreateFromOrgForm(forms.ModelForm):
Button("cancel", "Cancel", onclick=f"location.href='{cancel_redirect}';", css_class="btn-danger")
)
)
-
diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py
index 9770a81..2bfe7ad 100644
--- a/ctrack/caf/views.py
+++ b/ctrack/caf/views.py
@@ -1,7 +1,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render
from django.urls import reverse_lazy
-from django.views.generic import ListView, DetailView, CreateView
+from django.views.generic import ListView, DetailView, CreateView, FormView
from ctrack.assessments.models import CAFAssessmentOutcomeScore
from ctrack.caf.forms import ApplicableSystemCreateFromOrgForm
@@ -54,8 +54,7 @@ class ApplicableSystemDetail(LoginRequiredMixin, DetailView):
template_name = "caf/applicablesystem_detail.html"
-class ApplicableSystemCreateFromOrg(LoginRequiredMixin, CreateView):
- model = ApplicableSystem
+class ApplicableSystemCreateFromOrg(LoginRequiredMixin, FormView):
form_class = ApplicableSystemCreateFromOrgForm
template_name = "caf/applicable_system_create_from_org.html"
@@ -67,9 +66,12 @@ class ApplicableSystemCreateFromOrg(LoginRequiredMixin, CreateView):
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
org = Organisation.objects.get(slug=self.kwargs["slug"])
+ asses = org.applicablesystem_set.all()
+ org_cafs = {ass.caf for ass in asses}
kwargs['org_id'] = org.id
kwargs['slug'] = org.slug
kwargs['org_name'] = org.name
+ kwargs['org_cafs'] = list(org_cafs)
return kwargs
def get_success_url(self):