Import coreapi from rest_framework.compat, not directly. (#5921)

This commit is contained in:
gsvr 2018-04-05 15:07:49 +02:00 committed by Carlton Gibson
parent ffac61c6fe
commit 32caca4dd3
2 changed files with 24 additions and 24 deletions

View File

@ -1,8 +1,7 @@
import coreapi
import coreschema
from rest_framework import parsers, renderers from rest_framework import parsers, renderers
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.authtoken.serializers import AuthTokenSerializer
from rest_framework.compat import coreapi, coreschema
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.schemas import ManualSchema from rest_framework.schemas import ManualSchema
from rest_framework.views import APIView from rest_framework.views import APIView
@ -14,29 +13,30 @@ class ObtainAuthToken(APIView):
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,) parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
renderer_classes = (renderers.JSONRenderer,) renderer_classes = (renderers.JSONRenderer,)
serializer_class = AuthTokenSerializer serializer_class = AuthTokenSerializer
schema = ManualSchema( if coreapi is not None and coreschema is not None:
fields=[ schema = ManualSchema(
coreapi.Field( fields=[
name="username", coreapi.Field(
required=True, name="username",
location='form', required=True,
schema=coreschema.String( location='form',
title="Username", schema=coreschema.String(
description="Valid username for authentication", title="Username",
description="Valid username for authentication",
),
), ),
), coreapi.Field(
coreapi.Field( name="password",
name="password", required=True,
required=True, location='form',
location='form', schema=coreschema.String(
schema=coreschema.String( title="Password",
title="Password", description="Valid password for authentication",
description="Valid password for authentication", ),
), ),
), ],
], encoding="application/json",
encoding="application/json", )
)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
serializer = self.serializer_class(data=request.data, serializer = self.serializer_class(data=request.data,

View File

@ -14,8 +14,8 @@ from django.utils import six
from django.utils.safestring import SafeText from django.utils.safestring import SafeText
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import coreapi
from rest_framework import permissions, serializers, status from rest_framework import permissions, serializers, status
from rest_framework.compat import coreapi
from rest_framework.renderers import ( from rest_framework.renderers import (
AdminRenderer, BaseRenderer, BrowsableAPIRenderer, DocumentationRenderer, AdminRenderer, BaseRenderer, BrowsableAPIRenderer, DocumentationRenderer,
HTMLFormRenderer, JSONRenderer, SchemaJSRenderer, StaticHTMLRenderer HTMLFormRenderer, JSONRenderer, SchemaJSRenderer, StaticHTMLRenderer