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 2d1fc54
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 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):
if self.is_retired:
return "red"
if self.is_deprecated:
return "grey"
if self.is_restricted:
return "yellow"
return "green"


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

0 comments on commit 2d1fc54

Please sign in to comment.