diff options
| author | markotibold | 2011-06-20 01:11:08 +0200 | 
|---|---|---|
| committer | markotibold | 2011-06-20 01:11:08 +0200 | 
| commit | ef8c286f86027b2f7ebea2232730bd7340f20075 (patch) | |
| tree | 6c3f018956e3d248bef53dd2723ec44a7b189cd4 /examples/permissionsexample | |
| parent | 37db771cb97052cdf4890dc47168b995d80ee64e (diff) | |
| download | django-rest-framework-ef8c286f86027b2f7ebea2232730bd7340f20075.tar.bz2 | |
added a `permissions` example with just a per-user-throttle which we may want to expand with some auth examples.
Diffstat (limited to 'examples/permissionsexample')
| -rw-r--r-- | examples/permissionsexample/__init__.py | 0 | ||||
| -rw-r--r-- | examples/permissionsexample/urls.py | 6 | ||||
| -rw-r--r-- | examples/permissionsexample/views.py | 20 | 
3 files changed, 26 insertions, 0 deletions
diff --git a/examples/permissionsexample/__init__.py b/examples/permissionsexample/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/examples/permissionsexample/__init__.py diff --git a/examples/permissionsexample/urls.py b/examples/permissionsexample/urls.py new file mode 100644 index 00000000..d17f5159 --- /dev/null +++ b/examples/permissionsexample/urls.py @@ -0,0 +1,6 @@ +from django.conf.urls.defaults import patterns, url +from permissionsexample.views import ThrottlingExampleView + +urlpatterns = patterns('', +    url(r'^$',                 ThrottlingExampleView.as_view(), name='throttled-resource'), +) diff --git a/examples/permissionsexample/views.py b/examples/permissionsexample/views.py new file mode 100644 index 00000000..20e7cba7 --- /dev/null +++ b/examples/permissionsexample/views.py @@ -0,0 +1,20 @@ +from djangorestframework.views import View +from djangorestframework.permissions import PerUserThrottling + + +class ThrottlingExampleView(View): +    """ +    A basic read-only View that has a **per-user throttle** of 10 requests per minute. +     +    If a user exceeds the 10 requests limit within a period of one minute, the +    throttle will be applied until 60 seconds have passed since the first request. +    """ +     +    permissions = ( PerUserThrottling, ) +    throttle = '10/min' +     +    def get(self, request): +        """ +        Handle GET requests. +        """ +        return "Successful response to GET request because throttle is not yet active."
\ No newline at end of file  | 
