diff --git a/validity/navigation.py b/validity/navigation.py index 5033c81..5a228ce 100644 --- a/validity/navigation.py +++ b/validity/navigation.py @@ -2,90 +2,45 @@ from utilities.choices import ButtonColorChoices +def model_add_button(entity): + return PluginMenuButton( + link=f"plugins:validity:{entity}_add", + title="Add", + icon_class="mdi mdi-plus-thick", + color=ButtonColorChoices.GREEN, + permissions=[f"validity.add_{entity}"], + ) + + +def model_menu_item(entity, title, buttons=()): + buttons = [btn(entity) if callable(btn) else btn for btn in buttons] + return PluginMenuItem( + link=f"plugins:validity:{entity}_list", + link_text=title, + buttons=buttons or [], + permissions=[f"validity.view_{entity}"], + ) + + +run_tests_button = PluginMenuButton( + link="plugins:validity:compliancetest_run", + title="Run", + icon_class="mdi mdi-rocket-launch", + color=ButtonColorChoices.CYAN, +) + validity_menu_items = ( - PluginMenuItem( - link="plugins:validity:complianceselector_list", - link_text="Selectors", - buttons=[ - PluginMenuButton( - link="plugins:validity:complianceselector_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), - PluginMenuItem( - link="plugins:validity:compliancetest_list", - link_text="Tests", - buttons=[ - PluginMenuButton( - link="plugins:validity:compliancetest_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), - PluginMenuItem( - link="plugins:validity:compliancetestresult_list", - link_text="Test Results", - ), - PluginMenuItem( - link="plugins:validity:compliancereport_list", - link_text="Reports", - ), - PluginMenuItem( - link="plugins:validity:serializer_list", - link_text="Serializers", - buttons=[ - PluginMenuButton( - link="plugins:validity:serializer_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), - PluginMenuItem( - link="plugins:validity:nameset_list", - link_text="Name Sets", - buttons=[ - PluginMenuButton( - link="plugins:validity:nameset_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), + model_menu_item("complianceselector", "Selectors", [model_add_button]), + model_menu_item("compliancetest", "Tests", [run_tests_button, model_add_button]), + model_menu_item("compliancetestresult", "Test Results"), + model_menu_item("compliancereport", "Reports"), + model_menu_item("serializer", "Serializers", [model_add_button]), + model_menu_item("nameset", "Name Sets", [model_add_button]), ) polling_menu_items = ( - PluginMenuItem( - link="plugins:validity:poller_list", - link_text="Pollers", - buttons=[ - PluginMenuButton( - link="plugins:validity:poller_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), - PluginMenuItem( - link="plugins:validity:command_list", - link_text="Commands", - buttons=[ - PluginMenuButton( - link="plugins:validity:command_add", - title="Add", - icon_class="mdi mdi-plus-thick", - color=ButtonColorChoices.GREEN, - ), - ], - ), + model_menu_item("command", "Commands", [model_add_button]), + model_menu_item("poller", "Pollers", [model_add_button]), ) menu = PluginMenu( diff --git a/validity/urls.py b/validity/urls.py index db244c3..5b4e262 100644 --- a/validity/urls.py +++ b/validity/urls.py @@ -1,3 +1,4 @@ +from django.shortcuts import redirect from django.urls import include, path from utilities.urls import get_model_urls @@ -10,6 +11,11 @@ path("selectors/delete/", views.ComplianceSelectorBulkDeleteView.as_view(), name="complianceselector_bulk_delete"), path("selectors//", include(get_model_urls("validity", "complianceselector"))), path("tests/", views.ComplianceTestListView.as_view(), name="compliancetest_list"), + path( + "tests/run/", + lambda _: redirect("extras:script", module="validity_scripts", name="RunTests"), + name="compliancetest_run", + ), path("tests/add/", views.ComplianceTestEditView.as_view(), name="compliancetest_add"), path("tests/delete/", views.ComplianceTestBulkDeleteView.as_view(), name="compliancetest_bulk_delete"), path("tests//", include(get_model_urls("validity", "compliancetest"))),