diff --git a/controlpanel/api/models/tool.py b/controlpanel/api/models/tool.py index 943ea8da..23acfbe1 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): + if self.is_retired: + return "red" + if self.is_deprecated: + return "grey" + if self.is_restricted: + return "yellow" + return "green" + 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 @@