Skip to content

Commit

Permalink
Custom tables configuration (#113)
Browse files Browse the repository at this point in the history
* configure button for custom tables

* configurable tables
  • Loading branch information
amyasnikov authored Sep 22, 2024
1 parent c43550e commit 430f42a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions validity/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def render(self, value):
return result if result else "—"


class ComplianceReportDeviceTable(NetBoxTable):
class ComplianceReportDeviceTable(BaseTable):
device = TemplateColumn(
order_by=("_name",), template_code=DEVICE_LINK, linkify=True, accessor="name", attrs={"th": {"class": "col-2"}}
)
Expand All @@ -251,7 +251,7 @@ class ComplianceReportDeviceTable(NetBoxTable):
badge_color="danger",
)

class Meta(NetBoxTable.Meta):
class Meta(BaseTable.Meta):
model = models.VDevice
fields = ("device", "compliance_passed", "result_stats", "passed_results", "failed_results")
default_columns = fields
Expand Down
16 changes: 15 additions & 1 deletion validity/templates/validity/aux_tab_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@
</div>
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title mb-2">{% block table_title %}{% endblock %}</h5>
<div class="row mb-2">
<h5 class="col card-title">{% block table_title %}{% endblock %}</h5>
<div class="col-auto ms-auto d-print-none">
<div class="table-configure input-group">
<button type="button" data-bs-toggle="modal" title="Configure Table"
data-bs-target="#ObjectTable_config"
class="btn">
<i class="mdi mdi-cog"></i>Configure Table
</button>
</div>
</div>
</div>
<div class="table-responsive">
{% render_table table 'inc/table.html' %}
</div>
{%include 'inc/paginator.html' with paginator=table.paginator page=table.page%}
</div>
{% endblock %}
{% block modals %}
{% table_config_form table table_name="ObjectTable" %}
{% endblock modals %}
3 changes: 3 additions & 0 deletions validity/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def get_table(self, **kwargs):
table.exclude = (self.result_relation,)
return table

def get_table_kwargs(self):
return {"user": self.request.user}

def get_queryset(self):
return self.queryset.filter(**{self.result_relation: self.kwargs["pk"]})

Expand Down
4 changes: 4 additions & 0 deletions validity/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def get_queryset(self) -> QuerySet[models.VDevice]:
self.queryset.filter(results__report=self.object)
.annotate_result_stats(self.object.pk, severity_ge)
.prefetch_results(self.object.pk, severity_ge)
.order_by("_name")
)

def get_filterform_initial(self):
Expand All @@ -102,6 +103,9 @@ def get_table(self, **kwargs):
table.configure(self.request)
return table

def get_table_kwargs(self):
return {"user": self.request.user}

def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
return super().get_context_data(**kwargs) | {
"object": self.object,
Expand Down

0 comments on commit 430f42a

Please sign in to comment.