diff options
author | MR Lemon <matt@matthewlemon> | 2020-04-17 16:03:51 +0100 |
---|---|---|
committer | MR Lemon <matt@matthewlemon> | 2020-04-17 16:03:51 +0100 |
commit | 51149b561a44e5ecfbca90dfb9989985ccf2c122 (patch) | |
tree | fd39a5d1768ed79a9b3a3419dc63edf2522e5e59 /ctrack/caf | |
parent | a4be1627b2705bba96d80204043876a3abec6a24 (diff) |
Adding a form for creating ApplicableSystem objects
Diffstat (limited to 'ctrack/caf')
-rw-r--r-- | ctrack/caf/forms.py | 23 | ||||
-rw-r--r-- | ctrack/caf/templates/caf/applicablesystem_create.html | 14 | ||||
-rw-r--r-- | ctrack/caf/urls.py | 6 | ||||
-rw-r--r-- | ctrack/caf/views.py | 9 |
4 files changed, 49 insertions, 3 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index fac3049..5903a2c 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -18,3 +18,26 @@ from django.forms.models import ModelMultipleChoiceField CAFCreateInlineFormset = inlineformset_factory( CAF, ApplicableSystem, fields=("name", "organisation"), extra=2) + + +class ApplicableSystemCreateForm(forms.ModelForm): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper(self) + self.helper.layout = Layout( + Fieldset( + "Create a new System", + "name", + "description", + "organisation", + "caf", + ), + ButtonHolder( + Submit("submit", "Submit", css_class="btn-primary") + ) + ) + + class Meta: + model = ApplicableSystem + fields = ["name", "description", "organisation", "caf"] diff --git a/ctrack/caf/templates/caf/applicablesystem_create.html b/ctrack/caf/templates/caf/applicablesystem_create.html new file mode 100644 index 0000000..5d5f4d9 --- /dev/null +++ b/ctrack/caf/templates/caf/applicablesystem_create.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% load crispy_forms_filters %} + +{% load crispy_forms_tags %} + +{% block content %} + <div class="container"> + <div class="row"> + <div class="col-lg-6"> + {% crispy form %} + </div> + </div> + </div> +{% endblock content %} diff --git a/ctrack/caf/urls.py b/ctrack/caf/urls.py index 943fede..72a1de5 100644 --- a/ctrack/caf/urls.py +++ b/ctrack/caf/urls.py @@ -1,7 +1,8 @@ from django.urls import path from django.views.decorators.cache import cache_page -from ctrack.caf.views import ListCAF, ListApplicableSystem, caf_detail_view, ApplicableSystemDetail +from ctrack.caf.views import ListCAF, ListApplicableSystem, caf_detail_view, ApplicableSystemDetail, \ + ApplicableSystemCreate app_name = "caf" @@ -9,5 +10,6 @@ urlpatterns = [ path("", view=ListCAF.as_view(), name="caf_list"), path("applicablesystems", cache_page(60 * 60)(ListApplicableSystem.as_view()), name="es_list"), path("applicablesystems/<int:pk>", ApplicableSystemDetail.as_view(), name="ass_detail"), - path("<int:pk>", caf_detail_view, name="detail") + path("applicablesystem/", ApplicableSystemCreate.as_view(), name="create"), + path("<int:pk>", caf_detail_view, name="detail") ] diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index 4bcfe61..9a5cb64 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -1,8 +1,9 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import render -from django.views.generic import ListView, DetailView +from django.views.generic import ListView, DetailView, CreateView from ctrack.assessments.models import CAFAssessmentOutcomeScore +from ctrack.caf.forms import ApplicableSystemCreateForm from ctrack.caf.models import ApplicableSystem, CAF @@ -49,3 +50,9 @@ class ListApplicableSystem(LoginRequiredMixin, ListView): class ApplicableSystemDetail(LoginRequiredMixin, DetailView): model = ApplicableSystem template_name = "caf/applicablesystem_detail.html" + + +class ApplicableSystemCreate(LoginRequiredMixin, CreateView): + form_class = ApplicableSystemCreateForm + model = ApplicableSystem + template_name = "caf/applicablesystem_create.html" |