readonly -> read_only

This commit is contained in:
Tom Christie 2012-10-28 20:21:45 +00:00
parent 795f611663
commit 6e4ab09aae
6 changed files with 23 additions and 23 deletions

View File

@ -26,7 +26,7 @@ The value `source='*'` has a special meaning, and is used to indicate that the e
Defaults to the name of the field. Defaults to the name of the field.
### `readonly` ### `read_only`
Set this to `True` to ensure that the field is used when serializing a representation, but is not used when updating an instance dureing deserialization. Set this to `True` to ensure that the field is used when serializing a representation, but is not used when updating an instance dureing deserialization.
@ -241,7 +241,7 @@ This field can be applied to any "to-one" relationship, such as a `ForeignKey` f
`PrimaryKeyRelatedField` will represent the target of the field using it's primary key. `PrimaryKeyRelatedField` will represent the target of the field using it's primary key.
Be default, `PrimaryKeyRelatedField` is read-write, although you can change this behaviour using the `readonly` flag. Be default, `PrimaryKeyRelatedField` is read-write, although you can change this behaviour using the `read_only` flag.
## ManyPrimaryKeyRelatedField ## ManyPrimaryKeyRelatedField
@ -249,7 +249,7 @@ This field can be applied to any "to-many" relationship, such as a `ManyToManyFi
`PrimaryKeyRelatedField` will represent the targets of the field using their primary key. `PrimaryKeyRelatedField` will represent the targets of the field using their primary key.
Be default, `ManyPrimaryKeyRelatedField` is read-write, although you can change this behaviour using the `readonly` flag. Be default, `ManyPrimaryKeyRelatedField` is read-write, although you can change this behaviour using the `read_only` flag.
## HyperlinkedRelatedField ## HyperlinkedRelatedField
@ -257,7 +257,7 @@ This field can be applied to any "to-one" relationship, such as a `ForeignKey` f
`HyperlinkedRelatedField` will represent the target of the field using a hyperlink. You must include a named URL pattern in your URL conf, with a name like `'{model-name}-detail'` that corresponds to the target of the hyperlink. `HyperlinkedRelatedField` will represent the target of the field using a hyperlink. You must include a named URL pattern in your URL conf, with a name like `'{model-name}-detail'` that corresponds to the target of the hyperlink.
Be default, `HyperlinkedRelatedField` is read-write, although you can change this behaviour using the `readonly` flag. Be default, `HyperlinkedRelatedField` is read-write, although you can change this behaviour using the `read_only` flag.
## ManyHyperlinkedRelatedField ## ManyHyperlinkedRelatedField
@ -265,7 +265,7 @@ This field can be applied to any "to-many" relationship, such as a `ManyToManyFi
`ManyHyperlinkedRelatedField` will represent the targets of the field using hyperlinks. You must include a named URL pattern in your URL conf, with a name like `'{model-name}-detail'` that corresponds to the target of the hyperlink. `ManyHyperlinkedRelatedField` will represent the targets of the field using hyperlinks. You must include a named URL pattern in your URL conf, with a name like `'{model-name}-detail'` that corresponds to the target of the hyperlink.
Be default, `ManyHyperlinkedRelatedField` is read-write, although you can change this behaviour using the `readonly` flag. Be default, `ManyHyperlinkedRelatedField` is read-write, although you can change this behaviour using the `read_only` flag.
## HyperLinkedIdentityField ## HyperLinkedIdentityField

View File

@ -190,7 +190,7 @@ The `ModelSerializer` class lets you automatically create a Serializer class wit
You can add extra fields to a `ModelSerializer` or override the default fields by declaring fields on the class, just as you would for a `Serializer` class. You can add extra fields to a `ModelSerializer` or override the default fields by declaring fields on the class, just as you would for a `Serializer` class.
class AccountSerializer(serializers.ModelSerializer): class AccountSerializer(serializers.ModelSerializer):
url = CharField(source='get_absolute_url', readonly=True) url = CharField(source='get_absolute_url', read_only=True)
group = NaturalKeyField() group = NaturalKeyField()
class Meta: class Meta:
@ -246,7 +246,7 @@ When serializing objects using a nested representation any occurances of recursi
model = Account model = Account
def get_pk_field(self, model_field): def get_pk_field(self, model_field):
return serializers.Field(readonly=True) return serializers.Field(read_only=True)
def get_nested_field(self, model_field): def get_nested_field(self, model_field):
return serializers.ModelSerializer() return serializers.ModelSerializer()

View File

@ -111,17 +111,17 @@ class WritableField(Field):
widget = widgets.TextInput widget = widgets.TextInput
default = None default = None
def __init__(self, source=None, readonly=False, required=None, def __init__(self, source=None, read_only=False, required=None,
validators=[], error_messages=None, widget=None, validators=[], error_messages=None, widget=None,
default=None): default=None):
super(WritableField, self).__init__(source=source) super(WritableField, self).__init__(source=source)
self.readonly = readonly self.read_only = read_only
if required is None: if required is None:
self.required = not(readonly) self.required = not(read_only)
else: else:
assert not readonly, "Cannot set required=True and readonly=True" assert not read_only, "Cannot set required=True and read_only=True"
self.required = required self.required = required
messages = {} messages = {}
@ -166,7 +166,7 @@ class WritableField(Field):
Given a dictionary and a field name, updates the dictionary `into`, Given a dictionary and a field name, updates the dictionary `into`,
with the field and it's deserialized value. with the field and it's deserialized value.
""" """
if self.readonly: if self.read_only:
return return
try: try:
@ -240,7 +240,7 @@ class RelatedField(WritableField):
return self.to_native(value) return self.to_native(value)
def field_from_native(self, data, field_name, into): def field_from_native(self, data, field_name, into):
if self.readonly: if self.read_only:
return return
value = data.get(field_name) value = data.get(field_name)
@ -256,7 +256,7 @@ class ManyRelatedMixin(object):
return [self.to_native(item) for item in value.all()] return [self.to_native(item) for item in value.all()]
def field_from_native(self, data, field_name, into): def field_from_native(self, data, field_name, into):
if self.readonly: if self.read_only:
return return
try: try:

View File

@ -288,7 +288,7 @@ class BrowsableAPIRenderer(BaseRenderer):
fields = {} fields = {}
for k, v in serializer.get_fields(True).items(): for k, v in serializer.get_fields(True).items():
if getattr(v, 'readonly', True): if getattr(v, 'read_only', True):
continue continue
kwargs = {} kwargs = {}

View File

@ -301,7 +301,7 @@ class ManyToManyTests(TestCase):
class ReadOnlyManyToManyTests(TestCase): class ReadOnlyManyToManyTests(TestCase):
def setUp(self): def setUp(self):
class ReadOnlyManyToManySerializer(serializers.ModelSerializer): class ReadOnlyManyToManySerializer(serializers.ModelSerializer):
rel = serializers.ManyRelatedField(readonly=True) rel = serializers.ManyRelatedField(read_only=True)
class Meta: class Meta:
model = ReadOnlyManyToManyModel model = ReadOnlyManyToManyModel
@ -323,7 +323,7 @@ class ReadOnlyManyToManyTests(TestCase):
def test_update(self): def test_update(self):
""" """
Attempt to update an instance of a model with a ManyToMany Attempt to update an instance of a model with a ManyToMany
relationship. Not updated due to readonly=True relationship. Not updated due to read_only=True
""" """
new_anchor = Anchor() new_anchor = Anchor()
new_anchor.save() new_anchor.save()
@ -339,7 +339,7 @@ class ReadOnlyManyToManyTests(TestCase):
def test_update_without_relationship(self): def test_update_without_relationship(self):
""" """
Attempt to update an instance of a model where many to ManyToMany Attempt to update an instance of a model where many to ManyToMany
relationship is not supplied. Not updated due to readonly=True relationship is not supplied. Not updated due to read_only=True
""" """
new_anchor = Anchor() new_anchor = Anchor()
new_anchor.save() new_anchor.save()

View File

@ -285,7 +285,7 @@
# uiop = models.CharField(max_length=256, blank=True) # uiop = models.CharField(max_length=256, blank=True)
# @property # @property
# def readonly(self): # def read_only(self):
# return 'read only' # return 'read only'
# class MockResource(ModelResource): # class MockResource(ModelResource):
@ -298,7 +298,7 @@
# def test_property_fields_are_allowed_on_model_forms(self): # def test_property_fields_are_allowed_on_model_forms(self):
# """Validation on ModelForms may include property fields that exist on the Model to be included in the input.""" # """Validation on ModelForms may include property fields that exist on the Model to be included in the input."""
# content = {'qwerty': 'example', 'uiop': 'example', 'readonly': 'read only'} # content = {'qwerty': 'example', 'uiop': 'example', 'read_only': 'read only'}
# self.assertEqual(self.validator.validate_request(content, None), content) # self.assertEqual(self.validator.validate_request(content, None), content)
# def test_property_fields_are_not_required_on_model_forms(self): # def test_property_fields_are_not_required_on_model_forms(self):
@ -310,19 +310,19 @@
# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. # """If some (otherwise valid) content includes fields that are not in the form then validation should fail.
# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up # It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up
# broken clients more easily (eg submitting content with a misnamed field)""" # broken clients more easily (eg submitting content with a misnamed field)"""
# content = {'qwerty': 'example', 'uiop': 'example', 'readonly': 'read only', 'extra': 'extra'} # content = {'qwerty': 'example', 'uiop': 'example', 'read_only': 'read only', 'extra': 'extra'}
# self.assertRaises(ImmediateResponse, self.validator.validate_request, content, None) # self.assertRaises(ImmediateResponse, self.validator.validate_request, content, None)
# def test_validate_requires_fields_on_model_forms(self): # def test_validate_requires_fields_on_model_forms(self):
# """If some (otherwise valid) content includes fields that are not in the form then validation should fail. # """If some (otherwise valid) content includes fields that are not in the form then validation should fail.
# It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up # It might be okay on normal form submission, but for Web APIs we oughta get strict, as it'll help show up
# broken clients more easily (eg submitting content with a misnamed field)""" # broken clients more easily (eg submitting content with a misnamed field)"""
# content = {'readonly': 'read only'} # content = {'read_only': 'read only'}
# self.assertRaises(ImmediateResponse, self.validator.validate_request, content, None) # self.assertRaises(ImmediateResponse, self.validator.validate_request, content, None)
# def test_validate_does_not_require_blankable_fields_on_model_forms(self): # def test_validate_does_not_require_blankable_fields_on_model_forms(self):
# """Test standard ModelForm validation behaviour - fields with blank=True are not required.""" # """Test standard ModelForm validation behaviour - fields with blank=True are not required."""
# content = {'qwerty': 'example', 'readonly': 'read only'} # content = {'qwerty': 'example', 'read_only': 'read only'}
# self.validator.validate_request(content, None) # self.validator.validate_request(content, None)
# def test_model_form_validator_uses_model_forms(self): # def test_model_form_validator_uses_model_forms(self):