diff options
| author | tom christie tom@tomchristie.com | 2011-01-23 23:08:44 +0000 |
|---|---|---|
| committer | tom christie tom@tomchristie.com | 2011-01-23 23:08:44 +0000 |
| commit | e95198a1c0b206bd3b565bb62d167ada71595099 (patch) | |
| tree | 65dc7f469b28f09783b732862ab9822b8528f10d /src/testapp/views.py | |
| parent | 4100242fa2395bef8db0c5ffbab6f5d0cf95301d (diff) | |
| download | django-rest-framework-e95198a1c0b206bd3b565bb62d167ada71595099.tar.bz2 | |
Sphinx docs, examples, lots of refactoring
Diffstat (limited to 'src/testapp/views.py')
| -rw-r--r-- | src/testapp/views.py | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/testapp/views.py b/src/testapp/views.py deleted file mode 100644 index 82539435..00000000 --- a/src/testapp/views.py +++ /dev/null @@ -1,118 +0,0 @@ -from rest.resource import Resource -from rest.modelresource import ModelResource, QueryModelResource -from testapp.models import BlogPost, Comment - -##### Root Resource ##### - -class RootResource(Resource): - """This is the top level resource for the API. - All the sub-resources are discoverable from here.""" - allowed_operations = ('read',) - - def read(self, headers={}, *args, **kwargs): - return (200, {'blog-posts': self.reverse(BlogPostList), - 'blog-post': self.reverse(BlogPostCreator)}, {}) - - -##### Blog Post Resources ##### - -BLOG_POST_FIELDS = ('created', 'title', 'slug', 'content', 'absolute_url', 'comment_url', 'comments_url') - -class BlogPostList(QueryModelResource): - """A resource which lists all existing blog posts.""" - allowed_operations = ('read', ) - model = BlogPost - fields = BLOG_POST_FIELDS - -class BlogPostCreator(ModelResource): - """A resource with which blog posts may be created.""" - allowed_operations = ('create',) - model = BlogPost - fields = BLOG_POST_FIELDS - -class BlogPostInstance(ModelResource): - """A resource which represents a single blog post.""" - allowed_operations = ('read', 'update', 'delete') - model = BlogPost - fields = BLOG_POST_FIELDS - - -##### Comment Resources ##### - -COMMENT_FIELDS = ('username', 'comment', 'created', 'rating', 'absolute_url', 'blogpost_url') - -class CommentList(QueryModelResource): - """A resource which lists all existing comments for a given blog post.""" - allowed_operations = ('read', ) - model = Comment - fields = COMMENT_FIELDS - -class CommentCreator(ModelResource): - """A resource with which blog comments may be created for a given blog post.""" - allowed_operations = ('create',) - model = Comment - fields = COMMENT_FIELDS - -class CommentInstance(ModelResource): - """A resource which represents a single comment.""" - allowed_operations = ('read', 'update', 'delete') - model = Comment - fields = COMMENT_FIELDS - - - -# -#'read-only-api': self.reverse(ReadOnlyResource), -# 'write-only-api': self.reverse(WriteOnlyResource), -# 'read-write-api': self.reverse(ReadWriteResource), -# 'model-api': self.reverse(ModelFormResource), -# 'create-container': self.reverse(ContainerFactory), -# -#class ReadOnlyResource(Resource): -# """This is my docstring -# """ -# allowed_operations = ('read',) -# -# def read(self, headers={}, *args, **kwargs): -# return (200, {'ExampleString': 'Example', -# 'ExampleInt': 1, -# 'ExampleDecimal': 1.0}, {}) -# -# -#class WriteOnlyResource(Resource): -# """This is my docstring -# """ -# allowed_operations = ('update',) -# -# def update(self, data, headers={}, *args, **kwargs): -# return (200, data, {}) -# -# -#class ReadWriteResource(Resource): -# allowed_operations = ('read', 'update', 'delete') -# create_form = ExampleForm -# update_form = ExampleForm -# -# -#class ModelFormResource(ModelResource): -# allowed_operations = ('read', 'update', 'delete') -# model = ExampleModel -# -## Nice things: form validation is applied to any input type -## html forms for output -## output always serialized nicely -#class ContainerFactory(ModelResource): -# allowed_operations = ('create',) -# model = ExampleContainer -# fields = ('absolute_uri', 'name', 'key') -# form_fields = ('name',) -# -# -#class ContainerInstance(ModelResource): -# allowed_operations = ('read', 'update', 'delete') -# model = ExampleContainer -# fields = ('absolute_uri', 'name', 'key') -# form_fields = ('name',) - -####################### - |
