Skip to content

Commit

Permalink
Fixes netbox-community#1522: Removed object create/edit forms from th…
Browse files Browse the repository at this point in the history
…e browsable API
  • Loading branch information
jeremystretch authored and John Anderson committed Oct 13, 2017
1 parent 6f1e777 commit fa176a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions netbox/netbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@
'DEFAULT_PERMISSION_CLASSES': (
'utilities.api.TokenPermissions',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'utilities.api.FormlessBrowsableAPIRenderer',
),
'DEFAULT_VERSION': REST_FRAMEWORK_VERSION,
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
'PAGE_SIZE': PAGINATE_COUNT,
Expand Down
13 changes: 13 additions & 0 deletions netbox/utilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from rest_framework.exceptions import APIException
from rest_framework.pagination import LimitOffsetPagination
from rest_framework.permissions import BasePermission, DjangoModelPermissions, SAFE_METHODS
from rest_framework.renderers import BrowsableAPIRenderer
from rest_framework.serializers import Field, ModelSerializer, ValidationError
from rest_framework.views import get_view_name as drf_get_view_name

Expand Down Expand Up @@ -211,6 +212,18 @@ def get_limit(self, request):
return self.default_limit


#
# Renderers
#

class FormlessBrowsableAPIRenderer(BrowsableAPIRenderer):
"""
Override the built-in BrowsableAPIRenderer to disable HTML forms.
"""
def show_form_for_method(self, *args, **kwargs):
return False


#
# Miscellaneous
#
Expand Down

0 comments on commit fa176a6

Please sign in to comment.