From dbe4555b17e2dd0d49b8c4879252692f75f8fe42 Mon Sep 17 00:00:00 2001 From: MR Lemon Date: Fri, 1 May 2020 16:28:08 +0100 Subject: squashed a lot of wizard form code --- config/settings/base.py | 1 - ctrack/organisations/forms.py | 31 +++++-- .../organisations/org_create_wizard_form.html | 103 --------------------- .../organisations/organisation_create.html | 3 +- ctrack/organisations/urls.py | 5 +- ctrack/organisations/views.py | 18 ---- requirements/base.txt | 4 +- 7 files changed, 24 insertions(+), 141 deletions(-) delete mode 100644 ctrack/organisations/templates/organisations/org_create_wizard_form.html diff --git a/config/settings/base.py b/config/settings/base.py index e1d7763..fd3f502 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -81,7 +81,6 @@ THIRD_PARTY_APPS = [ "allauth", "allauth.account", "allauth.socialaccount", - "formtools", ] LOCAL_APPS = [ 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 %} - -
-
-
-

Create a new Organisation

-
-
-
-
-

Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}

-
-
-
-
-
- {% csrf_token %} - {{ wizard.management_form }} - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {{ form }} - {% endfor %} - {% else %} -
- - {{ wizard.form.name }} -
-
-
-
- {{ wizard.form.oes }} - -
-
- {{ wizard.form.active }} - -
-
-
-
-
-
-
-
- - {{ wizard.form.submode }} -
-
-
-
- - {{ wizard.form.designation_type }} - {{ wizard.form.designation_type.help_text }} -
-
-
-
-
-
-
- - {{ wizard.form.registered_company_name }} - {{ wizard.form.registered_company_name.help_text }} -
-
-
-
- - {{ wizard.form.registered_company_number }} - {{ wizard.form.registered_company_number.help_text }} -
-
-
-{# {{ wizard.form }}#} - {% endif %} - {% if wizard.steps.prev %} - - - {% endif %} -
-
- -
-
-
-
-
-
- - - -{% 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 @@
-

Create a new Organisation (Step 1 of 2)

+

Create a new Organisation

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("/", 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 diff --git a/requirements/base.txt b/requirements/base.txt index a6c6d53..5fea182 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,12 +1,10 @@ # Django # ------------------------------------------------------------------------------ -django==3.0.5 # pyup: < 3.0 # https://www.djangoproject.com/ +django==3.0 # pyup: < 3.0 # https://www.djangoproject.com/ django-environ # https://github.com/joke2k/django-environ django-allauth # https://github.com/pennersr/django-allauth django-crispy-forms # https://github.com/django-crispy-forms/django-crispy-forms -django-formtools # https://github.com/jazzband/django-formtools - # These were required for the basic run python-slugify argon2-cffi -- cgit v1.2.3