From 4e156328752a19f6251a166de4f8a2de0b45da7d Mon Sep 17 00:00:00 2001 From: "tom christie tom@tomchristie.com" Date: Tue, 1 Feb 2011 23:07:55 +0000 Subject: [PATCH] Updated resourceexample with seperate form.py --- examples/resourceexample/forms.py | 6 ++++++ examples/resourceexample/urls.py | 2 +- examples/resourceexample/views.py | 12 ++---------- 3 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 examples/resourceexample/forms.py diff --git a/examples/resourceexample/forms.py b/examples/resourceexample/forms.py new file mode 100644 index 000000000..e484afba2 --- /dev/null +++ b/examples/resourceexample/forms.py @@ -0,0 +1,6 @@ +from django import forms + +class MyForm(forms.Form): + foo = forms.BooleanField() + bar = forms.IntegerField(help_text='Must be an integer.') + baz = forms.CharField(max_length=32, help_text='Free text. Max length 32 chars.') diff --git a/examples/resourceexample/urls.py b/examples/resourceexample/urls.py index 01cc7c62e..828caef20 100644 --- a/examples/resourceexample/urls.py +++ b/examples/resourceexample/urls.py @@ -1,6 +1,6 @@ from django.conf.urls.defaults import patterns, url urlpatterns = patterns('resourceexample.views', - url(r'^$', 'ExampleResource'), + url(r'^$', 'ExampleResource'), url(r'^(?P[0-9]+)/$', 'AnotherExampleResource'), ) diff --git a/examples/resourceexample/views.py b/examples/resourceexample/views.py index 650a8e39d..e5bb5efab 100644 --- a/examples/resourceexample/views.py +++ b/examples/resourceexample/views.py @@ -1,13 +1,6 @@ -from django import forms from djangorestframework.resource import Resource from djangorestframework.response import Response, status - - -class MyForm(forms.Form): - foo = forms.BooleanField() - bar = forms.IntegerField(help_text='Must be an integer.') - baz = forms.CharField(max_length=32, help_text='Free text. Max length 32 chars.') - +from resourceexample.forms import MyForm class ExampleResource(Resource): """A basic read only resource that points to 3 other resources.""" @@ -16,11 +9,10 @@ class ExampleResource(Resource): def get(self, request, auth): return {"Some other resources": [self.reverse(AnotherExampleResource, 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 + 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): """Handle GET requests"""