mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixed page titles in the browsable API
This commit is contained in:
@ -221,6 +221,7 @@ SECRETS_MIN_PUBKEY_SIZE = 2048
|
|||||||
# Django REST framework (API)
|
# Django REST framework (API)
|
||||||
REST_FRAMEWORK_VERSION = VERSION[0:3] # Use major.minor as API version
|
REST_FRAMEWORK_VERSION = VERSION[0:3] # Use major.minor as API version
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
|
'ALLOWED_VERSIONS': [REST_FRAMEWORK_VERSION],
|
||||||
'DEFAULT_AUTHENTICATION_CLASSES': (
|
'DEFAULT_AUTHENTICATION_CLASSES': (
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
'utilities.api.TokenAuthentication',
|
'utilities.api.TokenAuthentication',
|
||||||
@ -233,9 +234,9 @@ REST_FRAMEWORK = {
|
|||||||
'utilities.api.TokenPermissions',
|
'utilities.api.TokenPermissions',
|
||||||
),
|
),
|
||||||
'DEFAULT_VERSION': REST_FRAMEWORK_VERSION,
|
'DEFAULT_VERSION': REST_FRAMEWORK_VERSION,
|
||||||
'ALLOWED_VERSIONS': [REST_FRAMEWORK_VERSION],
|
|
||||||
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
||||||
'PAGE_SIZE': PAGINATE_COUNT,
|
'PAGE_SIZE': PAGINATE_COUNT,
|
||||||
|
'VIEW_NAME_FUNCTION': 'utilities.api.get_view_name',
|
||||||
}
|
}
|
||||||
|
|
||||||
# Django debug toolbar
|
# Django debug toolbar
|
||||||
|
@ -9,6 +9,7 @@ from rest_framework.exceptions import APIException
|
|||||||
from rest_framework.pagination import LimitOffsetPagination
|
from rest_framework.pagination import LimitOffsetPagination
|
||||||
from rest_framework.permissions import BasePermission, DjangoModelPermissions, SAFE_METHODS
|
from rest_framework.permissions import BasePermission, DjangoModelPermissions, SAFE_METHODS
|
||||||
from rest_framework.serializers import Field, ModelSerializer, ValidationError
|
from rest_framework.serializers import Field, ModelSerializer, ValidationError
|
||||||
|
from rest_framework.views import get_view_name as drf_get_view_name
|
||||||
|
|
||||||
from users.models import Token
|
from users.models import Token
|
||||||
|
|
||||||
@ -196,3 +197,21 @@ class OptionalLimitOffsetPagination(LimitOffsetPagination):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
return self.default_limit
|
return self.default_limit
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Miscellaneous
|
||||||
|
#
|
||||||
|
|
||||||
|
def get_view_name(view_cls, suffix=None):
|
||||||
|
"""
|
||||||
|
Derive the view name from its associated model, if it has one. Fall back to DRF's built-in `get_view_name`.
|
||||||
|
"""
|
||||||
|
if hasattr(view_cls, 'queryset'):
|
||||||
|
name = view_cls.queryset.model._meta.verbose_name
|
||||||
|
name = ' '.join([w[0].upper() + w[1:] for w in name.split()]) # Capitalize each word
|
||||||
|
if suffix:
|
||||||
|
name = "{} {}".format(name, suffix)
|
||||||
|
return name
|
||||||
|
|
||||||
|
return drf_get_view_name(view_cls, suffix)
|
||||||
|
Reference in New Issue
Block a user