aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/resources.py
diff options
context:
space:
mode:
authorTom Christie2011-12-29 13:31:12 +0000
committerTom Christie2011-12-29 13:31:12 +0000
commit07349597ab936dc9887caa70b5d7d2860c897b12 (patch)
treedb1fdb8934e4d8dc8d3afe8d1e9fd076e3a4e27d /djangorestframework/resources.py
parent1bdc5eacc6290c486796eb5ab8fa29092137dab6 (diff)
downloaddjango-rest-framework-07349597ab936dc9887caa70b5d7d2860c897b12.tar.bz2
whitespace fixes
Diffstat (limited to 'djangorestframework/resources.py')
-rw-r--r--djangorestframework/resources.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/djangorestframework/resources.py b/djangorestframework/resources.py
index 5770d07f..bf9af6f0 100644
--- a/djangorestframework/resources.py
+++ b/djangorestframework/resources.py
@@ -34,7 +34,7 @@ class BaseResource(Serializer):
Typically raises a :exc:`response.ErrorResponse` with status code 400 (Bad Request) on failure.
"""
return data
-
+
def filter_response(self, obj):
"""
Given the response content, filter it into a serializable object.
@@ -47,11 +47,11 @@ class Resource(BaseResource):
A Resource determines how a python object maps to some serializable data.
Objects that a resource can act on include plain Python object instances, Django Models, and Django QuerySets.
"""
-
+
# The model attribute refers to the Django Model which this Resource maps to.
# (The Model's class, rather than an instance of the Model)
model = None
-
+
# By default the set of returned fields will be the set of:
#
# 0. All the fields on the model, excluding 'id'.
@@ -83,7 +83,7 @@ class FormResource(Resource):
"""
Given some content as input return some cleaned, validated content.
Raises a :exc:`response.ErrorResponse` with status code 400 (Bad Request) on failure.
-
+
Validation is standard form validation, with an additional constraint that *no extra unknown fields* may be supplied.
On failure the :exc:`response.ErrorResponse` content is a dict which may contain :obj:`'errors'` and :obj:`'field-errors'` keys.
@@ -99,27 +99,27 @@ class FormResource(Resource):
allowed_extra_fields is a list of fields which are not defined by the form, but which we still
expect to see on the input.
-
+
fake_data is a string that should be used as an extra key, as a kludge to force .errors
to be populated when an empty dict is supplied in `data`
"""
-
+
# We'd like nice error messages even if no content is supplied.
# Typically if an empty dict is given to a form Django will
# return .is_valid() == False, but .errors == {}
#
- # To get around this case we revalidate with some fake data.
+ # To get around this case we revalidate with some fake data.
if fake_data:
data[fake_data] = '_fake_data'
allowed_extra_fields = tuple(allowed_extra_fields) + ('_fake_data',)
-
+
bound_form = self.get_bound_form(data, files)
if bound_form is None:
return data
-
+
self.view.bound_form_instance = bound_form
-
+
data = data and data or {}
files = files and files or {}
@@ -130,7 +130,7 @@ class FormResource(Resource):
# In addition to regular validation we also ensure no additional fields are being passed in...
unknown_fields = seen_fields_set - (form_fields_set | allowed_extra_fields_set)
unknown_fields = unknown_fields - set(('csrfmiddlewaretoken', '_accept', '_method')) # TODO: Ugh.
-
+
# Check using both regular validation, and our stricter no additional fields rule
if bound_form.is_valid() and not unknown_fields:
# Validation succeeded...
@@ -155,7 +155,7 @@ class FormResource(Resource):
# If we've already set fake_dict and we're still here, fallback gracefully.
detail = {u'errors': [u'No content was supplied.']}
- else:
+ else:
# Add any non-field errors
if bound_form.non_field_errors():
detail[u'errors'] = bound_form.non_field_errors()
@@ -171,7 +171,7 @@ class FormResource(Resource):
# Add any unknown field errors
for key in unknown_fields:
field_errors[key] = [u'This field does not exist.']
-
+
if field_errors:
detail[u'field-errors'] = field_errors
@@ -199,7 +199,7 @@ class FormResource(Resource):
form = getattr(self.view, '%s_form' % method.lower(), form)
return form
-
+
def get_bound_form(self, data=None, files=None, method=None):
"""
@@ -237,7 +237,7 @@ class ModelResource(FormResource):
Also provides a :meth:`get_bound_form` method which may be used by some renderers.
"""
- # Auto-register new ModelResource classes into _model_to_resource
+ # Auto-register new ModelResource classes into _model_to_resource
#__metaclass__ = _RegisterModelResource
form = None
@@ -258,21 +258,21 @@ class ModelResource(FormResource):
fields = None
"""
The list of fields to use on the output.
-
+
May be any of:
-
+
The name of a model field. To view nested resources, give the field as a tuple of ("fieldName", resource) where `resource` may be any of ModelResource reference, the name of a ModelResourc reference as a string or a tuple of strings representing fields on the nested model.
The name of an attribute on the model.
The name of an attribute on the resource.
The name of a method on the model, with a signature like ``func(self)``.
The name of a method on the resource, with a signature like ``func(self, instance)``.
"""
-
+
exclude = ('id', 'pk')
"""
The list of fields to exclude. This is only used if :attr:`fields` is not set.
"""
-
+
include = ('url',)
"""
@@ -294,7 +294,7 @@ class ModelResource(FormResource):
"""
Given some content as input return some cleaned, validated content.
Raises a :exc:`response.ErrorResponse` with status code 400 (Bad Request) on failure.
-
+
Validation is standard form or model form validation,
with an additional constraint that no extra unknown fields may be supplied,
and that all fields specified by the fields class attribute must be supplied,
@@ -345,12 +345,12 @@ class ModelResource(FormResource):
Attempts to reverse resolve the url of the given model *instance* for this resource.
Requires a ``View`` with :class:`mixins.InstanceMixin` to have been created for this resource.
-
+
This method can be overridden if you need to set the resource url reversing explicitly.
"""
if not hasattr(self, 'view_callable'):
- raise _SkipField
+ raise _SkipField
# dis does teh magicks...
urlconf = get_urlconf()
@@ -393,7 +393,7 @@ class ModelResource(FormResource):
return model_fields & set(as_tuple(self.fields))
return model_fields - set(as_tuple(self.exclude))
-
+
@property
def _property_fields_set(self):
"""