aboutsummaryrefslogtreecommitdiffstats
path: root/examples/resourceexample/views.py
diff options
context:
space:
mode:
authorTom Christie2011-06-02 12:58:10 +0100
committerTom Christie2011-06-02 12:58:10 +0100
commitb50492853f537a2473bb0a9eea86c8b0ed6b8824 (patch)
treed289d39aacf187a8a0696a4c1c863aabe1472c3a /examples/resourceexample/views.py
parent7ee9adbe5c03c29cd4a894dd476548f7fe73b5e4 (diff)
parentfc1640de75511006e89f033c9270ec91a9f1e4d4 (diff)
downloaddjango-rest-framework-b50492853f537a2473bb0a9eea86c8b0ed6b8824.tar.bz2
pull in -dev as 0.2.0
Diffstat (limited to 'examples/resourceexample/views.py')
-rw-r--r--examples/resourceexample/views.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py
index 41d2e5c5..29651fbf 100644
--- a/examples/resourceexample/views.py
+++ b/examples/resourceexample/views.py
@@ -1,31 +1,42 @@
from django.core.urlresolvers import reverse
-from djangorestframework.resource import Resource
+from djangorestframework.views import View
+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."""
- allowed_methods = anon_allowed_methods = ('GET',)
+class MyFormValidation(FormResource):
+ """
+ A resource which applies form validation on the input.
+ """
+ form = MyForm
- def get(self, request, auth):
+
+class ExampleResource(View):
+ """
+ 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."""
- 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):
+class AnotherExampleResource(View):
+ """
+ A basic GET-able/POST-able resource.
+ """
+ resource = MyFormValidation
+
+ 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))