mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Integrated status quo of grimborg's awesome humanize_field() for exposing field metadata via OPTIONS :)
This commit is contained in:
parent
9454e23aa9
commit
c0f3a1c397
|
@ -136,7 +136,7 @@ def humanize_field(field):
|
|||
humanized = {
|
||||
'type': humanize_field_type(field.__class__),
|
||||
'required': getattr(field, 'required', False),
|
||||
'label': field.label,
|
||||
'label': getattr(field, 'label', None),
|
||||
}
|
||||
optional_attrs = ['read_only', 'help_text']
|
||||
for attr in optional_attrs:
|
||||
|
|
|
@ -128,18 +128,18 @@ class TestRootView(TestCase):
|
|||
for method in ('GET', 'POST',):
|
||||
expected['actions'][method] = {
|
||||
'text': {
|
||||
'description': '',
|
||||
'label': '',
|
||||
'readonly': False,
|
||||
#'description': '',
|
||||
'label': None,
|
||||
'read_only': False,
|
||||
'required': True,
|
||||
'type': 'CharField',
|
||||
'type': 'Single Character',
|
||||
},
|
||||
'id': {
|
||||
'description': '',
|
||||
'label': '',
|
||||
'readonly': True,
|
||||
'required': True,
|
||||
'type': 'IntegerField',
|
||||
#'description': '',
|
||||
'label': None,
|
||||
'read_only': True,
|
||||
'required': False,
|
||||
'type': 'Integer',
|
||||
},
|
||||
}
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
@ -264,18 +264,18 @@ class TestInstanceView(TestCase):
|
|||
for method in ('GET', 'PATCH', 'PUT', 'DELETE'):
|
||||
expected['actions'][method] = {
|
||||
'text': {
|
||||
'description': '',
|
||||
'label': '',
|
||||
'readonly': False,
|
||||
#'description': '',
|
||||
'label': None,
|
||||
'read_only': False,
|
||||
'required': True,
|
||||
'type': 'CharField',
|
||||
'type': 'Single Character',
|
||||
},
|
||||
'id': {
|
||||
'description': '',
|
||||
'label': '',
|
||||
'readonly': True,
|
||||
'required': True,
|
||||
'type': 'IntegerField',
|
||||
#'description': '',
|
||||
'label': None,
|
||||
'read_only': True,
|
||||
'required': False,
|
||||
'type': 'Integer',
|
||||
},
|
||||
}
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
|
|
@ -85,8 +85,7 @@ class APIView(View):
|
|||
field_name_types = {}
|
||||
for name, field in serializer.fields.iteritems():
|
||||
from rest_framework.fields import humanize_field
|
||||
humanize_field(field)
|
||||
field_name_types[name] = field.__class__.__name__
|
||||
field_name_types[name] = humanize_field(field)
|
||||
|
||||
actions[method] = field_name_types
|
||||
except exceptions.PermissionDenied:
|
||||
|
|
Loading…
Reference in New Issue
Block a user