-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: require debug mode for browsable api (#36)
- Loading branch information
1 parent
30cceb2
commit c649dd1
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
from django.conf import settings | ||
from rest_framework.renderers import BrowsableAPIRenderer, JSONRenderer | ||
from wagtail.api.v2.router import WagtailAPIRouter | ||
from wagtail.images.api.v2.views import ImagesAPIViewSet | ||
|
||
# "Base" routes | ||
# Content/app specific routes existing in each individual app, not here | ||
|
||
|
||
class AppImagesAPIViewSet(ImagesAPIViewSet): | ||
# To disable rest_framework's default browsable renderer | ||
# - https://github.com/wagtail/wagtail/issues/6066 | ||
# (outlines how they secretly ignore/override default REST_FRAMEWORK config options) | ||
# - https://docs.wagtail.org/en/stable/advanced_topics/api/v2/configuration.html#enable-the-app | ||
# (says rest_framework is optional, it isn't) | ||
renderer_classes = [ | ||
JSONRenderer, | ||
] | ||
|
||
|
||
if settings.DEBUG: | ||
AppImagesAPIViewSet.renderer_classes = [ | ||
JSONRenderer, | ||
BrowsableAPIRenderer, | ||
] | ||
|
||
api_router = WagtailAPIRouter("wagtailapi") | ||
api_router.register_endpoint("images", ImagesAPIViewSet) | ||
api_router.register_endpoint("images", AppImagesAPIViewSet) |