diff --git a/controlpanel/api/models/tool.py b/controlpanel/api/models/tool.py index 943ea8da..6eddfe88 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 a1a98c34..ed343025 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 11ebb9b4..ef5742ce 100644 --- a/controlpanel/frontend/jinja2/release-list.html +++ b/controlpanel/frontend/jinja2/release-list.html @@ -45,7 +45,7 @@ <h2 class="govuk-heading-m">Filter</h2> <th class="govuk-table__header">Image tag</th> <th class="govuk-table__header">Description</th> <th class="govuk-table__header">Created</th> - <th class="govuk-table__header">Restricted Release?</th> + <th class="govuk-table__header">Status</th> <th class="govuk-table__header"> <span class="govuk-visually-hidden">Actions</span> </th> @@ -72,7 +72,9 @@ <h2 class="govuk-heading-m">Filter</h2> {{ release.created.strftime('%d-%m-%Y') }} </td> <td class="govuk-table__cell"> - {{ release.is_restricted }} + <strong class="govuk-tag govuk-tag--{{ release.status_colour }}"> + {{ release.status }} + </strong> </td> <td class="govuk-table__cell"> <a href="{{ url('manage-tool-release', kwargs={ "pk": release.pk }) }}" diff --git a/tests/api/models/test_tool.py b/tests/api/models/test_tool.py index fdf013a9..ecd38ad9 100644 --- a/tests/api/models/test_tool.py +++ b/tests/api/models/test_tool.py @@ -125,3 +125,25 @@ def test_get_deprecated_message(tool): assert tool.get_deprecated_message == "This tool is deprecated" tool.is_retired = True assert tool.get_deprecated_message == "" + + +def test_tool_status(): + tool = Tool(is_restricted=False, is_deprecated=False, is_retired=False) + assert tool.status == "Active" + tool.is_restricted = True + assert tool.status == "Restricted" + tool.is_deprecated = True + assert tool.status == "Deprecated" + tool.is_retired = True + assert tool.status == "Retired" + + +def test_status_colour(): + tool = Tool(is_restricted=False, is_deprecated=False, is_retired=False) + assert tool.status_colour == "green" + tool.is_restricted = True + assert tool.status_colour == "yellow" + tool.is_deprecated = True + assert tool.status_colour == "grey" + tool.is_retired = True + assert tool.status_colour == "red" diff --git a/tests/frontend/views/test_release.py b/tests/frontend/views/test_release.py index 4da5ffd0..29f9ff01 100644 --- a/tests/frontend/views/test_release.py +++ b/tests/frontend/views/test_release.py @@ -35,8 +35,8 @@ def test_release_detail_context_data(): ({}, 2), ({"chart_name": "rstudio"}, 1), ({"chart_name": "jupyter-lab"}, 1), - ({"is_restricted": "true"}, 0), - ({"is_restricted": "false"}, 2), + ({"status": "restricted"}, 0), + ({"status": "active"}, 2), ], ) def test_release_list_get_context_data(rf, data, count):