aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-09-02 11:35:59 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-09-02 11:35:59 +0100
commit6610509f3a3ceab151bc70305508892c9fe00e7b (patch)
tree6e2cf1283ddc679a223cd0ad0286b23f58988dd7
parent055b50d7675505d60c0faa8bea900c9e553b7f2b (diff)
can now add a new system via the org user page
-rw-r--r--ctrack/caf/admin.py10
-rw-r--r--ctrack/caf/forms.py28
-rw-r--r--ctrack/caf/views.py10
-rw-r--r--ctrack/core/utils.py1
4 files changed, 29 insertions, 20 deletions
diff --git a/ctrack/caf/admin.py b/ctrack/caf/admin.py
index f1aa860..5513781 100644
--- a/ctrack/caf/admin.py
+++ b/ctrack/caf/admin.py
@@ -10,13 +10,21 @@ from .models import (
)
+def get_system_org(obj):
+ es = obj.essentialservice_set.first() # just get the first if there are many
+ return es.organisation.name
+
+
+get_system_org.short_description = "Organisation"
+
+
class EssentialServiceAdmin(admin.ModelAdmin):
model = EssentialService
class ApplicableSystemListAdmin(admin.ModelAdmin):
model = ApplicableSystem
- list_display = ["name", "function"]
+ list_display = ["name", get_system_org, "function"]
# FIXME
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py
index 928686d..412d310 100644
--- a/ctrack/caf/forms.py
+++ b/ctrack/caf/forms.py
@@ -12,7 +12,7 @@ from django import forms
from django.forms import inlineformset_factory
from django.urls import reverse
-from ctrack.caf.models import CAF, ApplicableSystem
+from ctrack.caf.models import CAF, ApplicableSystem, EssentialService
from ctrack.organisations.models import Organisation
# TODO - Replace this to get inlineformet working
@@ -78,13 +78,14 @@ class ApplicableSystemCreateFromCafForm(forms.Form):
class ApplicableSystemCreateFromOrgForm(forms.Form):
name = forms.CharField(max_length=255)
function = forms.CharField(widget=forms.Textarea)
- organisation = forms.ModelChoiceField(queryset=Organisation.objects.all())
- caf = forms.ModelChoiceField(queryset=CAF.objects.all())
- essential_service = forms.CharField(
- widget=forms.Textarea,
- max_length=255,
- help_text="Description of the essential service which the system suppports.",
- )
+ # organisation = forms.ModelChoiceField(queryset=Organisation.objects.all())
+ # caf = forms.ModelChoiceField(queryset=CAF.objects.all())
+ # essential_service = forms.CharField(
+ # widget=forms.Textarea,
+ # max_length=255,
+ # help_text="Description of the essential service which the system suppports.",
+ # )
+ essential_service = forms.ModelChoiceField(queryset=EssentialService.objects.all())
dft_categorisation = forms.ChoiceField(
choices=ApplicableSystem.SYSTEM_CATEGORISATION,
help_text="Refer to documentation for description of these criteria",
@@ -94,14 +95,14 @@ class ApplicableSystemCreateFromOrgForm(forms.Form):
help_text="Categorisation based on OES' own internal prioritisation process.",
)
- def __init__(self, org_id, slug, org_name, org_cafs, *args, **kwargs):
+ def __init__(self, org_id, slug, org_name, *args, **kwargs):
super().__init__(*args, **kwargs)
cancel_redirect = reverse("organisations:detail", args=[slug])
# we need to create the choices we can use for the CAF dropdown in the form
- self.fields["caf"].queryset = CAF.objects.filter(
- pk__in=[caf.pk for caf in org_cafs]
- )
- self.fields["caf"].label = "CAF"
+ # self.fields["caf"].queryset = CAF.objects.filter(
+ # pk__in=[caf.pk for caf in org_cafs]
+ # )
+ # self.fields["caf"].label = "CAF"
self.fields["dft_categorisation"].label = "DfT Categorisation"
self.fields["oes_categorisation"].label = "OES Categorisation"
self.helper = FormHelper(self)
@@ -114,7 +115,6 @@ class ApplicableSystemCreateFromOrgForm(forms.Form):
"dft_categorisation",
"oes_categorisation",
Hidden("organisation", org_id),
- "caf",
),
ButtonHolder(
Submit("submit", "Submit", css_class="btn-primary"),
diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py
index aaeb90b..480e305 100644
--- a/ctrack/caf/views.py
+++ b/ctrack/caf/views.py
@@ -107,20 +107,22 @@ class ApplicableSystemCreateFromOrg(
ass = ApplicableSystem.objects.create(
name=form.cleaned_data["name"],
function=form.cleaned_data["function"],
- organisation=form.cleaned_data["organisation"],
- caf=form.cleaned_data["caf"],
+ # organisation=form.cleaned_data["organisation"],
+ # caf=form.cleaned_data["caf"],
)
+ es = form.cleaned_data["essential_service"]
+ es.systems.add(ass)
return super().form_valid(form)
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
org = Organisation.objects.get(slug=self.kwargs["slug"])
asses = org.applicable_systems()
- org_cafs = org.caf_set.all()
+ # org_cafs = org.caf_set.all()
kwargs["org_id"] = org.id
kwargs["slug"] = org.slug
kwargs["org_name"] = org.name
- kwargs["org_cafs"] = list(org_cafs)
+ # kwargs["org_cafs"] = list(org_cafs)
return kwargs
def get_success_url(self):
diff --git a/ctrack/core/utils.py b/ctrack/core/utils.py
index 5382a84..af01549 100644
--- a/ctrack/core/utils.py
+++ b/ctrack/core/utils.py
@@ -687,7 +687,6 @@ def populate_db(**kwargs):
_caf2 = CAF.objects.get(pk=1)
_completer = Person.objects.get(pk=1)
- breakpoint()
caf_assessment = CAFAssessment.objects.create(
caf_id=_caf2.id, completer_id=_completer.id, comments="Random Comments"
)