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

Add MAINTENANCE_MODE, MAPS_URL

This commit is contained in:
jeremystretch
2021-10-26 10:57:33 -04:00
parent 559dc2f865
commit 94804fecd8
7 changed files with 25 additions and 18 deletions

View File

@ -28,9 +28,9 @@ class ConfigRevisionAdmin(admin.ModelAdmin):
# ('Pagination', { # ('Pagination', {
# 'fields': ('MAX_PAGE_SIZE', 'PAGINATE_COUNT'), # 'fields': ('MAX_PAGE_SIZE', 'PAGINATE_COUNT'),
# }), # }),
# ('Miscellaneous', { ('Miscellaneous', {
# 'fields': ('GRAPHQL_ENABLED', 'METRICS_ENABLED', 'MAINTENANCE_MODE', 'MAPS_URL'), 'fields': ('MAINTENANCE_MODE', 'MAPS_URL'),
# }), }),
('Config Revision', { ('Config Revision', {
'fields': ('comment',), 'fields': ('comment',),
}) })

View File

@ -56,14 +56,14 @@ PARAMS = (
# Racks # Racks
ConfigParam( ConfigParam(
name='RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', name='RACK_ELEVATION_DEFAULT_UNIT_HEIGHT',
label='Rack Unit Height', label='Rack unit height',
default=22, default=22,
description="Default unit height for rendered rack elevations", description="Default unit height for rendered rack elevations",
field=forms.IntegerField field=forms.IntegerField
), ),
ConfigParam( ConfigParam(
name='RACK_ELEVATION_DEFAULT_UNIT_WIDTH', name='RACK_ELEVATION_DEFAULT_UNIT_WIDTH',
label='Rack Unit Width', label='Rack unit width',
default=220, default=220,
description="Default unit width for rendered rack elevations", description="Default unit width for rendered rack elevations",
field=forms.IntegerField field=forms.IntegerField
@ -82,4 +82,19 @@ PARAMS = (
field_kwargs={'base_field': forms.CharField()} field_kwargs={'base_field': forms.CharField()}
), ),
# Miscellaneous
ConfigParam(
name='MAINTENANCE_MODE',
label='Maintenance mode',
default=False,
description="Enable maintenance mode",
field=OptionalBooleanField
),
ConfigParam(
name='MAPS_URL',
label='Maps URL',
default='https://maps.google.com/?q=',
description="Base URL for mapping geographic locations"
),
) )

View File

@ -158,12 +158,6 @@ LOGIN_REQUIRED = False
# re-authenticate. (Default: 1209600 [14 days]) # re-authenticate. (Default: 1209600 [14 days])
LOGIN_TIMEOUT = None LOGIN_TIMEOUT = None
# Setting this to True will display a "maintenance mode" banner at the top of every page.
MAINTENANCE_MODE = False
# The URL to use when mapping physical addresses or GPS coordinates
MAPS_URL = 'https://maps.google.com/?q='
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g. # An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request # "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
# all objects by specifying "?limit=0". # all objects by specifying "?limit=0".

View File

@ -128,8 +128,6 @@ GRAPHQL_ENABLED = getattr(configuration, 'GRAPHQL_ENABLED', True)
LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False) LOGIN_PERSISTENCE = getattr(configuration, 'LOGIN_PERSISTENCE', False)
LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False) LOGIN_REQUIRED = getattr(configuration, 'LOGIN_REQUIRED', False)
LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None) LOGIN_TIMEOUT = getattr(configuration, 'LOGIN_TIMEOUT', None)
MAINTENANCE_MODE = getattr(configuration, 'MAINTENANCE_MODE', False)
MAPS_URL = getattr(configuration, 'MAPS_URL', 'https://maps.google.com/?q=')
MAX_PAGE_SIZE = getattr(configuration, 'MAX_PAGE_SIZE', 1000) MAX_PAGE_SIZE = getattr(configuration, 'MAX_PAGE_SIZE', 1000)
METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False) METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False)
NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {})

View File

@ -64,7 +64,7 @@
</div> </div>
{% endif %} {% endif %}
{% if settings.MAINTENANCE_MODE %} {% if config.MAINTENANCE_MODE %}
<div class="alert alert-warning text-center mx-3" role="alert"> <div class="alert alert-warning text-center mx-3" role="alert">
<h4><i class="mdi mdi-alert"></i> Maintenance Mode</h4> <h4><i class="mdi mdi-alert"></i> Maintenance Mode</h4>
<span>NetBox is currently in maintenance mode. Functionality may be limited.</span> <span>NetBox is currently in maintenance mode. Functionality may be limited.</span>

View File

@ -100,7 +100,7 @@
<td> <td>
{% if object.physical_address %} {% if object.physical_address %}
<div class="float-end noprint"> <div class="float-end noprint">
<a href="{{ settings.MAPS_URL }}{{ object.physical_address|urlencode }}" target="_blank" class="btn btn-primary btn-sm"> <a href="{{ config.MAPS_URL }}{{ object.physical_address|urlencode }}" target="_blank" class="btn btn-primary btn-sm">
<i class="mdi mdi-map-marker"></i> Map It <i class="mdi mdi-map-marker"></i> Map It
</a> </a>
</div> </div>
@ -119,7 +119,7 @@
<td> <td>
{% if object.latitude and object.longitude %} {% if object.latitude and object.longitude %}
<div class="float-end noprint"> <div class="float-end noprint">
<a href="{{ settings.MAPS_URL }}{{ object.latitude }},{{ object.longitude }}" target="_blank" class="btn btn-primary btn-sm"> <a href="{{ config.MAPS_URL }}{{ object.latitude }},{{ object.longitude }}" target="_blank" class="btn btn-primary btn-sm">
<i class="mdi mdi-map-marker"></i> Map It <i class="mdi mdi-map-marker"></i> Map It
</a> </a>
</div> </div>

View File

@ -1,6 +1,5 @@
import logging import logging
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
@ -14,6 +13,7 @@ from django.utils.http import is_safe_url
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic import View from django.views.generic import View
from netbox.config import Config
from utilities.forms import ConfirmationForm from utilities.forms import ConfirmationForm
from .forms import LoginForm, PasswordChangeForm, TokenForm from .forms import LoginForm, PasswordChangeForm, TokenForm
from .models import Token from .models import Token
@ -53,7 +53,7 @@ class LoginView(View):
# If maintenance mode is enabled, assume the database is read-only, and disable updating the user's # If maintenance mode is enabled, assume the database is read-only, and disable updating the user's
# last_login time upon authentication. # last_login time upon authentication.
if settings.MAINTENANCE_MODE: if Config().MAINTENANCE_MODE:
logger.warning("Maintenance mode enabled: disabling update of most recent login time") logger.warning("Maintenance mode enabled: disabling update of most recent login time")
user_logged_in.disconnect(update_last_login, dispatch_uid='update_last_login') user_logged_in.disconnect(update_last_login, dispatch_uid='update_last_login')