Skip to content

Commit

Permalink
Add status tag in release admin, and allow filtering by status
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk committed Dec 13, 2024
1 parent e21a127 commit 47c71a0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
24 changes: 24 additions & 0 deletions controlpanel/api/models/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
"""
Expand Down
19 changes: 10 additions & 9 deletions controlpanel/frontend/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions controlpanel/frontend/jinja2/release-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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 }) }}"
Expand Down
22 changes: 22 additions & 0 deletions tests/api/models/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions tests/frontend/views/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 47c71a0

Please sign in to comment.