Skip to content

Commit

Permalink
option to delete report
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Dec 4, 2023
1 parent 7bee7b7 commit 53b5cb5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion validity/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ class NameSetViewSet(NetBoxModelViewSet):
filterset_class = filtersets.NameSetFilterSet


class ComplianceReportViewSet(ReadOnlyNetboxViewSet):
class ComplianceReportViewSet(NetBoxModelViewSet):
queryset = models.ComplianceReport.objects.annotate_result_stats().count_devices_and_tests()
serializer_class = serializers.ComplianceReportSerializer
http_method_names = ["get", "head", "options", "trace", "delete"]


class DeviceReportView(ListAPIView):
Expand Down
5 changes: 4 additions & 1 deletion validity/models/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ class Meta:
ordering = ("-created",)

def __str__(self) -> str:
return f"report-{self.pk}"
# Without this hack django.messages displays report deletion as "Deleted report-None"
if "__str__" not in self.__dict__:
self.__dict__["__str__"] = f"report-{self.pk}"
return self.__dict__["__str__"]
3 changes: 2 additions & 1 deletion validity/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django_tables2 import Column, RequestConfig, Table, TemplateColumn
from netbox.tables import BooleanColumn as BooleanColumn
from netbox.tables import ChoiceFieldColumn, ManyToManyColumn, NetBoxTable
from netbox.tables.columns import ActionsColumn
from utilities.paginator import EnhancedPaginator

from validity import models
Expand Down Expand Up @@ -151,6 +152,7 @@ class ComplianceReportTable(NetBoxTable):
low_stats = StatsColumn(data_prefix="low", verbose_name=_("Low Severity"), empty_values=())
middle_stats = StatsColumn(data_prefix="middle", verbose_name=_("Middle Severity"), empty_values=())
high_stats = StatsColumn(data_prefix="high", verbose_name=_("High Severity"), empty_values=())
actions = ActionsColumn(actions=("delete",))

class Meta(NetBoxTable.Meta):
model = models.ComplianceReport
Expand All @@ -165,7 +167,6 @@ class Meta(NetBoxTable.Meta):
"high_stats",
"created",
)
exclude = ("actions",)
default_columns = fields


Expand Down
8 changes: 7 additions & 1 deletion validity/templates/validity/compliancereport.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{% extends 'generic/object.html' %}
{% load validity %}
{% load bootstrap5 %}
{% load buttons %}
{% load perms %}
{% load render_table from django_tables2 %}
{% block controls %}
<div class="controls"></div>
<div class="controls">
{% if request.user|can_delete:object %}
{% delete_button object %}
{% endif %}
</div>
{% endblock %}
{% block content %}
<div class="row">
Expand Down
4 changes: 2 additions & 2 deletions validity/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class TestDSNameSet(ViewTest):
class TestReport(ViewTest):
factory_class = ReportFactory
model_class = models.ComplianceReport
get_suffixes = ["", "list"]
post_suffixes = []
get_suffixes = ["", "list", "delete"]
post_suffixes = ["delete"]
post_body = {}


Expand Down
5 changes: 5 additions & 0 deletions validity/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ class ReportResultView(TestResultBaseView):
read_only = True
exclude_form_fields = ("latest", "selector_id", "platform_id", "tenant_id", "device_role_id", "manufacturer_id")
permission_required = "view_compliancereport"


@register_model_view(models.ComplianceReport, "delete")
class ReportDeleteView(generic.ObjectDeleteView):
queryset = models.ComplianceReport.objects.all()

0 comments on commit 53b5cb5

Please sign in to comment.