Add deletion links for modules

This commit is contained in:
jeremystretch 2023-03-24 09:22:25 -04:00
parent b2bba7fc40
commit bfccd6820e
5 changed files with 38 additions and 14 deletions

View File

@ -855,6 +855,13 @@ class ScriptModule(JobResultsMixin, WebhooksMixin, PythonModuleMixin, ManagedFil
self.file_root = SCRIPTS_ROOT_NAME
return super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse('extras:script_list')
@property
def name(self):
return self.file_path
#
# Reports
@ -886,3 +893,6 @@ class ReportModule(JobResultsMixin, WebhooksMixin, PythonModuleMixin, ManagedFil
def save(self, *args, **kwargs):
self.file_root = REPORTS_ROOT_NAME
return super().save(*args, **kwargs)
def get_absolute_url(self):
return reverse('extras:report_list')

View File

@ -94,17 +94,17 @@ urlpatterns = [
# Reports
path('reports/', views.ReportListView.as_view(), name='report_list'),
path('reports/results/<int:job_result_pk>/', views.ReportResultView.as_view(), name='report_result'),
re_path(r'^reports/(?P<module>.([^.]+)).(?P<name>.(.+))/', views.ReportView.as_view(), name='report'),
path('reports/add/', views.ScriptModuleCreateView.as_view(), name='reportmodule_add'),
path('reports/results/<int:job_result_pk>/', views.ReportResultView.as_view(), name='report_result'),
path('reports/<int:pk>/', include(get_model_urls('extras', 'reportmodule'))),
path('reports/<str:module>.<str:name>/', views.ReportView.as_view(), name='report'),
# Scripts
path('scripts/', views.ScriptListView.as_view(), name='script_list'),
path('scripts/results/<int:job_result_pk>/', views.ScriptResultView.as_view(), name='script_result'),
re_path(r'^scripts/(?P<module>.([^.]+)).(?P<name>.(.+))/', views.ScriptView.as_view(), name='script'),
path('scripts/add/', views.ScriptModuleCreateView.as_view(), name='scriptmodule_add'),
path('scripts/results/<int:job_result_pk>/', views.ScriptResultView.as_view(), name='script_result'),
path('scripts/<int:pk>/', include(get_model_urls('extras', 'scriptmodule'))),
path('scripts/<str:module>.<str:name>/', views.ScriptView.as_view(), name='script'),
# Job results
path('job-results/', views.JobResultListView.as_view(), name='jobresult_list'),

View File

@ -79,15 +79,15 @@ def get_modules(queryset, litmus_func, ordering_attr):
Returns a list of tuples:
[
(module_name, (child, child, ...)),
(module_name, (child, child, ...)),
(module, (child, child, ...)),
(module, (child, child, ...)),
...
]
"""
results = {}
modules = [mf.get_module_info() for mf in queryset]
modules_bases = set([name.split(".")[0] for _, name, _ in modules])
modules = [(mf, *mf.get_module_info()) for mf in queryset]
modules_bases = set([name.split(".")[0] for _, _, name, _ in modules])
# Deleting from sys.modules needs to done behind a lock to prevent race conditions where a module is
# removed from sys.modules while another thread is importing
@ -100,7 +100,7 @@ def get_modules(queryset, litmus_func, ordering_attr):
if module_base in ('reports', 'scripts', *modules_bases):
del sys.modules[module_name]
for importer, module_name, _ in modules:
for mf, importer, module_name, _ in modules:
module = importer.find_module(module_name).load_module(module_name)
child_order = getattr(module, ordering_attr, ())
ordered_children = [cls() for cls in child_order if litmus_func(cls)]
@ -114,6 +114,6 @@ def get_modules(queryset, litmus_func, ordering_attr):
children[child_name] = cls
if children:
results[module_name] = children
results[mf] = children
return results

View File

@ -28,8 +28,15 @@
{% for module, module_reports in reports %}
<div class="card">
<h5 class="card-header">
<a name="module.{{ module }}"></a>
<i class="mdi mdi-file-document-outline"></i> {{ module|bettertitle }}
{% if perms.extras.delete_reportmodule %}
<div class="float-end">
<a href="{% url 'extras:reportmodule_delete' pk=module.pk %}" class="btn btn-danger btn-sm">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete
</a>
</div>
{% endif %}
<a name="module.{{ module.name }}"></a>
<i class="mdi mdi-file-document-outline"></i> {{ module.name|bettertitle }}
</h5>
<div class="card-body">
<table class="table table-hover table-headings reports">

View File

@ -27,8 +27,15 @@
{% for module, module_scripts in scripts.items %}
<div class="card">
<h5 class="card-header">
<a name="module.{{ module }}"></a>
<i class="mdi mdi-file-document-outline"></i> {{ module|bettertitle }}
{% if perms.extras.delete_scriptmodule %}
<div class="float-end">
<a href="{% url 'extras:scriptmodule_delete' pk=module.pk %}" class="btn btn-danger btn-sm">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete
</a>
</div>
{% endif %}
<a name="module.{{ module.name }}"></a>
<i class="mdi mdi-file-document-outline"></i> {{ module.name|bettertitle }}
</h5>
<div class="card-body">
<table class="table table-hover table-headings reports">