diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-04-19 20:37:56 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-04-19 20:37:56 +0100 |
commit | 6489d10f65e1d2b6ff50714caec6564ccf632a6f (patch) | |
tree | 9ce81232a822e191e4d5ae3ea7b0cd558d05c345 /ctrack/caf | |
parent | 9952f7a5fb3efc8abb657ab0cfaa7e898ec6606a (diff) |
can add a new system via organisation detail page
Diffstat (limited to 'ctrack/caf')
-rw-r--r-- | ctrack/caf/forms.py | 22 | ||||
-rw-r--r-- | ctrack/caf/templates/caf/applicable_system_create_from_org.html | 2 | ||||
-rw-r--r-- | ctrack/caf/templates/caf/caf_list.html | 2 | ||||
-rw-r--r-- | ctrack/caf/views.py | 15 |
4 files changed, 33 insertions, 8 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index 776e9af..c2d75ff 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -1,5 +1,5 @@ from crispy_forms.helper import FormHelper -from crispy_forms.layout import Button, Field +from crispy_forms.layout import Button, Field, Hidden from crispy_forms.layout import ButtonHolder from crispy_forms.layout import Fieldset from crispy_forms.layout import Layout @@ -21,9 +21,27 @@ CAFCreateInlineFormset = inlineformset_factory( class ApplicableSystemCreateFromOrgForm(forms.ModelForm): + + def __init__(self, org_id, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper(self) + self.helper.layout = Layout( + Fieldset( + "Create a new System", + Field("name", css_class="form-control form-control-sm"), + Field("description", css_class="form-control form-control-sm"), + Hidden("organisation", org_id), + Field("caf", css_class="form-control form-control-sm") + ), + ButtonHolder( + Submit("submit", "Submit", css_class="btn-primary"), + Button("cancel", "Cancel", css_class="btn-danger") + ) + ) + class Meta: model = ApplicableSystem - fields = ["name", "description", "caf"] + fields = ["name", "description", "caf", "organisation"] class ApplicableSystemCreateForm(forms.ModelForm): diff --git a/ctrack/caf/templates/caf/applicable_system_create_from_org.html b/ctrack/caf/templates/caf/applicable_system_create_from_org.html index 4c356e0..0de8b7d 100644 --- a/ctrack/caf/templates/caf/applicable_system_create_from_org.html +++ b/ctrack/caf/templates/caf/applicable_system_create_from_org.html @@ -6,7 +6,7 @@ <div class="container"> <div class="row"> <div class="col-sm-6"> - <p>Creating form for </p> + <p>Creating form for {{ organisation }} </p> {% crispy form %} </div> </div> diff --git a/ctrack/caf/templates/caf/caf_list.html b/ctrack/caf/templates/caf/caf_list.html index ce2940e..a5e4bbc 100644 --- a/ctrack/caf/templates/caf/caf_list.html +++ b/ctrack/caf/templates/caf/caf_list.html @@ -28,7 +28,7 @@ <td> <ul> {% for applicable_system in caf.applicable_systems.all %} - <li>{{ applicable_system.name }}</li> + <li><a href="{% url "caf:ass_detail" applicable_system.pk %}">{{ applicable_system.name }}</a></li> {% endfor %} </ul> </td> diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index 141c87e..07fd1b1 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -60,10 +60,17 @@ class ApplicableSystemCreateFromOrg(LoginRequiredMixin, CreateView): template_name = "caf/applicable_system_create_from_org.html" def get_context_data(self, **kwargs): - org = Organisation.objects.get(slug=self.kwargs["slug"]) - # TODO - now we have the organisation - we need to pass it to the form or store it in this class. - # We probably need to do return super().get_context_data(**kwargs) here to complete the func. - pass + context = super().get_context_data(**kwargs) + context["organisation"] = Organisation.objects.get(slug=self.kwargs["slug"]) + return context + + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs['org_id'] = Organisation.objects.get(slug=self.kwargs["slug"]).id + return kwargs + + def get_success_url(self): + return reverse_lazy("organisations:detail", args=[self.kwargs['slug']]) class ApplicableSystemCreate(LoginRequiredMixin, CreateView): |