aboutsummaryrefslogtreecommitdiffstats
path: root/examples/resourceexample/views.py
diff options
context:
space:
mode:
authorTom Christie2011-06-02 16:03:11 +0100
committerTom Christie2011-06-02 16:03:11 +0100
commit3531b0b35540ade216299c46717dcf9fa24487c7 (patch)
tree813755ed96aa7a0476a719b570635424119f0000 /examples/resourceexample/views.py
parentbf9ea978bca8928ba5726e4ec3d76e81d72aada8 (diff)
downloaddjango-rest-framework-3531b0b35540ade216299c46717dcf9fa24487c7.tar.bz2
More updating docs for 0.2
--HG-- rename : docs/examples/modelresources.rst => docs/examples/modelviews.rst rename : docs/examples/resources.rst => docs/examples/views.rst
Diffstat (limited to 'examples/resourceexample/views.py')
-rw-r--r--examples/resourceexample/views.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py
index 29651fbf..990c7834 100644
--- a/examples/resourceexample/views.py
+++ b/examples/resourceexample/views.py
@@ -1,42 +1,45 @@
from django.core.urlresolvers import reverse
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 MyFormValidation(FormResource):
- """
- A resource which applies form validation on the input.
- """
- form = MyForm
-
-class ExampleResource(View):
+class ExampleView(View):
"""
- A basic read-only resource that points to 3 other resources.
+ A basic read-only view that points to 3 other views.
"""
def get(self, request):
- return {"Some other resources": [reverse('another-example-resource', kwargs={'num':num}) for num in range(3)]}
+ """
+ Handle GET requests, returning a list of URLs pointing to 3 other views.
+ """
+ return {"Some other resources": [reverse('another-example', kwargs={'num':num}) for num in range(3)]}
-class AnotherExampleResource(View):
+class AnotherExampleView(View):
"""
- A basic GET-able/POST-able resource.
+ A basic view, that can be handle GET and POST requests.
+ Applies some simple form validation on POST requests.
"""
- resource = MyFormValidation
+ form = MyForm
def get(self, request, num):
- """Handle GET requests"""
+ """
+ Handle GET requests.
+ Returns a simple string indicating which view the GET request was for.
+ """
if int(num) > 2:
return Response(status.HTTP_404_NOT_FOUND)
return "GET request to AnotherExampleResource %s" % num
def post(self, request, num):
- """Handle POST requests"""
+ """
+ Handle POST requests, with form validation.
+ Returns a simple string indicating what content was supplied.
+ """
if int(num) > 2:
return Response(status.HTTP_404_NOT_FOUND)
return "POST request to AnotherExampleResource %s, with content: %s" % (num, repr(self.CONTENT))