From f74421c9a8982a692f190b0f9b0d3338b6f32fa8 Mon Sep 17 00:00:00 2001 From: MR Lemon Date: Tue, 5 May 2020 15:27:59 +0100 Subject: organisation bit of the form looking better now after manually formatting the html --- ctrack/organisations/forms.py | 29 ++++------ .../organisations/org_create_formset.html | 66 ++++++++++++++++++++-- ctrack/organisations/views.py | 1 - 3 files changed, 72 insertions(+), 24 deletions(-) diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py index 2fe5033..30a24c5 100644 --- a/ctrack/organisations/forms.py +++ b/ctrack/organisations/forms.py @@ -1,8 +1,7 @@ from crispy_forms.helper import FormHelper -from crispy_forms.layout import Layout, Fieldset, Field, ButtonHolder, Submit +from crispy_forms.layout import Layout, Submit from django import forms from django.forms import inlineformset_factory -from django.urls import reverse from ctrack.organisations.models import Organisation, Address @@ -10,21 +9,14 @@ from ctrack.organisations.models import Organisation, Address class OrganisationCreateForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - 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", - "comments", - "active" - ), - ) + self.fields["name"].widget.attrs["class"] = "form-control form-control-lg" + self.fields["submode"].widget.attrs["class"] = "form-control" + self.fields["oes"].widget.attrs["class"] = "form-check-input" + self.fields["oes"].widget.attrs["type"] = "checkbox" + 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" + self.fields["comments"].widget.attrs["class"] = "form-control" class Meta: model = Organisation @@ -35,9 +27,10 @@ class OrganisationCreateForm(forms.ModelForm): "oes": "OES" } help_texts = { + "name": "Name of the organisation", "submode": "e.g. Rail Maintenance, TOC, etc...", "active": "Is this company an active participant in the NIS compliance regime?", - "designation_type": "This is probably defined in the Reguation", + "designation_type": "This is probably defined in the Regulation", } diff --git a/ctrack/organisations/templates/organisations/org_create_formset.html b/ctrack/organisations/templates/organisations/org_create_formset.html index 393b94e..251e5da 100644 --- a/ctrack/organisations/templates/organisations/org_create_formset.html +++ b/ctrack/organisations/templates/organisations/org_create_formset.html @@ -9,15 +9,71 @@ {% block content %}
+

Create a new organisation

-
+
- {% csrf_token %} - {{ form }} - {% crispy addresses helper %} -
+ {# this is the parent form - in this case the organisation form #} +
+ {{ form.non_field_errors }} + + {{ form.name }} + {{ form.name.help_text }} +
+ +
+ {{ form.non_field_errors }} + {{ form.oes }} + + {{ form.oes.help_text }} +
+ + +
+ {{ form.non_field_errors }} + + {{ form.submode }} + {{ form.submode.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.designation_type }} + {{ form.designation_type.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.registered_company_name }} + {{ form.registered_company_name.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.registered_company_number }} + {{ form.registered_company_number.help_text }} +
+ +
+ {{ form.non_field_errors }} + + {{ form.comments }} + {{ form.comments.help_text }} +
+ +
+
+
Add address:
+
+
+ {% crispy addresses helper %}
+ {# This is the address inlineformset#} +
{% endblock %} diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 925ac77..6578bdc 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -1,7 +1,6 @@ from typing import Any from typing import Dict -from crispy_forms.layout import Submit from django.contrib.auth.mixins import LoginRequiredMixin from django.db import transaction from django.urls import reverse_lazy -- cgit v1.2.3