diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-04-21 22:16:00 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-04-21 22:16:00 +0100 |
commit | b1d0fa9854e91572339056ea8d38a839a6e8fd43 (patch) | |
tree | 5b11cb55cf1c62616d4180bb17c7be777eed5244 /ctrack | |
parent | 4abbf4b838513b9157b84e080d90d40292eee997 (diff) |
started work on the create organisation page
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/organisations/forms.py | 37 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_create.html | 17 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_detail.html | 35 | ||||
-rw-r--r-- | ctrack/organisations/urls.py | 5 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 9 |
5 files changed, 87 insertions, 16 deletions
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 %} + <div class="container"> + <div class="row"> + <div class="col-sm-12"> + {% crispy form %} + </div> + </div> + </div> +{% 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 @@ </div> </div> + <div class="row pt-3 text-info"> + <h4>NIS Systems</h4> + </div> + <div class="row"> <div class="col-sm-8 p-2"> <div class="card bg-light"> <div class="card-body"> - <div class="card-title">NIS Systems | <small><a href="{% url "caf:create_from_org" object.slug %}">Add new...</a></small></div> + <div class="card-title"></div> <div class="card-text"> <div class="table-responsive"> <table class="table"> - {% for ass in applicable_systems %} - <tr> - <td><strong>{{ ass.name }}</strong></td> - <td>{{ ass.description }}<br> - <a href="{% url "caf:detail" ass.caf.pk %}" class="small"> - {{ ass.caf }} - </a> <span class="text-muted">|</span> <a href="{% url "caf:ass_detail" ass.pk %}" class="small">System - Detail</a> - <span class="text-muted">|</span> <a href="#" class="small">Edit System</a> - </td> - </tr> - {% endfor %} + {% if applicable_systems|length > 1 %} + {% for ass in applicable_systems %} + <tr> + <td><strong>{{ ass.name }}</strong></td> + <td>{{ ass.description }}<br> + <a href="{% url "caf:detail" ass.caf.pk %}" class="small"> + {{ ass.caf }} + </a> <span class="text-muted">|</span> <a href="{% url "caf:ass_detail" ass.pk %}" + class="small">System + Detail</a> + <span class="text-muted">|</span> <a href="#" class="small">Edit System</a> + </td> + </tr> + {% endfor %} + {% else %} + <p><small><a href="{% url "caf:create_from_org" object.slug %}">Add new...</a></small></p> + {% endif %} </table> </div> </div> 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("<slug:slug>/", 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 |