Commit bae21b14 by markotibold

added a container view for the permissions example

parent ddd36206
from django.conf.urls.defaults import patterns, url from django.conf.urls.defaults import patterns, url
from permissionsexample.views import ThrottlingExampleView from permissionsexample.views import PermissionsExampleView, ThrottlingExampleView, LoggedinView
urlpatterns = patterns('', 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'),
) )
from djangorestframework.views import View 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): class ThrottlingExampleView(View):
""" """
...@@ -17,4 +27,10 @@ class ThrottlingExampleView(View): ...@@ -17,4 +27,10 @@ class ThrottlingExampleView(View):
""" """
Handle GET requests. 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."
\ No newline at end of file
class LoggedinView(View):
permissions = (IsAuthenticated, )
def get(self, request):
return 'Logged in or not?'
\ No newline at end of file
...@@ -22,6 +22,7 @@ class Sandbox(View): ...@@ -22,6 +22,7 @@ class Sandbox(View):
4. A generic object store API. 4. A generic object store API.
5. A code highlighting API. 5. A code highlighting API.
6. A blog posts and comments 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.""" Please feel free to browse, create, edit and delete the resources in these examples."""
...@@ -32,5 +33,5 @@ class Sandbox(View): ...@@ -32,5 +33,5 @@ class Sandbox(View):
{'name': 'Object store API', 'url': reverse('object-store-root')}, {'name': 'Object store API', 'url': reverse('object-store-root')},
{'name': 'Code highlighting API', 'url': reverse('pygments-root')}, {'name': 'Code highlighting API', 'url': reverse('pygments-root')},
{'name': 'Blog posts API', 'url': reverse('blog-posts-root')}, {'name': 'Blog posts API', 'url': reverse('blog-posts-root')},
{'name': 'Permissions example', 'url': reverse('throttled-resource')} {'name': 'Permissions example', 'url': reverse('permissions-example')}
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment