mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Form fields should use textual only value representations. Closes #3139. Closes #2416. Closes #2558.
This commit is contained in:
parent
8d306823b4
commit
6b08e97b6a
|
@ -318,6 +318,9 @@ class HTMLFormRenderer(BaseRenderer):
|
||||||
style['template_pack'] = parent_style.get('template_pack', self.template_pack)
|
style['template_pack'] = parent_style.get('template_pack', self.template_pack)
|
||||||
style['renderer'] = self
|
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):
|
if style.get('input_type') == 'datetime-local' and isinstance(field.value, six.text_type):
|
||||||
field.value = field.value.rstrip('Z')
|
field.value = field.value.rstrip('Z')
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import collections
|
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):
|
class ReturnDict(OrderedDict):
|
||||||
|
@ -54,6 +54,7 @@ class BoundField(object):
|
||||||
"""
|
"""
|
||||||
def __init__(self, field, value, errors, prefix=''):
|
def __init__(self, field, value, errors, prefix=''):
|
||||||
self._field = field
|
self._field = field
|
||||||
|
self._prefix = prefix
|
||||||
self.value = value
|
self.value = value
|
||||||
self.errors = errors
|
self.errors = errors
|
||||||
self.name = prefix + self.field_name
|
self.name = prefix + self.field_name
|
||||||
|
@ -70,6 +71,9 @@ class BoundField(object):
|
||||||
self.__class__.__name__, self.value, self.errors
|
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):
|
class NestedBoundField(BoundField):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user