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

Moved PAGINATE_COUNT to configuration.py

This commit is contained in:
Jeremy Stretch
2016-05-23 12:55:03 -04:00
parent 81fd1dfde4
commit c96bfdbc18
5 changed files with 45 additions and 28 deletions

View File

@ -1,7 +1,6 @@
from netaddr import IPSet from netaddr import IPSet
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Count from django.db.models import Count
@ -156,8 +155,7 @@ def aggregate(request, pk):
prefix_table.model = Prefix prefix_table.model = Prefix
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'): if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
prefix_table.base_columns['pk'].visible = True prefix_table.base_columns['pk'].visible = True
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\ RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(prefix_table)
.configure(prefix_table)
return render(request, 'ipam/aggregate.html', { return render(request, 'ipam/aggregate.html', {
'aggregate': aggregate, 'aggregate': aggregate,
@ -286,8 +284,7 @@ def prefix(request, pk):
child_prefix_table.model = Prefix child_prefix_table.model = Prefix
if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'): if request.user.has_perm('ipam.change_prefix') or request.user.has_perm('ipam.delete_prefix'):
child_prefix_table.base_columns['pk'].visible = True child_prefix_table.base_columns['pk'].visible = True
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\ RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(child_prefix_table)
.configure(child_prefix_table)
return render(request, 'ipam/prefix.html', { return render(request, 'ipam/prefix.html', {
'prefix': prefix, 'prefix': prefix,
@ -362,8 +359,7 @@ def prefix_ipaddresses(request, pk):
ip_table.model = IPAddress ip_table.model = IPAddress
if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'): if request.user.has_perm('ipam.change_ipaddress') or request.user.has_perm('ipam.delete_ipaddress'):
ip_table.base_columns['pk'].visible = True ip_table.base_columns['pk'].visible = True
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\ RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(ip_table)
.configure(ip_table)
return render(request, 'ipam/prefix_ipaddresses.html', { return render(request, 'ipam/prefix_ipaddresses.html', {
'prefix': prefix, 'prefix': prefix,
@ -389,10 +385,11 @@ def ipaddress(request, pk):
ipaddress = get_object_or_404(IPAddress.objects.select_related('interface__device'), pk=pk) ipaddress = get_object_or_404(IPAddress.objects.select_related('interface__device'), pk=pk)
parent_prefixes = Prefix.objects.filter(vrf=ipaddress.vrf, prefix__net_contains=str(ipaddress.address.ip)) parent_prefixes = Prefix.objects.filter(vrf=ipaddress.vrf, prefix__net_contains=str(ipaddress.address.ip))
related_ips = IPAddress.objects.select_related('interface__device').exclude(pk=ipaddress.pk).filter(vrf=ipaddress.vrf, address__net_contained_or_equal=str(ipaddress.address)) related_ips = IPAddress.objects.select_related('interface__device').exclude(pk=ipaddress.pk)\
.filter(vrf=ipaddress.vrf, address__net_contained_or_equal=str(ipaddress.address))
related_ips_table = tables.IPAddressBriefTable(related_ips) related_ips_table = tables.IPAddressBriefTable(related_ips)
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator}).configure(related_ips_table) RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(related_ips_table)
return render(request, 'ipam/ipaddress.html', { return render(request, 'ipam/ipaddress.html', {
'ipaddress': ipaddress, 'ipaddress': ipaddress,

View File

@ -1,20 +1,19 @@
#########################
# #
# Required settings #
# #
#########################
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file. # This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and # For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
# symbols. NetBox will not run without this defined. For more information, see # symbols. NetBox will not run without this defined. For more information, see
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = '' SECRET_KEY = ''
# If enabled, NetBox will run with debugging turned on. This should only be used for development or troubleshooting.
# NEVER ENABLE DEBUGGING ON A PRODUCTION SYSTEM.
DEBUG = False
# Set this to your server's FQDN. This is required when DEBUG = False. # Set this to your server's FQDN. This is required when DEBUG = False.
# E.g. ALLOWED_HOSTS = ['netbox.yourdomain.com'] # E.g. ALLOWED_HOSTS = ['netbox.yourdomain.com']
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
# Setting this to true will display a "maintenance mode" banner at the top of every page.
MAINTENANCE_MODE = False
# PostgreSQL database configuration. # PostgreSQL database configuration.
DATABASES = { DATABASES = {
'default': { 'default': {
@ -27,10 +26,28 @@ DATABASES = {
} }
} }
# If true, user authentication will be required for all site access. If false, unauthenticated users will be able to
#########################
# #
# Optional settings #
# #
#########################
# Setting this to True will display a "maintenance mode" banner at the top of every page.
MAINTENANCE_MODE = False
# If enabled, NetBox will run with debugging turned on. This should only be used for development or troubleshooting.
#
# NEVER ENABLE DEBUGGING ON A PRODUCTION SYSTEM!
DEBUG = False
# If True, user authentication will be required for all site access. If False, unauthenticated users will be able to
# access NetBox but not make any changes. # access NetBox but not make any changes.
LOGIN_REQUIRED = False LOGIN_REQUIRED = False
# Credentials that NetBox will use to access live devices. (Optional) # Determine how many objects to display per page within a list. (Default: 50)
PAGINATE_COUNT = 50
# Credentials that NetBox will use to access live devices.
NETBOX_USERNAME = '' NETBOX_USERNAME = ''
NETBOX_PASSWORD = '' NETBOX_PASSWORD = ''

View File

@ -1,9 +1,12 @@
import os import os
import socket import socket
from django.contrib.messages import constants as messages
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Application definition # Installed applications
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
@ -25,6 +28,7 @@ INSTALLED_APPS = (
'utilities', 'utilities',
) )
# Middleware
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -57,6 +61,7 @@ TEMPLATES = [
}, },
] ]
# WSGI
WSGI_APPLICATION = 'netbox.wsgi.application' WSGI_APPLICATION = 'netbox.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
@ -67,7 +72,6 @@ TIME_ZONE = 'UTC'
USE_I18N = True USE_I18N = True
USE_TZ = True USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/ # https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
@ -76,15 +80,11 @@ STATICFILES_DIRS = (
) )
# Messages # Messages
from django.contrib.messages import constants as messages
MESSAGE_TAGS = { MESSAGE_TAGS = {
messages.ERROR: 'danger', messages.ERROR: 'danger',
} }
# Pagination # Authentication URLs
PAGINATE_COUNT = 50
# Authentication
LOGIN_URL = '/login/' LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = '/'
LOGOUT_URL = '/logout/' LOGOUT_URL = '/logout/'

View File

@ -1,8 +1,13 @@
from django.conf import settings
from django.core.paginator import Paginator, Page from django.core.paginator import Paginator, Page
class EnhancedPaginator(Paginator): class EnhancedPaginator(Paginator):
def __init__(self, object_list, per_page, **kwargs):
per_page = getattr(settings, 'PAGINATE_COUNT', 50)
super(EnhancedPaginator, self).__init__(object_list, per_page, **kwargs)
def _get_page(self, *args, **kwargs): def _get_page(self, *args, **kwargs):
return EnhancedPage(*args, **kwargs) return EnhancedPage(*args, **kwargs)

View File

@ -1,6 +1,5 @@
from django_tables2 import RequestConfig from django_tables2 import RequestConfig
from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
@ -64,8 +63,7 @@ class ObjectListView(View):
table.model = model table.model = model
if 'pk' in table.base_columns and any([request.user.has_perm(perm) for perm in self.edit_permissions]): if 'pk' in table.base_columns and any([request.user.has_perm(perm) for perm in self.edit_permissions]):
table.base_columns['pk'].visible = True table.base_columns['pk'].visible = True
RequestConfig(request, paginate={'per_page': settings.PAGINATE_COUNT, 'klass': EnhancedPaginator})\ RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(table)
.configure(table)
return render(request, self.template_name, { return render(request, self.template_name, {
'table': table, 'table': table,