From 7dcd2738a57a2a96e29c38e78c90e36e825514ba Mon Sep 17 00:00:00 2001 From: Jens Alm Date: Tue, 19 Jul 2011 22:09:35 +0200 Subject: [PATCH 1/9] Fixed misaligned documentation on ModelResource. Added basic documentation for nested resources Signed-off-by: Jens Alm --- djangorestframework/resources.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/djangorestframework/resources.py b/djangorestframework/resources.py index f4a2ab147..0bb1a530e 100644 --- a/djangorestframework/resources.py +++ b/djangorestframework/resources.py @@ -72,11 +72,11 @@ class FormResource(Resource): view, which may be used by some renderers. """ + form = None """ The :class:`Form` class that should be used for request validation. This can be overridden by a :attr:`form` attribute on the :class:`views.View`. """ - form = None def validate_request(self, data, files=None): @@ -240,44 +240,44 @@ class ModelResource(FormResource): # Auto-register new ModelResource classes into _model_to_resource #__metaclass__ = _RegisterModelResource + form = None """ The form class that should be used for request validation. If set to :const:`None` then the default model form validation will be used. This can be overridden by a :attr:`form` attribute on the :class:`views.View`. """ - form = None + model = None """ The model class which this resource maps to. This can be overridden by a :attr:`model` attribute on the :class:`views.View`. """ - model = None + fields = None """ The list of fields to use on the output. May be any of: - The name of a model field. + 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)``. """ - fields = None + exclude = ('id', 'pk') """ The list of fields to exclude. This is only used if :attr:`fields` is not set. """ - exclude = ('id', 'pk') + + include = ('url',) """ The list of extra fields to include. This is only used if :attr:`fields` is not set. """ - include = ('url',) - def __init__(self, view=None, depth=None, stack=[], **kwargs): """ From 524954b2460bf8d461688400fd68598a57adca5f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 22 Jul 2011 04:01:38 -0700 Subject: [PATCH 2/9] Whitespace tweak --- djangorestframework/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/djangorestframework/views.py b/djangorestframework/views.py index c25bb88f6..860e2bb80 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -40,7 +40,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): """ List of renderers the resource can serialize the response with, ordered by preference. """ - renderers = renderers.DEFAULT_RENDERERS + renderers = renderers.DEFAULT_RENDERERS + """ List of parsers the resource can parse the request with. """ From 746b817ad34af712d362539583bfdbcf5b84adc1 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 22 Jul 2011 04:03:04 -0700 Subject: [PATCH 3/9] Whitespace tweaks --- djangorestframework/views.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/djangorestframework/views.py b/djangorestframework/views.py index 860e2bb80..5f8e84cd2 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -160,17 +160,25 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): class ModelView(View): - """A RESTful view that maps to a model in the database.""" + """ + A RESTful view that maps to a model in the database. + """ resource = resources.ModelResource class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteModelMixin, ModelView): - """A view which provides default operations for read/update/delete against a model instance.""" + """ + A view which provides default operations for read/update/delete against a model instance. + """ _suffix = 'Instance' class ListModelView(ListModelMixin, ModelView): - """A view which provides default operations for list, against a model in the database.""" + """ + A view which provides default operations for list, against a model in the database. + """ _suffix = 'List' class ListOrCreateModelView(ListModelMixin, CreateModelMixin, ModelView): - """A view which provides default operations for list and create, against a model in the database.""" + """ + A view which provides default operations for list and create, against a model in the database. + """ _suffix = 'List' From e3c00e4c1e0d64c8b0f0b04e6e7a7e1a308099f2 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Wed, 27 Jul 2011 18:32:19 +0300 Subject: [PATCH 4/9] Fixed TypeError that occurs without request data. If no request data gets sent, allowed_extra_fields is a set and can't be joined to a tuple using the + operator. --- djangorestframework/resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangorestframework/resources.py b/djangorestframework/resources.py index f4a2ab147..99c452440 100644 --- a/djangorestframework/resources.py +++ b/djangorestframework/resources.py @@ -111,7 +111,7 @@ class FormResource(Resource): # To get around this case we revalidate with some fake data. if fake_data: data[fake_data] = '_fake_data' - allowed_extra_fields = allowed_extra_fields + ('_fake_data',) + allowed_extra_fields = tuple(allowed_extra_fields) + ('_fake_data',) bound_form = self.get_bound_form(data, files) From 968c5e43f3f64c40ebc64127210d67fc5f77de8f Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Sun, 31 Jul 2011 13:21:06 -0700 Subject: [PATCH 5/9] Removed rogue import for LimitBytes to fix issue #63 --- djangorestframework/mixins.py | 1 - 1 file changed, 1 deletion(-) diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index bb26ad963..9fed61221 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -7,7 +7,6 @@ from django.contrib.auth.models import AnonymousUser from django.db.models.query import QuerySet from django.db.models.fields.related import ForeignKey from django.http import HttpResponse -from django.http.multipartparser import LimitBytes from djangorestframework import status from djangorestframework.parsers import FormParser, MultiPartParser From 6d1207fdcfea2fac6cad011a2a4a4369cd790e17 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sun, 31 Jul 2011 22:35:36 +0200 Subject: [PATCH 6/9] Edited AUTHORS via GitHub --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 97319f754..c5fd5b6e9 100644 --- a/AUTHORS +++ b/AUTHORS @@ -15,6 +15,8 @@ Jens Alm Craig Blaszczyk Tom Drummond +Danilo Bargen +Andrew McCloud THANKS TO: From 9682c9b9b23cbf616cb58cab9313bf7cbbe79d80 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 1 Aug 2011 11:22:07 +0200 Subject: [PATCH 7/9] Edited AUTHORS via GitHub --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index c5fd5b6e9..ca5c46277 100644 --- a/AUTHORS +++ b/AUTHORS @@ -9,7 +9,7 @@ Carles Barrobés Michael Fötsch David Larlet Andrew Straw - +Zeth Fernando Zunino Jens Alm Craig Blaszczyk From 642d73f4e704b56f56e12512e662ea5101b79735 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 1 Aug 2011 11:22:51 +0200 Subject: [PATCH 8/9] Edited AUTHORS via GitHub --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index ca5c46277..2b8af2b97 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,7 +13,7 @@ Zeth Fernando Zunino Jens Alm Craig Blaszczyk - +Garcia Solero Tom Drummond Danilo Bargen Andrew McCloud From c50637287b18ca00a54c6158f3edbb0136c71b16 Mon Sep 17 00:00:00 2001 From: Mason Tang Date: Wed, 24 Aug 2011 07:49:16 -0300 Subject: [PATCH 9/9] Fix in permissions, user.is_staff is a field, not a function. --- djangorestframework/permissions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangorestframework/permissions.py b/djangorestframework/permissions.py index 59c5f481f..0052a6094 100644 --- a/djangorestframework/permissions.py +++ b/djangorestframework/permissions.py @@ -73,7 +73,7 @@ class IsAdminUser(BasePermission): """ def check_permission(self, user): - if not user.is_staff(): + if not user.is_staff: raise _403_FORBIDDEN_RESPONSE