From ef8c286f86027b2f7ebea2232730bd7340f20075 Mon Sep 17 00:00:00 2001 From: markotibold Date: Mon, 20 Jun 2011 01:11:08 +0200 Subject: [PATCH] added a `permissions` example with just a per-user-throttle which we may want to expand with some auth examples. --- examples/permissionsexample/__init__.py | 0 examples/permissionsexample/urls.py | 6 ++++++ examples/permissionsexample/views.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 examples/permissionsexample/__init__.py create mode 100644 examples/permissionsexample/urls.py create mode 100644 examples/permissionsexample/views.py diff --git a/examples/permissionsexample/__init__.py b/examples/permissionsexample/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/examples/permissionsexample/urls.py b/examples/permissionsexample/urls.py new file mode 100644 index 000000000..d17f5159a --- /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 000000000..20e7cba7a --- /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