kopia lustrzana https://github.com/wagtail/wagtail
Merge branch 'kaedroho-drf-browsable-api'
commit
c4738fc3d5
|
@ -2,7 +2,7 @@ Wagtail API Installation
|
|||
========================
|
||||
|
||||
|
||||
To install, add ``wagtail.contrib.wagtailapi`` to ``INSTALLED_APPS`` in your Django settings and configure a URL for it in ``urls.py``
|
||||
To install, add ``wagtail.contrib.wagtailapi`` and ``rest_framework`` to ``INSTALLED_APPS`` in your Django settings and configure a URL for it in ``urls.py``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -11,6 +11,7 @@ To install, add ``wagtail.contrib.wagtailapi`` to ``INSTALLED_APPS`` in your Dja
|
|||
INSTALLED_APPS = [
|
||||
...
|
||||
'wagtail.contrib.wagtailapi',
|
||||
'rest_framework',
|
||||
]
|
||||
|
||||
# urls.py
|
||||
|
|
|
@ -45,6 +45,12 @@ See: :ref:`inline_panels`
|
|||
StreamField blocks now :ref:`provide a get_context method <streamfield_get_context>` that can be overridden to pass additional variables to the block's template.
|
||||
|
||||
|
||||
Browsable API
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
The Wagtail API now incorporates the browsable front-end provided by Django Rest Framework. Note that this must be enabled by adding ``'rest_framework'`` to your project's ``INSTALLED_APPS`` setting.
|
||||
|
||||
|
||||
Minor features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -135,3 +141,9 @@ can be rewritten as:
|
|||
.. code-block:: python
|
||||
|
||||
Image.objects.filter(uploaded_by_user=user).search("Hello")
|
||||
|
||||
|
||||
Wagtail API requires adding ``rest_framework`` to INSTALLED_APPS
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If you have the Wagtail API (``wagtail.contrib.wagtailapi``) enabled, you must now add ``'rest_framework'`` to your project's ``INSTALLED_APPS`` setting. In the current version the API will continue to function without this app, but the browsable front-end will not be available; this ability will be dropped in a future release.
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import warnings
|
||||
|
||||
from django.apps import AppConfig, apps
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
from wagtail.utils.deprecation import RemovedInWagtail14Warning
|
||||
|
||||
|
||||
class WagtailAPIAppConfig(AppConfig):
|
||||
name = 'wagtail.contrib.wagtailapi'
|
||||
|
@ -16,3 +20,9 @@ class WagtailAPIAppConfig(AppConfig):
|
|||
register_signal_handlers()
|
||||
else:
|
||||
raise ImproperlyConfigured("The setting 'WAGTAILAPI_USE_FRONTENDCACHE' is True but 'wagtail.contrib.wagtailfrontendcache' is not in INSTALLED_APPS.")
|
||||
|
||||
if not apps.is_installed('rest_framework'):
|
||||
warnings.warn(
|
||||
"The 'wagtailapi' module now requires 'rest_framework' to be installed. "
|
||||
"Please add 'rest_framework' to INSTALLED_APPS.",
|
||||
RemovedInWagtail14Warning)
|
||||
|
|
|
@ -5,11 +5,12 @@ from collections import OrderedDict
|
|||
from django.conf.urls import url
|
||||
from django.http import Http404
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.apps import apps
|
||||
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import GenericViewSet
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.renderers import JSONRenderer, BrowsableAPIRenderer
|
||||
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.wagtailimages.models import get_image_model
|
||||
|
@ -27,10 +28,17 @@ from .utils import BadRequestError
|
|||
|
||||
class BaseAPIEndpoint(GenericViewSet):
|
||||
renderer_classes = [JSONRenderer]
|
||||
|
||||
# The BrowsableAPIRenderer requires rest_framework to be installed
|
||||
# Remove this check in Wagtail 1.4 as rest_framework will be required
|
||||
# RemovedInWagtail14Warning
|
||||
if apps.is_installed('rest_framework'):
|
||||
renderer_classes.append(BrowsableAPIRenderer)
|
||||
|
||||
pagination_class = WagtailPagination
|
||||
base_serializer_class = BaseSerializer
|
||||
filter_backends = []
|
||||
model = None # Set on subclass
|
||||
model = None # Set on subclass
|
||||
|
||||
known_query_parameters = frozenset([
|
||||
'limit',
|
||||
|
@ -41,6 +49,9 @@ class BaseAPIEndpoint(GenericViewSet):
|
|||
|
||||
# Used by jQuery for cache-busting. See #1671
|
||||
'_',
|
||||
|
||||
# Required by BrowsableAPIRenderer
|
||||
'format',
|
||||
])
|
||||
extra_api_fields = []
|
||||
name = None # Set on subclass.
|
||||
|
@ -105,7 +116,7 @@ class BaseAPIEndpoint(GenericViewSet):
|
|||
|
||||
# Get all available fields
|
||||
all_fields = self.get_api_fields(model)
|
||||
all_fields = list(OrderedDict.fromkeys(all_fields)) # Removes any duplicates in case the developer put "title" in api_fields
|
||||
all_fields = list(OrderedDict.fromkeys(all_fields)) # Removes any duplicates in case the developer put "title" in api_fields
|
||||
|
||||
if self.action == 'listing_view':
|
||||
# Listing views just show the title field and any other allowed field the user specified
|
||||
|
|
Ładowanie…
Reference in New Issue