Commit c0f3a1c3 by Nikolaus Schlemm

Integrated status quo of grimborg's awesome humanize_field() for exposing field…

Integrated status quo of grimborg's awesome humanize_field() for exposing field metadata via OPTIONS :)
parent 9454e23a
...@@ -136,7 +136,7 @@ def humanize_field(field): ...@@ -136,7 +136,7 @@ def humanize_field(field):
humanized = { humanized = {
'type': humanize_field_type(field.__class__), 'type': humanize_field_type(field.__class__),
'required': getattr(field, 'required', False), 'required': getattr(field, 'required', False),
'label': field.label, 'label': getattr(field, 'label', None),
} }
optional_attrs = ['read_only', 'help_text'] optional_attrs = ['read_only', 'help_text']
for attr in optional_attrs: for attr in optional_attrs:
......
...@@ -128,18 +128,18 @@ class TestRootView(TestCase): ...@@ -128,18 +128,18 @@ class TestRootView(TestCase):
for method in ('GET', 'POST',): for method in ('GET', 'POST',):
expected['actions'][method] = { expected['actions'][method] = {
'text': { 'text': {
'description': '', #'description': '',
'label': '', 'label': None,
'readonly': False, 'read_only': False,
'required': True, 'required': True,
'type': 'CharField', 'type': 'Single Character',
}, },
'id': { 'id': {
'description': '', #'description': '',
'label': '', 'label': None,
'readonly': True, 'read_only': True,
'required': True, 'required': False,
'type': 'IntegerField', 'type': 'Integer',
}, },
} }
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -264,18 +264,18 @@ class TestInstanceView(TestCase): ...@@ -264,18 +264,18 @@ class TestInstanceView(TestCase):
for method in ('GET', 'PATCH', 'PUT', 'DELETE'): for method in ('GET', 'PATCH', 'PUT', 'DELETE'):
expected['actions'][method] = { expected['actions'][method] = {
'text': { 'text': {
'description': '', #'description': '',
'label': '', 'label': None,
'readonly': False, 'read_only': False,
'required': True, 'required': True,
'type': 'CharField', 'type': 'Single Character',
}, },
'id': { 'id': {
'description': '', #'description': '',
'label': '', 'label': None,
'readonly': True, 'read_only': True,
'required': True, 'required': False,
'type': 'IntegerField', 'type': 'Integer',
}, },
} }
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
......
...@@ -85,8 +85,7 @@ class APIView(View): ...@@ -85,8 +85,7 @@ class APIView(View):
field_name_types = {} field_name_types = {}
for name, field in serializer.fields.iteritems(): for name, field in serializer.fields.iteritems():
from rest_framework.fields import humanize_field from rest_framework.fields import humanize_field
humanize_field(field) field_name_types[name] = humanize_field(field)
field_name_types[name] = field.__class__.__name__
actions[method] = field_name_types actions[method] = field_name_types
except exceptions.PermissionDenied: except exceptions.PermissionDenied:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment