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/forms.py | |
parent | 899fc0668b8137b41851739a4e1c9e43733985af (diff) |
cancel button in place and better form
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/forms.py | 33 |
1 files changed, 6 insertions, 27 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"] |