1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Introduced the REPORTS_ROOT config parameter; Python2 fixes

This commit is contained in:
Jeremy Stretch
2017-10-11 14:03:35 -04:00
parent 51194e20f2
commit fdae3a3f31
5 changed files with 20 additions and 5 deletions

View File

@ -145,7 +145,7 @@ An API consumer can request an arbitrary number of objects by appending the "lim
Default: $BASE_DIR/netbox/media/ Default: $BASE_DIR/netbox/media/
The file path to the location where media files (such as image attachments) are stored. By default, this is the `netbox/media` directory within the base NetBox installation path. The file path to the location where media files (such as image attachments) are stored. By default, this is the `netbox/media/` directory within the base NetBox installation path.
--- ---
@ -207,6 +207,14 @@ When determining the primary IP address for a device, IPv6 is preferred over IPv
--- ---
## REPORTS_ROOT
Default: $BASE_DIR/netbox/reports/
The file path to the location where custom reports will be kept. By default, this is the `netbox/reports/` directory within the base NetBox installation path.
---
## TIME_ZONE ## TIME_ZONE
Default: UTC Default: UTC

View File

@ -1,13 +1,14 @@
from __future__ import unicode_literals
from collections import OrderedDict from collections import OrderedDict
import importlib import importlib
import inspect import inspect
import pkgutil import pkgutil
from django.conf import settings
from django.utils import timezone from django.utils import timezone
from .constants import LOG_DEFAULT, LOG_FAILURE, LOG_INFO, LOG_LEVEL_CODES, LOG_SUCCESS, LOG_WARNING from .constants import LOG_DEFAULT, LOG_FAILURE, LOG_INFO, LOG_LEVEL_CODES, LOG_SUCCESS, LOG_WARNING
from .models import ReportResult from .models import ReportResult
import reports as custom_reports
def is_report(obj): def is_report(obj):
@ -42,9 +43,9 @@ def get_reports():
""" """
module_list = [] module_list = []
# Iterate through all modules within the reports path. These are the user-defined files in which reports are # Iterate through all modules within the reports path. These are the user-created files in which reports are
# defined. # defined.
for importer, module_name, is_pkg in pkgutil.walk_packages(custom_reports.__path__): for importer, module_name, is_pkg in pkgutil.walk_packages([settings.REPORTS_ROOT]):
module = importlib.import_module('reports.{}'.format(module_name)) module = importlib.import_module('reports.{}'.format(module_name))
report_list = [cls() for _, cls in inspect.getmembers(module, is_report)] report_list = [cls() for _, cls in inspect.getmembers(module, is_report)]
module_list.append((module_name, report_list)) module_list.append((module_name, report_list))

View File

@ -118,6 +118,10 @@ PAGINATE_COUNT = 50
# prefer IPv4 instead. # prefer IPv4 instead.
PREFER_IPV4 = False PREFER_IPV4 = False
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
# this setting is derived from the installed location.
# REPORTS_ROOT = '/opt/netbox/netbox/reports'
# Time zone (default: UTC) # Time zone (default: UTC)
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'

View File

@ -54,6 +54,7 @@ NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30)
NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {})
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/')
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d') SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i') SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s') SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s')

View File

@ -52,7 +52,8 @@
{% endfor %} {% endfor %}
{% else %} {% else %}
<div class="alert alert-info"> <div class="alert alert-info">
<strong>No reports found.</strong> <p><strong>No reports found.</strong></p>
<p>Reports should be saved to <code>{{ settings.REPORTS_ROOT }}</code>. (This path can be changed by setting <code>REPORTS_ROOT</code> in NetBox's configuration.)</p>
</div> </div>
{% endif %} {% endif %}
</div> </div>