Remove initial kwarg, add default.

This commit is contained in:
Tom Christie 2012-10-21 17:41:05 +01:00
parent 13d0a82939
commit 93f1aa4f69
2 changed files with 17 additions and 9 deletions

View File

@ -107,10 +107,11 @@ class WritableField(Field):
'invalid': _('Invalid value.'),
}
widget = widgets.TextInput
default = None
def __init__(self, source=None, readonly=False, required=None,
validators=[], error_messages=None, widget=None,
initial=None):
default=None):
super(WritableField, self).__init__(source=source)
@ -128,10 +129,9 @@ class WritableField(Field):
self.error_messages = messages
self.validators = self.default_validators + validators
self.default = default or self.default
# These attributes are ony used for HTML forms.
self.initial = initial
# Widgets are ony used for HTML forms.
widget = widget or self.widget
if isinstance(widget, type):
widget = widget()
@ -170,8 +170,8 @@ class WritableField(Field):
try:
native = data[field_name]
except KeyError:
if getattr(self, 'missing_value', None) is not None:
native = self.missing_value
if self.default is not None:
native = self.default
else:
if self.required:
raise ValidationError(self.error_messages['required'])
@ -415,7 +415,11 @@ class BooleanField(WritableField):
'invalid': _(u"'%s' value must be either True or False."),
}
empty = False
missing_value = False # Fill in missing value not supplied by html form
# Note: we set default to `False` in order to fill in missing value not
# supplied by html form. TODO: Fix so that only html form input gets
# this behavior.
default = False
def from_native(self, value):
if value in ('t', 'True', '1'):

View File

@ -281,8 +281,10 @@ class BrowsableAPIRenderer(BaseRenderer):
kwargs = {}
kwargs['required'] = v.required
if getattr(v, 'queryset', None):
kwargs['queryset'] = v.queryset
if getattr(v, 'widget', None):
widget = copy.deepcopy(v.widget)
# If choices have friendly readable names,
@ -294,8 +296,10 @@ class BrowsableAPIRenderer(BaseRenderer):
for (ident, desc) in choices]
widget.choices = choices
kwargs['widget'] = widget
if getattr(v, 'initial', None):
kwargs['initial'] = v.initial
if getattr(v, 'default', None) is not None:
kwargs['initial'] = v.default
kwargs['label'] = k
try: