From b1d0fa9854e91572339056ea8d38a839a6e8fd43 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Tue, 21 Apr 2020 22:16:00 +0100 Subject: started work on the create organisation page --- ctrack/organisations/forms.py | 37 ++++++++++++++++++++++ .../organisations/organisation_create.html | 17 ++++++++++ .../organisations/organisation_detail.html | 35 ++++++++++++-------- ctrack/organisations/urls.py | 5 +-- ctrack/organisations/views.py | 9 +++++- 5 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 ctrack/organisations/forms.py create mode 100644 ctrack/organisations/templates/organisations/organisation_create.html (limited to 'ctrack') diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py new file mode 100644 index 0000000..59782e0 --- /dev/null +++ b/ctrack/organisations/forms.py @@ -0,0 +1,37 @@ +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, Button, Hidden +from django import forms +from django.urls import reverse + +from ctrack.organisations.models import Organisation + + +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( + f"Create a new Organisation", + "name", + "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"] diff --git a/ctrack/organisations/templates/organisations/organisation_create.html b/ctrack/organisations/templates/organisations/organisation_create.html new file mode 100644 index 0000000..27e2cf4 --- /dev/null +++ b/ctrack/organisations/templates/organisations/organisation_create.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% block title %} + Create a new Organisation +{% endblock title %} + +{% load crispy_forms_tags %} + +{% block content %} +
+
+
+ {% crispy form %} +
+
+
+{% endblock content %} diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index 254516a..bfbd07f 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -65,26 +65,35 @@ +
+

NIS Systems

+
+
-
NIS Systems | Add new...
+
- {% for ass in applicable_systems %} - - - - - {% endfor %} + {% if applicable_systems|length > 1 %} + {% for ass in applicable_systems %} + + + + + {% endfor %} + {% else %} +

Add new...

+ {% endif %}
{{ ass.name }}{{ ass.description }}
- - {{ ass.caf }} - | System - Detail - | Edit System -
{{ ass.name }}{{ ass.description }}
+ + {{ ass.caf }} + | System + Detail + | Edit System +
diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index 1ca93d8..8a23cd2 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -1,10 +1,11 @@ from django.urls import path -from ctrack.organisations.views import OrganisationDetailView, OrganisationListView +from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate app_name = "organisations" urlpatterns = [ path("/", view=OrganisationDetailView.as_view(), name="detail"), - path("", view=OrganisationListView.as_view(), name="list") + 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 0902e57..74b290e 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -2,11 +2,18 @@ from typing import Any from typing import Dict from django.contrib.auth.mixins import LoginRequiredMixin -from django.views.generic import DetailView, ListView +from django.views.generic import DetailView, ListView, CreateView +from .forms import OrganisationCreateForm from .models import Organisation +class OrganisationCreate(LoginRequiredMixin, CreateView): + form_class = OrganisationCreateForm + model = Organisation + template_name = "organisations/organisation_create.html" + + class OrganisationListView(LoginRequiredMixin, ListView): model = Organisation -- cgit v1.2.3