mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Closes #12085: Add a file source view for reports
This commit is contained in:
parent
715592547c
commit
c4891fe105
@ -59,6 +59,7 @@ Two new webhook trigger events have been introduced: `job_start` and `job_end`.
|
||||
* [#11693](https://github.com/netbox-community/netbox/issues/11693) - Enable syncing export template content from remote sources
|
||||
* [#11780](https://github.com/netbox-community/netbox/issues/11780) - Enable loading import data from remote sources
|
||||
* [#11968](https://github.com/netbox-community/netbox/issues/11968) - Add navigation menu buttons to create device & VM components
|
||||
* [#12085](https://github.com/netbox-community/netbox/issues/12085) - Add a file source view for reports
|
||||
|
||||
### Other Changes
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import inspect
|
||||
import logging
|
||||
import traceback
|
||||
from datetime import timedelta
|
||||
@ -127,6 +128,14 @@ class Report(object):
|
||||
"""
|
||||
return self.class_name
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
return inspect.getfile(self.__class__)
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
return inspect.getsource(self.__class__)
|
||||
|
||||
#
|
||||
# Logging methods
|
||||
#
|
||||
|
@ -98,6 +98,7 @@ urlpatterns = [
|
||||
path('reports/results/<int:job_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'),
|
||||
path('reports/<str:module>/<str:name>/source/', views.ReportSourceView.as_view(), name='report_source'),
|
||||
path('reports/<str:module>/<str:name>/jobs/', views.ReportJobsView.as_view(), name='report_jobs'),
|
||||
|
||||
# Scripts
|
||||
|
@ -887,6 +887,22 @@ class ReportView(ContentTypePermissionRequiredMixin, View):
|
||||
})
|
||||
|
||||
|
||||
class ReportSourceView(ContentTypePermissionRequiredMixin, View):
|
||||
|
||||
def get_required_permission(self):
|
||||
return 'extras.view_report'
|
||||
|
||||
def get(self, request, module, name):
|
||||
module = get_object_or_404(ReportModule.objects.restrict(request.user), file_path__startswith=module)
|
||||
report = module.reports[name]()
|
||||
|
||||
return render(request, 'extras/report/source.html', {
|
||||
'module': module,
|
||||
'report': report,
|
||||
'tab': 'source',
|
||||
})
|
||||
|
||||
|
||||
class ReportJobsView(ContentTypePermissionRequiredMixin, View):
|
||||
|
||||
def get_required_permission(self):
|
||||
|
@ -28,6 +28,9 @@
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link{% if not tab %} active{% endif %}" href="{% url 'extras:report' module=report.module name=report.class_name %}">Report</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link{% if tab == 'source' %} active{% endif %}" href="{% url 'extras:report_source' module=report.module name=report.class_name %}">Source</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link{% if tab == 'jobs' %} active{% endif %}" href="{% url 'extras:report_jobs' module=report.module name=report.class_name %}">Jobs</a>
|
||||
</li>
|
||||
|
6
netbox/templates/extras/report/source.html
Normal file
6
netbox/templates/extras/report/source.html
Normal file
@ -0,0 +1,6 @@
|
||||
{% extends 'extras/report/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<code class="h6 my-3 d-block">{{ report.filename }}</code>
|
||||
<pre class="block">{{ report.source }}</pre>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user