From 47c71a0aa69b874c1eb280026160dbb2891da488 Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:09:08 +0000 Subject: [PATCH] Add status tag in release admin, and allow filtering by status --- controlpanel/api/models/tool.py | 24 +++++++++++++++++++ controlpanel/frontend/filters.py | 19 ++++++++------- .../frontend/jinja2/release-list.html | 6 +++-- tests/api/models/test_tool.py | 22 +++++++++++++++++ tests/frontend/views/test_release.py | 4 ++-- 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/controlpanel/api/models/tool.py b/controlpanel/api/models/tool.py index 943ea8da3..6eddfe883 100644 --- a/controlpanel/api/models/tool.py +++ b/controlpanel/api/models/tool.py @@ -33,6 +33,10 @@ class Tool(TimeStampedModel): JUPYTER_LAB_CHART_NAME = "jupyter-lab" RSTUDIO_CHART_NAME = "rstudio" VSCODE_CHART_NAME = "vscode" + STATUS_RETIRED = "retired" + STATUS_DEPRECATED = "deprecated" + STATUS_ACTIVE = "active" + STATUS_RESTRICTED = "restricted" description = models.TextField(blank=False) chart_name = models.CharField(max_length=100, blank=False) @@ -107,6 +111,26 @@ def image_tag_key(self): } return mapping[self.chart_name] + @property + def status(self): + if self.is_retired: + return self.STATUS_RETIRED.capitalize() + if self.is_deprecated: + return self.STATUS_DEPRECATED.capitalize() + if self.is_restricted: + return self.STATUS_RESTRICTED.capitalize() + return self.STATUS_ACTIVE.capitalize() + + @property + def status_colour(self): + mapping = { + self.STATUS_RETIRED: "red", + self.STATUS_DEPRECATED: "grey", + self.STATUS_RESTRICTED: "yellow", + self.STATUS_ACTIVE: "green", + } + return mapping[self.status.lower()] + class ToolDeploymentManager: """ diff --git a/controlpanel/frontend/filters.py b/controlpanel/frontend/filters.py index a1a98c347..ed3430256 100644 --- a/controlpanel/frontend/filters.py +++ b/controlpanel/frontend/filters.py @@ -29,15 +29,14 @@ class ReleaseFilter(InitialFilterSetMixin): # is_restricted = django_filters.BooleanFilter(label="Restricted release?") status = django_filters.ChoiceFilter( choices=[ - ("active", "Active"), - ("unrestricted", "Unrestricted"), - ("restricted", "Restricted"), - ("deprecated", "Deprecated"), - ("retired", "Retired"), + (Tool.STATUS_ACTIVE, Tool.STATUS_ACTIVE.capitalize()), + (Tool.STATUS_RESTRICTED, Tool.STATUS_RESTRICTED.capitalize()), + (Tool.STATUS_DEPRECATED, Tool.STATUS_DEPRECATED.capitalize()), + (Tool.STATUS_RETIRED, Tool.STATUS_RETIRED.capitalize()), ("all", "All"), ], method="filter_status", - label="Availability", + label="Status", empty_label=None, initial="active", ) @@ -59,10 +58,12 @@ def __init__(self, data=None, *args, **kwargs): def filter_status(self, queryset, name, value): if value == "all": return queryset + if value == "retired": + return queryset.filter(is_retired=True) + # remove retired tools from the list + queryset = queryset.filter(is_retired=False) if value == "active": - return queryset.filter(is_retired=False) - if value == "unrestricted": - return queryset.filter(is_restricted=False) + return queryset.filter(is_restricted=False, is_deprecated=False) return queryset.filter( **{ f"is_{value}": True, diff --git a/controlpanel/frontend/jinja2/release-list.html b/controlpanel/frontend/jinja2/release-list.html index 11ebb9b47..ef5742cef 100644 --- a/controlpanel/frontend/jinja2/release-list.html +++ b/controlpanel/frontend/jinja2/release-list.html @@ -45,7 +45,7 @@