added a container view for the permissions example

This commit is contained in:
markotibold 2011-06-25 16:38:16 +02:00
parent ddd36206bc
commit bae21b14c9
3 changed files with 24 additions and 5 deletions

View File

@ -1,6 +1,8 @@
from django.conf.urls.defaults import patterns, url
from permissionsexample.views import ThrottlingExampleView
from permissionsexample.views import PermissionsExampleView, ThrottlingExampleView, LoggedinView
urlpatterns = patterns('',
url(r'^$', ThrottlingExampleView.as_view(), name='throttled-resource'),
url(r'^$', PermissionsExampleView.as_view(), name='permissions-example'),
url(r'^throttling$', ThrottlingExampleView.as_view(), name='throttled-resource'),
url(r'^loggedin$', LoggedinView.as_view(), name='loggedin-resource'),
)

View File

@ -1,6 +1,16 @@
from djangorestframework.views import View
from djangorestframework.permissions import PerUserThrottling
from djangorestframework.permissions import PerUserThrottling, IsAuthenticated
from django.core.urlresolvers import reverse
class PermissionsExampleView(View):
"""
A container view for permissions examples.
"""
def get(self, request):
return [{'name': 'Throttling Example', 'url': reverse('throttled-resource')},
{'name': 'Logged in example', 'url': reverse('loggedin-resource')},]
class ThrottlingExampleView(View):
"""
@ -17,4 +27,10 @@ class ThrottlingExampleView(View):
"""
Handle GET requests.
"""
return "Successful response to GET request because throttle is not yet active."
return "Successful response to GET request because throttle is not yet active."
class LoggedinView(View):
permissions = (IsAuthenticated, )
def get(self, request):
return 'Logged in or not?'

View File

@ -22,6 +22,7 @@ class Sandbox(View):
4. A generic object store API.
5. A code highlighting API.
6. A blog posts and comments API.
7. A basic example using permissions. You can login with **'test', 'test'.**
Please feel free to browse, create, edit and delete the resources in these examples."""
@ -32,5 +33,5 @@ class Sandbox(View):
{'name': 'Object store API', 'url': reverse('object-store-root')},
{'name': 'Code highlighting API', 'url': reverse('pygments-root')},
{'name': 'Blog posts API', 'url': reverse('blog-posts-root')},
{'name': 'Permissions example', 'url': reverse('throttled-resource')}
{'name': 'Permissions example', 'url': reverse('permissions-example')}
]