Skip to content

Commit

Permalink
Form fields should use textual only value representations. Closes #3139
Browse files Browse the repository at this point in the history
…. Closes #2416. Closes #2558.
  • Loading branch information
tomchristie committed Jul 14, 2015
1 parent 8d30682 commit 6b08e97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions rest_framework/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ def render_field(self, field, parent_style):
style['template_pack'] = parent_style.get('template_pack', self.template_pack)
style['renderer'] = self

# Get a clone of the field with text-only value representation.
field = field.as_form_field()

if style.get('input_type') == 'datetime-local' and isinstance(field.value, six.text_type):
field.value = field.value.rstrip('Z')

Expand Down
6 changes: 5 additions & 1 deletion rest_framework/utils/serializer_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import collections

from rest_framework.compat import OrderedDict, unicode_to_repr
from rest_framework.compat import OrderedDict, force_text, unicode_to_repr


class ReturnDict(OrderedDict):
Expand Down Expand Up @@ -54,6 +54,7 @@ class BoundField(object):
"""
def __init__(self, field, value, errors, prefix=''):
self._field = field
self._prefix = prefix
self.value = value
self.errors = errors
self.name = prefix + self.field_name
Expand All @@ -70,6 +71,9 @@ def __repr__(self):
self.__class__.__name__, self.value, self.errors
))

def as_form_field(self):
return BoundField(self._field, force_text(self.value), self.errors, self._prefix)


class NestedBoundField(BoundField):
"""
Expand Down

0 comments on commit 6b08e97

Please sign in to comment.