Merge branch 'kaedroho-drf-browsable-api'

pull/1860/head
Matt Westcott 2015-10-22 17:24:42 +01:00
commit c4738fc3d5
4 zmienionych plików z 38 dodań i 4 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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.

Wyświetl plik

@ -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)

Wyświetl plik

@ -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,6 +28,13 @@ 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 = []
@ -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.