From 028851bfa1ee44b8e92808b18d32278d4a473cc8 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 27 Apr 2011 18:07:28 +0100 Subject: Fix up tests and examples after refactoring --- examples/resourceexample/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'examples/resourceexample') diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py index 41d2e5c5..911fd467 100644 --- a/examples/resourceexample/views.py +++ b/examples/resourceexample/views.py @@ -8,24 +8,22 @@ from resourceexample.forms import MyForm class ExampleResource(Resource): """A basic read-only resource that points to 3 other resources.""" - allowed_methods = anon_allowed_methods = ('GET',) - def get(self, request, auth): + def get(self, request): return {"Some other resources": [reverse('another-example-resource', kwargs={'num':num}) for num in range(3)]} class AnotherExampleResource(Resource): """A basic GET-able/POST-able resource.""" - allowed_methods = anon_allowed_methods = ('GET', 'POST') form = MyForm # Optional form validation on input (Applies in this case the POST method, but can also apply to PUT) - def get(self, request, auth, num): + def get(self, request, num): """Handle GET requests""" if int(num) > 2: return Response(status.HTTP_404_NOT_FOUND) return "GET request to AnotherExampleResource %s" % num - def post(self, request, auth, content, num): + def post(self, request, num): """Handle POST requests""" if int(num) > 2: return Response(status.HTTP_404_NOT_FOUND) - return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(content)) + return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(self.CONTENT)) -- cgit v1.2.3 From 1e04790d505a1174f9e3c4481288982f9e7fd6c0 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 16 May 2011 14:11:36 +0100 Subject: Fixing some of the last blocking issues --- examples/resourceexample/views.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'examples/resourceexample') diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py index 911fd467..70d96891 100644 --- a/examples/resourceexample/views.py +++ b/examples/resourceexample/views.py @@ -1,20 +1,33 @@ from django.core.urlresolvers import reverse -from djangorestframework.resource import Resource +from djangorestframework.views import BaseView +from djangorestframework.resources import FormResource from djangorestframework.response import Response from djangorestframework import status from resourceexample.forms import MyForm -class ExampleResource(Resource): - """A basic read-only resource that points to 3 other resources.""" +class MyFormValidation(FormResource): + """ + A resource which applies form validation on the input. + """ + form = MyForm + + +class ExampleResource(BaseView): + """ + A basic read-only resource that points to 3 other resources. + """ def get(self, request): return {"Some other resources": [reverse('another-example-resource', kwargs={'num':num}) for num in range(3)]} -class AnotherExampleResource(Resource): - """A basic GET-able/POST-able resource.""" - form = MyForm # Optional form validation on input (Applies in this case the POST method, but can also apply to PUT) + +class AnotherExampleResource(BaseView): + """ + A basic GET-able/POST-able resource. + """ + resource = MyFormValidation def get(self, request, num): """Handle GET requests""" -- cgit v1.2.3 From 370274f5640d55ef71422f7a2440710a43ff900e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 24 May 2011 10:27:24 +0100 Subject: Allow views to return HttpResponses. Add initial() hook method --- examples/resourceexample/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/resourceexample') diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py index 70d96891..29651fbf 100644 --- a/examples/resourceexample/views.py +++ b/examples/resourceexample/views.py @@ -1,6 +1,6 @@ from django.core.urlresolvers import reverse -from djangorestframework.views import BaseView +from djangorestframework.views import View from djangorestframework.resources import FormResource from djangorestframework.response import Response from djangorestframework import status @@ -14,7 +14,7 @@ class MyFormValidation(FormResource): form = MyForm -class ExampleResource(BaseView): +class ExampleResource(View): """ A basic read-only resource that points to 3 other resources. """ @@ -23,7 +23,7 @@ class ExampleResource(BaseView): return {"Some other resources": [reverse('another-example-resource', kwargs={'num':num}) for num in range(3)]} -class AnotherExampleResource(BaseView): +class AnotherExampleResource(View): """ A basic GET-able/POST-able resource. """ -- cgit v1.2.3