Merge branch 'autodiscover' of github.com:jakul/django-rest-framework into autodiscover

This commit is contained in:
Craig Blaszczyk 2011-09-02 12:01:03 +01:00
commit 36759f733e
5 changed files with 28 additions and 18 deletions

View File

@ -9,12 +9,14 @@ Carles Barrobés <txels>
Michael Fötsch <mfoetsch> Michael Fötsch <mfoetsch>
David Larlet <david> David Larlet <david>
Andrew Straw <astraw> Andrew Straw <astraw>
<zeth> Zeth <zeth>
Fernando Zunino <fzunino> Fernando Zunino <fzunino>
Jens Alm <ulmus> Jens Alm <ulmus>
Craig Blaszczyk <jakul> Craig Blaszczyk <jakul>
<garciasolero> Garcia Solero <garciasolero>
Tom Drummond <devioustree> Tom Drummond <devioustree>
Danilo Bargen <gwrtheyrn>
Andrew McCloud <amccloud>
THANKS TO: THANKS TO:

View File

@ -7,7 +7,6 @@ from django.contrib.auth.models import AnonymousUser
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.db.models.fields.related import ForeignKey from django.db.models.fields.related import ForeignKey
from django.http import HttpResponse from django.http import HttpResponse
from django.http.multipartparser import LimitBytes
from djangorestframework import status from djangorestframework import status
from djangorestframework.parsers import FormParser, MultiPartParser from djangorestframework.parsers import FormParser, MultiPartParser

View File

@ -81,7 +81,7 @@ class IsAdminUser(BasePermission):
""" """
def check_permission(self, user): def check_permission(self, user):
if not user.is_staff(): if not user.is_staff:
raise _403_FORBIDDEN_RESPONSE raise _403_FORBIDDEN_RESPONSE

View File

@ -72,11 +72,11 @@ class FormResource(Resource):
view, which may be used by some renderers. view, which may be used by some renderers.
""" """
form = None
""" """
The :class:`Form` class that should be used for request validation. 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`. This can be overridden by a :attr:`form` attribute on the :class:`views.View`.
""" """
form = None
def validate_request(self, data, files=None): def validate_request(self, data, files=None):
@ -111,7 +111,7 @@ class FormResource(Resource):
# 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: if fake_data:
data[fake_data] = '_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) bound_form = self.get_bound_form(data, files)
@ -245,44 +245,44 @@ class ModelResource(FormResource):
# Auto-register new ModelResource classes into _model_to_resource # Auto-register new ModelResource classes into _model_to_resource
#__metaclass__ = _RegisterModelResource #__metaclass__ = _RegisterModelResource
form = None
""" """
The form class that should be used for request validation. The form class that should be used for request validation.
If set to :const:`None` then the default model form validation will be used. 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`. 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. The model class which this resource maps to.
This can be overridden by a :attr:`model` attribute on the :class:`views.View`. 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. The list of fields to use on the output.
May be any of: 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 model.
The name of an attribute on the resource. 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 model, with a signature like ``func(self)``.
The name of a method on the resource, with a signature like ``func(self, instance)``. 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. 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. The list of extra fields to include. This is only used if :attr:`fields` is not set.
""" """
include = ('url',)
def __init__(self, view): def __init__(self, view):
""" """

View File

@ -40,7 +40,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
""" """
List of renderers the resource can serialize the response with, ordered by preference. 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. List of parsers the resource can parse the request with.
""" """
@ -159,17 +160,25 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
class ModelView(View): 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 resource = resources.ModelResource
class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteModelMixin, ModelView): 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' _suffix = 'Instance'
class ListModelView(ListModelMixin, ModelView): 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' _suffix = 'List'
class ListOrCreateModelView(ListModelMixin, CreateModelMixin, ModelView): 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' _suffix = 'List'