From 9f4203128a60b4b58637f02baa3916587ecc2767 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:26:30 +0000 Subject: [PATCH] Update tool deployment field name --- controlpanel/api/views/tool_deployments.py | 2 +- controlpanel/frontend/forms.py | 8 ++++---- controlpanel/frontend/jinja2/tool-list.html | 4 ++-- .../static/javascripts/modules/tool-status.js | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/controlpanel/api/views/tool_deployments.py b/controlpanel/api/views/tool_deployments.py index b6207879..94712c4c 100644 --- a/controlpanel/api/views/tool_deployments.py +++ b/controlpanel/api/views/tool_deployments.py @@ -29,7 +29,7 @@ def _deploy(self): ) def post(self, request, *args, **kwargs): - self.serializer = self.get_serializer(data={"tool": request.data.get("version")}) + self.serializer = self.get_serializer(data=request.data) self.serializer.is_valid(raise_exception=True) tool_action = self.kwargs["action"] diff --git a/controlpanel/frontend/forms.py b/controlpanel/frontend/forms.py index 17a6c4e2..b2a3db71 100644 --- a/controlpanel/frontend/forms.py +++ b/controlpanel/frontend/forms.py @@ -682,7 +682,7 @@ def create_option(self, name, value, label, selected, index, subindex=None, attr class ToolForm(forms.Form): - version = forms.ModelChoiceField( + tool = forms.ModelChoiceField( queryset=Tool.objects.none(), empty_label=None, widget=ToolChoice(attrs={"class": "govuk-select govuk-!-width-full govuk-!-font-size-16"}), @@ -693,12 +693,12 @@ def __init__(self, *args, **kwargs): self.tool_type = kwargs.pop("tool_type") self.deployment = kwargs.pop("deployment", None) super().__init__(*args, **kwargs) - self.fields["version"].queryset = self.get_tool_release_choices(tool_type=self.tool_type) - self.fields["version"].widget.attrs.update( + self.fields["tool"].queryset = self.get_tool_release_choices(tool_type=self.tool_type) + self.fields["tool"].widget.attrs.update( {"data-action-target": self.tool_type, "id": f"tools-{self.tool_type}"} ) if self.deployment: - self.fields["version"].initial = self.deployment.tool + self.fields["tool"].initial = self.deployment.tool def get_tool_release_choices(self, tool_type: str): return Tool.objects.filter( diff --git a/controlpanel/frontend/jinja2/tool-list.html b/controlpanel/frontend/jinja2/tool-list.html index e5139362..0ff019ef 100644 --- a/controlpanel/frontend/jinja2/tool-list.html +++ b/controlpanel/frontend/jinja2/tool-list.html @@ -23,10 +23,10 @@

{{ tool_form.tool_type }}

method="post"> {{ csrf_input }}
-
diff --git a/controlpanel/frontend/static/javascripts/modules/tool-status.js b/controlpanel/frontend/static/javascripts/modules/tool-status.js index 4a7eba7f..4177a6c3 100644 --- a/controlpanel/frontend/static/javascripts/modules/tool-status.js +++ b/controlpanel/frontend/static/javascripts/modules/tool-status.js @@ -6,7 +6,7 @@ moj.Modules.toolStatus = { listenerClass: ".tool", statusLabelClass: ".tool-status-label", - versionSelector: "select[name='version']", + versionSelector: "select[name='tool']", versionNotInstalledClass: "not-installed", versionInstalledClass: "installed", installedSuffix: " (installed)", @@ -19,7 +19,7 @@ moj.Modules.toolStatus = { this.bindEvents(toolStatusListeners); } - // Bind version selects' change event listeners + // Bind tool selects' change event listeners const versionSelects = document.querySelectorAll(this.versionSelector); versionSelects.forEach(versionSelect => { versionSelect.addEventListener("change", (event) => this.versionSelectChanged(event.target)); @@ -68,7 +68,7 @@ moj.Modules.toolStatus = { }; }, - // Select the new version from the tool "version" select input + // Select the new tool from the tool select input updateAppVersion(listener, newVersionData) { const selectElement = listener.querySelector(this.versionSelector); @@ -80,7 +80,7 @@ moj.Modules.toolStatus = { notInstalledOption.remove(); } - // 2. remove "(installed)" suffix and class from old version + // 2. remove "(installed)" suffix and class from old tool version let oldVersionOption = selectElement.querySelector("option." + this.versionInstalledClass); if (oldVersionOption) { @@ -88,7 +88,7 @@ moj.Modules.toolStatus = { oldVersionOption.classList.remove(this.versionInstalledClass); } - // 3. add "(installed)" suffix and class to new version + // 3. add "(installed)" suffix and class to new tool version let newVersionOption = listener.querySelector(this.versionSelector + " option[value='" + newVersionData.tool_id + "']"); if (newVersionOption) { newVersionOption.label = newVersionOption.label + this.installedSuffix; @@ -141,7 +141,7 @@ moj.Modules.toolStatus = { }); }, - // version select "change" event handler + // tool version select "change" event handler versionSelectChanged(target) { const selected = target.options[target.options.selectedIndex]; const classes = selected.className.split(" ");