diff options
author | MR Lemon <matt@matthewlemon> | 2020-05-01 16:28:08 +0100 |
---|---|---|
committer | MR Lemon <matt@matthewlemon> | 2020-05-01 16:56:30 +0100 |
commit | dbe4555b17e2dd0d49b8c4879252692f75f8fe42 (patch) | |
tree | e9e308d6f49d5419096996674a36906f81da9a51 /ctrack | |
parent | efde7c98c202405c4bbbd9d8832f3f92fc402468 (diff) |
squashed a lot of wizard form code
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/organisations/forms.py | 31 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/org_create_wizard_form.html | 103 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_create.html | 3 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 18 |
5 files changed, 23 insertions, 137 deletions
diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py index d9495f8..d4baf64 100644 --- a/ctrack/organisations/forms.py +++ b/ctrack/organisations/forms.py @@ -9,20 +9,32 @@ from ctrack.organisations.models import Organisation, Address class OrganisationCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["name"].widget.attrs["class"] = "form-control" - self.fields["submode"].widget.attrs["class"] = "form-control" - self.fields["oes"].widget.attrs["class"] = "form-check-input" - self.fields["active"].widget.attrs["class"] = "form-check-input" - self.fields["designation_type"].widget.attrs["class"] = "form-control" - self.fields["registered_company_name"].widget.attrs["class"] = "form-control" - self.fields["registered_company_number"].widget.attrs["class"] = "form-control" + cancel_redirect = reverse("organisations:list") + self.helper = FormHelper(self) + self.helper.layout = Layout( + Fieldset( + "", + Field("name", css_class="form-control-lg"), + "submode", + "oes", + "designation_type", + "registered_company_name", + "registered_company_number", + "updated_by", + "comments", + "active" + ), + ButtonHolder( + Submit("submit", "Submit", css_class="btn-primary"), + Button("cancel", "Cancel", onclick=f"location.href='{cancel_redirect}';", css_class="btn-danger") + ) + ) class Meta: model = Organisation fields = ["name", "submode", "oes", "designation_type", "registered_company_name", "registered_company_number", "updated_by", "comments", "active"] - # This doesn't have any effect when using the form wizard labels = { "oes": "OES" } @@ -31,7 +43,6 @@ class OrganisationCreateForm(forms.ModelForm): "updated_by": "Name of staff member/inspector creating this record", "active": "Is this company an active participant in the NIS compliance regime?", "designation_type": "This is probably defined in the Reguation", - "registered_company_name": "Probably different from the Organisation name" } @@ -42,7 +53,7 @@ class AddressCreateForm(forms.ModelForm): 'country', 'other_details') def __init__(self, *args, **kwargs): - # self.org = kwargs.pop("org") + self.org = kwargs.pop("org") super().__init__(*args, **kwargs) def save(self): diff --git a/ctrack/organisations/templates/organisations/org_create_wizard_form.html b/ctrack/organisations/templates/organisations/org_create_wizard_form.html deleted file mode 100644 index 238a782..0000000 --- a/ctrack/organisations/templates/organisations/org_create_wizard_form.html +++ /dev/null @@ -1,103 +0,0 @@ -{% extends "base.html" %} - -{% block head %} - {{ wizard.form.media }} -{% endblock %} - -{% block title %} - Create a new Organisation -{% endblock title %} - -{% block content %} - - <div class="container mt-3"> - <div class="row"> - <div class="col-md-12 pl-0 my-2"> - <h4>Create a new Organisation</h4> - </div> - </div> - <div class="row"> - <div class="col-md-12 pl-0 my-2"> - <p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p> - </div> - </div> - <div class="row"> - <div class="col-md-8 pt-2 border bg-light"> - <form action="" method="post"> - {% csrf_token %} - {{ wizard.management_form }} - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {{ form }} - {% endfor %} - {% else %} - <div class="form-group required"> - <label for="name">Name:</label> - {{ wizard.form.name }} - </div> - <div class="row"> - <div class="col-md-12"> - <div class="form-check float-left"> - {{ wizard.form.oes }} - <label class="form-check-label" for="oes">OES</label> - </div> - <div class="form-check float-right"> - {{ wizard.form.active }} - <label class="form-check-label" for="active">Active?</label> - <br/> - </div> - </div> - </div> - <hr> - <div class="row"> - <div class="col-md-6"> - <div class="form-group"> - <label for="submode">Sub mode:</label> - {{ wizard.form.submode }} - </div> - </div> - <div class="col-md-6"> - <div class="form-group"> - <label for="designation_type">Designation Type:</label> - {{ wizard.form.designation_type }} - <small class="form-text text-muted">{{ wizard.form.designation_type.help_text }}</small> - </div> - </div> - </div> - <hr> - <div class="row"> - <div class="col-md-6"> - <div class="form-group"> - <label for="registered_company_name">Registered Company Name:</label> - {{ wizard.form.registered_company_name }} - <small class="form-text text-muted">{{ wizard.form.registered_company_name.help_text }}</small> - </div> - </div> - <div class="col-md-6"> - <div class="form-group"> - <label for="registered_company_number">Registered Company Number:</label> - {{ wizard.form.registered_company_number }} - <small class="form-text text-muted">{{ wizard.form.registered_company_number.help_text }}</small> - </div> - </div> - </div> -{# {{ wizard.form }}#} - {% endif %} - {% if wizard.steps.prev %} - <button class="btn btn-danger" name="wizard_goto_step" type="button" value="{{ wizard.steps.first }}">First Step</button> - <button class="btn btn-primary" name="wizard_goto_step" type="button" value="{{ wizard.steps.prev }}">Previous Step</button> - {% endif %} - <div class="row"> - <div class="col-md-12 my-2"> - <input type="button" class="btn btn-primary" value="Next"/> - </div> - </div> - </form> - </div> - </div> - </div> - - - -{% endblock %} diff --git a/ctrack/organisations/templates/organisations/organisation_create.html b/ctrack/organisations/templates/organisations/organisation_create.html index 035e06a..4ee2801 100644 --- a/ctrack/organisations/templates/organisations/organisation_create.html +++ b/ctrack/organisations/templates/organisations/organisation_create.html @@ -1,6 +1,5 @@ {% extends "base.html" %} - {% block title %} Create a new Organisation {% endblock title %} @@ -11,7 +10,7 @@ <div class="container mt-3"> <div class="row"> <div class="col-md-12 pl-0 my-2"> - <h4>Create a new Organisation (Step 1 of 2)</h4> + <h4>Create a new Organisation</h4> </div> </div> <div class="row"> diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index 1ddef8f..8a23cd2 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -1,14 +1,11 @@ from django.urls import path -from ctrack.organisations.forms import OrganisationCreateForm, AddressCreateForm -from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate, \ - OrganisationCreateWizard +from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate app_name = "organisations" urlpatterns = [ path("<slug:slug>/", view=OrganisationDetailView.as_view(), name="detail"), - path("add-wizard", view=OrganisationCreateWizard.as_view([OrganisationCreateForm, AddressCreateForm])), path("", view=OrganisationListView.as_view(), name="list"), path("create", view=OrganisationCreate.as_view(), name="create") ] diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index e90a588..74b290e 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -2,30 +2,12 @@ from typing import Any from typing import Dict from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import HttpResponseRedirect -from django.urls import reverse from django.views.generic import DetailView, ListView, CreateView -from formtools.wizard.views import SessionWizardView from .forms import OrganisationCreateForm from .models import Organisation -def save_organisation_to_database(form_list): - """ - When we have a multi-part wizard form data back, we save it to the database here! - """ - pass - - -class OrganisationCreateWizard(LoginRequiredMixin, SessionWizardView): - template_name = "organisations/org_create_wizard_form.html" - - def done(self, form_list, **kwargs): - save_organisation_to_database(form_list) - return HttpResponseRedirect(reverse("organisations:list")) - - class OrganisationCreate(LoginRequiredMixin, CreateView): form_class = OrganisationCreateForm model = Organisation |