mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 18:08:03 +03:00 
			
		
		
		
	added a container view for the permissions example
This commit is contained in:
		
							parent
							
								
									ddd36206bc
								
							
						
					
					
						commit
						bae21b14c9
					
				| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
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'),
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,15 @@
 | 
				
			||||||
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):
 | 
				
			||||||
| 
						 | 
					@ -18,3 +28,9 @@ 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."
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					class LoggedinView(View):
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    permissions = (IsAuthenticated, )
 | 
				
			||||||
 | 
					    def get(self, request):
 | 
				
			||||||
 | 
					        return 'Logged in or not?'
 | 
				
			||||||
| 
						 | 
					@ -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):
 | 
				
			||||||
                {'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')}
 | 
				
			||||||
                ]
 | 
					                ]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user