mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
Merge remote-tracking branch 'grimborg/issue-192-expose-fields-for-options' into issue-192-expose-fields-for-options
This commit is contained in:
commit
88c94f3720
|
@ -2,21 +2,23 @@
|
|||
General serializer field tests.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
from django.utils.datastructures import SortedDict
|
||||
import datetime
|
||||
from rest_framework.fields import (humanize_field, humanize_field_type,
|
||||
humanize_form_fields)
|
||||
from django import forms
|
||||
|
||||
from collections import namedtuple
|
||||
from decimal import Decimal
|
||||
from uuid import uuid4
|
||||
|
||||
import datetime
|
||||
from django import forms
|
||||
from django.core import validators
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.core import validators
|
||||
from django.utils.datastructures import SortedDict
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.fields import (humanize_field, humanize_field_type, humanize_form_fields,
|
||||
Field)
|
||||
from rest_framework.serializers import Serializer
|
||||
from rest_framework.tests.models import RESTFrameworkModel
|
||||
from rest_framework.fields import Field
|
||||
from collections import namedtuple
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
class TimestampedModel(models.Model):
|
||||
|
|
|
@ -6,6 +6,8 @@ from rest_framework.decorators import api_view
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import exceptions
|
||||
from rest_framework import serializers
|
||||
import copy
|
||||
|
||||
factory = RequestFactory()
|
||||
|
@ -98,3 +100,4 @@ class FunctionBasedViewIntegrationTests(TestCase):
|
|||
}
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(sanitise_json_error(response.data), expected)
|
||||
|
||||
|
|
|
@ -2,13 +2,16 @@
|
|||
Provides an APIView class that is the base of all views in REST framework.
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from rest_framework import status, exceptions
|
||||
from rest_framework.compat import View
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.fields import humanize_form_fields
|
||||
from rest_framework.request import clone_request, Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.utils.formatting import get_view_name, get_view_description
|
||||
|
||||
|
@ -69,7 +72,6 @@ class APIView(View):
|
|||
Helper for generating the fields metadata for allowed and permitted methods.
|
||||
"""
|
||||
actions = {}
|
||||
|
||||
for method in self.allowed_methods:
|
||||
# skip HEAD and OPTIONS
|
||||
if method in ('HEAD', 'OPTIONS'):
|
||||
|
@ -84,17 +86,11 @@ class APIView(View):
|
|||
actions[method] = {}
|
||||
continue
|
||||
|
||||
# TODO: find right placement - APIView does not have get_serializer
|
||||
if not hasattr(self, 'get_serializer'):
|
||||
continue
|
||||
serializer = self.get_serializer()
|
||||
if serializer is not None:
|
||||
field_name_types = {}
|
||||
for name, field in serializer.fields.iteritems():
|
||||
from rest_framework.fields import humanize_field
|
||||
field_name_types[name] = humanize_field(field)
|
||||
|
||||
actions[method] = field_name_types
|
||||
actions[method] = humanize_form_fields(serializer)
|
||||
except exceptions.PermissionDenied:
|
||||
# don't add this method
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user