diff options
| author | Tom Christie | 2011-04-27 18:53:54 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-04-27 18:53:54 +0100 |
| commit | 5921e5c84e13cafe90061629262f12dfe742c07a (patch) | |
| tree | 2d56ef1264b47704a4f9042aa5c6cb1cea4d465d | |
| parent | 5a59f339c1757767b136de33faa5b67a972141a1 (diff) | |
| download | django-rest-framework-5921e5c84e13cafe90061629262f12dfe742c07a.tar.bz2 | |
Fix up ModelResource issues
| -rw-r--r-- | djangorestframework/emitters.py | 4 | ||||
| -rw-r--r-- | djangorestframework/modelresource.py | 7 | ||||
| -rw-r--r-- | djangorestframework/resource.py | 5 | ||||
| -rw-r--r-- | examples/blogpost/views.py | 6 |
4 files changed, 12 insertions, 10 deletions
diff --git a/djangorestframework/emitters.py b/djangorestframework/emitters.py index d2b06c13..87b3e94e 100644 --- a/djangorestframework/emitters.py +++ b/djangorestframework/emitters.py @@ -15,8 +15,10 @@ from djangorestframework.breadcrumbs import get_breadcrumbs from djangorestframework.description import get_name, get_description from djangorestframework import status -from decimal import Decimal +from urllib import quote_plus import string +import re +from decimal import Decimal # TODO: Rename verbose to something more appropriate # TODO: Maybe None could be handled more cleanly. It'd be nice if it was handled by default, diff --git a/djangorestframework/modelresource.py b/djangorestframework/modelresource.py index 1afd7fa0..79505c6c 100644 --- a/djangorestframework/modelresource.py +++ b/djangorestframework/modelresource.py @@ -408,6 +408,9 @@ class ModelResource(Resource): return +class InstanceModelResource(ModelResource): + http_method_names = ['get', 'put', 'delete', 'head', 'options', 'trace', 'patch'] # Bit of a hack, these - needs fixing. + class RootModelResource(ModelResource): """A Resource which provides default operations for list and create.""" queryset = None @@ -416,7 +419,7 @@ class RootModelResource(ModelResource): queryset = self.queryset if self.queryset else self.model.objects.all() return queryset.filter(**kwargs) - put = delete = None + http_method_names = ['get', 'post', 'head', 'options', 'trace', 'patch'] class QueryModelResource(ModelResource): """Resource with default operations for list. @@ -428,4 +431,4 @@ class QueryModelResource(ModelResource): queryset = self.queryset if self.queryset else self.model.objects.all() return queryset.filer(**kwargs) - post = put = delete = None
\ No newline at end of file + http_method_names = ['get', 'head', 'options', 'trace', 'patch'] diff --git a/djangorestframework/resource.py b/djangorestframework/resource.py index fdbce8b5..636fe0ba 100644 --- a/djangorestframework/resource.py +++ b/djangorestframework/resource.py @@ -54,7 +54,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View): @property def allowed_methods(self): - return [method.upper() for method in self.http_method_names if getattr(self, method, None)] + return [method.upper() for method in self.http_method_names if hasattr(self, method)] def http_method_not_allowed(self, request, *args, **kwargs): """Return an HTTP 405 error if an operation is called which does not have a handler method.""" @@ -97,9 +97,6 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View): # Get the appropriate handler method if self.method.lower() in self.http_method_names: handler = getattr(self, self.method.lower(), self.http_method_not_allowed) - # If a previously defined method has been disabled - if handler is None: - handler = self.http_method_not_allowed else: handler = self.http_method_not_allowed diff --git a/examples/blogpost/views.py b/examples/blogpost/views.py index 9e07aa8a..e47f4a5b 100644 --- a/examples/blogpost/views.py +++ b/examples/blogpost/views.py @@ -1,4 +1,4 @@ -from djangorestframework.modelresource import ModelResource, RootModelResource +from djangorestframework.modelresource import InstanceModelResource, RootModelResource from blogpost import models @@ -11,7 +11,7 @@ class BlogPosts(RootModelResource): model = models.BlogPost fields = BLOG_POST_FIELDS -class BlogPostInstance(ModelResource): +class BlogPostInstance(InstanceModelResource): """A resource which represents a single blog post.""" model = models.BlogPost fields = BLOG_POST_FIELDS @@ -21,7 +21,7 @@ class Comments(RootModelResource): model = models.Comment fields = COMMENT_FIELDS -class CommentInstance(ModelResource): +class CommentInstance(InstanceModelResource): """A resource which represents a single comment.""" model = models.Comment fields = COMMENT_FIELDS |
