Skip to content

Commit c0f3a1c

Browse files
committed
Integrated status quo of grimborg's awesome humanize_field() for exposing field metadata via OPTIONS :)
1 parent 9454e23 commit c0f3a1c

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

rest_framework/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def humanize_field(field):
136136
humanized = {
137137
'type': humanize_field_type(field.__class__),
138138
'required': getattr(field, 'required', False),
139-
'label': field.label,
139+
'label': getattr(field, 'label', None),
140140
}
141141
optional_attrs = ['read_only', 'help_text']
142142
for attr in optional_attrs:

rest_framework/tests/generics.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,18 @@ def test_options_root_view(self):
128128
for method in ('GET', 'POST',):
129129
expected['actions'][method] = {
130130
'text': {
131-
'description': '',
132-
'label': '',
133-
'readonly': False,
131+
#'description': '',
132+
'label': None,
133+
'read_only': False,
134134
'required': True,
135-
'type': 'CharField',
135+
'type': 'Single Character',
136136
},
137137
'id': {
138-
'description': '',
139-
'label': '',
140-
'readonly': True,
141-
'required': True,
142-
'type': 'IntegerField',
138+
#'description': '',
139+
'label': None,
140+
'read_only': True,
141+
'required': False,
142+
'type': 'Integer',
143143
},
144144
}
145145
self.assertEqual(response.status_code, status.HTTP_200_OK)
@@ -264,18 +264,18 @@ def test_options_instance_view(self):
264264
for method in ('GET', 'PATCH', 'PUT', 'DELETE'):
265265
expected['actions'][method] = {
266266
'text': {
267-
'description': '',
268-
'label': '',
269-
'readonly': False,
267+
#'description': '',
268+
'label': None,
269+
'read_only': False,
270270
'required': True,
271-
'type': 'CharField',
271+
'type': 'Single Character',
272272
},
273273
'id': {
274-
'description': '',
275-
'label': '',
276-
'readonly': True,
277-
'required': True,
278-
'type': 'IntegerField',
274+
#'description': '',
275+
'label': None,
276+
'read_only': True,
277+
'required': False,
278+
'type': 'Integer',
279279
},
280280
}
281281
self.assertEqual(response.status_code, status.HTTP_200_OK)

rest_framework/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def _generate_action_metadata(self, request):
8585
field_name_types = {}
8686
for name, field in serializer.fields.iteritems():
8787
from rest_framework.fields import humanize_field
88-
humanize_field(field)
89-
field_name_types[name] = field.__class__.__name__
88+
field_name_types[name] = humanize_field(field)
9089

9190
actions[method] = field_name_types
9291
except exceptions.PermissionDenied:

0 commit comments

Comments
 (0)