diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-04-19 21:09:39 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-04-19 21:09:39 +0100 |
commit | 792e893a84e916b9aa8be3944f3e905d3bc14fdd (patch) | |
tree | 7a3e2fcf9a15430a78a7fac234ed4e31e53ac189 /ctrack/caf | |
parent | 899fc0668b8137b41851739a4e1c9e43733985af (diff) |
cancel button in place and better form
Diffstat (limited to 'ctrack/caf')
-rw-r--r-- | ctrack/caf/forms.py | 33 | ||||
-rw-r--r-- | ctrack/caf/templates/caf/applicable_system_create_from_org.html | 1 | ||||
-rw-r--r-- | ctrack/caf/views.py | 7 |
3 files changed, 11 insertions, 30 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index 28a85d2..c1d6595 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -6,6 +6,7 @@ from crispy_forms.layout import Layout from crispy_forms.layout import Submit from django import forms from django.forms import inlineformset_factory +from django.urls import reverse from ctrack.caf.models import ApplicableSystem from ctrack.caf.models import CAF @@ -16,47 +17,25 @@ 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", "organisation"] - -class ApplicableSystemCreateForm(forms.ModelForm): - - def __init__(self, *args, **kwargs): + def __init__(self, org_id, slug, org_name, *args, **kwargs): super().__init__(*args, **kwargs) + cancel_redirect = reverse("organisations:detail", args=[slug]) self.helper = FormHelper(self) self.helper.layout = Layout( Fieldset( - "Create a new System", + f"Create a new system for {org_name}", Field("name", css_class="form-control form-control-sm"), Field("description", css_class="form-control form-control-sm"), - Field("organisation", 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") + Button("cancel", "Cancel", onclick=f"location.href='{cancel_redirect}';", css_class="btn-danger") ) ) - class Meta: - model = ApplicableSystem - fields = ["name", "description", "organisation", "caf"] 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 0de8b7d..a655f3e 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,6 @@ <div class="container"> <div class="row"> <div class="col-sm-6"> - <p>Creating form for {{ organisation }} </p> {% crispy form %} </div> </div> diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index 5dcf7ee..9770a81 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -4,7 +4,7 @@ from django.urls import reverse_lazy from django.views.generic import ListView, DetailView, CreateView from ctrack.assessments.models import CAFAssessmentOutcomeScore -from ctrack.caf.forms import ApplicableSystemCreateForm, ApplicableSystemCreateFromOrgForm +from ctrack.caf.forms import ApplicableSystemCreateFromOrgForm from ctrack.caf.models import ApplicableSystem, CAF from ctrack.organisations.models import Organisation @@ -66,7 +66,10 @@ class ApplicableSystemCreateFromOrg(LoginRequiredMixin, CreateView): def get_form_kwargs(self): kwargs = super().get_form_kwargs() - kwargs['org_id'] = Organisation.objects.get(slug=self.kwargs["slug"]).id + org = Organisation.objects.get(slug=self.kwargs["slug"]) + kwargs['org_id'] = org.id + kwargs['slug'] = org.slug + kwargs['org_name'] = org.name return kwargs def get_success_url(self): |