diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/organisations/forms.py | 4 | ||||
-rw-r--r-- | ctrack/organisations/templates/organisations/org_create_wizard_form.html | 44 | ||||
-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 | ||||
-rw-r--r-- | requirements/base.txt | 4 |
6 files changed, 73 insertions, 5 deletions
diff --git a/ctrack/organisations/forms.py b/ctrack/organisations/forms.py index d4baf64..ab92e64 100644 --- a/ctrack/organisations/forms.py +++ b/ctrack/organisations/forms.py @@ -14,7 +14,7 @@ class OrganisationCreateForm(forms.ModelForm): self.helper.layout = Layout( Fieldset( "", - Field("name", css_class="form-control-lg"), + Field("name", css_class="form-control"), "submode", "oes", "designation_type", @@ -53,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 new file mode 100644 index 0000000..9305d1b --- /dev/null +++ b/ctrack/organisations/templates/organisations/org_create_wizard_form.html @@ -0,0 +1,44 @@ +{% 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>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</h4> + </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 %} + {{ wizard.form }} + {% endif %} + {% if wizard.steps.prev %} + <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">First Step</button> + <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">Previous Step</button> + {% endif %} + <input type="submit" value="Submit"/> + </form> + </div> + </div> + </div> + + + +{% endblock %} diff --git a/ctrack/organisations/templates/organisations/organisation_create.html b/ctrack/organisations/templates/organisations/organisation_create.html index 4ee2801..035e06a 100644 --- a/ctrack/organisations/templates/organisations/organisation_create.html +++ b/ctrack/organisations/templates/organisations/organisation_create.html @@ -1,5 +1,6 @@ {% extends "base.html" %} + {% block title %} Create a new Organisation {% endblock title %} @@ -10,7 +11,7 @@ <div class="container mt-3"> <div class="row"> <div class="col-md-12 pl-0 my-2"> - <h4>Create a new Organisation</h4> + <h4>Create a new Organisation (Step 1 of 2)</h4> </div> </div> <div class="row"> diff --git a/ctrack/organisations/urls.py b/ctrack/organisations/urls.py index 8a23cd2..1ddef8f 100644 --- a/ctrack/organisations/urls.py +++ b/ctrack/organisations/urls.py @@ -1,11 +1,14 @@ from django.urls import path -from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate +from ctrack.organisations.forms import OrganisationCreateForm, AddressCreateForm +from ctrack.organisations.views import OrganisationDetailView, OrganisationListView, OrganisationCreate, \ + OrganisationCreateWizard 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 74b290e..e90a588 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -2,12 +2,30 @@ 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 5fea182..a6c6d53 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,10 +1,12 @@ # Django # ------------------------------------------------------------------------------ -django==3.0 # pyup: < 3.0 # https://www.djangoproject.com/ +django==3.0.5 # 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 |