Comments (6)
implemented in the permission
module. Plus wrote a test. Both test and implementation need refactoring.
from django-rest-framework.
I would probably store it based on the name of the Resource class.
Actually even better would be if the throttle has a get_cache_key() method.
For per-user it'd return the user id, for the per-resource it'd return the
Resource class name - then have both Thottle classes inherit from a
BaseThrottle class. Then it's super obvious and easy for anyone to provide
for alternative caching behavior.
Actually thinking about it there's a few ways that a BaseThrottle class
could be made easier to override.
I think it's refactor nicely to:
BaseThrottle(BasePermission):
get_cache_key(self) # Not Implemented
check_throttle(self, cache_key)
throttle_success(self, cache_key)
throttle_failure(self, cache_key)
PerUserThrottle(BaseThrottle):
get_cache_key(self)
PerResourceThrottle(BaseThrottle):
get_cache_key(self)
Also thinking about it I think it'd be nice if the .throttle attribute was
string like '10/sec', '45/min', '100/hour', '100/day', '10/s' '45/m' etc...
instead of being a 2-tuple
So something like:
num, period = getattr(self.view, 'throttle', '0/sec').partition('/')
num = int(num)
period = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]
On 11 June 2011 01:22, markotibold <
[email protected]>wrote:
It would be nice to be able to throttle requests to a resource, not only
per user. Only question is: should we store thethrottle
in the cache
based on the url of the resource or based on the View's class....Reply to this email directly or view it on GitHub:
#25
from django-rest-framework.
Yeah that's a good idea!
But to return self.view.resource.__class__.__name__
in the gey_cache_key()
method would imply the View actually has a resource set. But this is not necessarily the case. We can have it store the name of the view then instead. Any thoughts?
from django-rest-framework.
Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)
from django-rest-framework.
Ok, I got it all implemented and tested. Check out my latest commits. Did
some proper refactoring on last nights work.
Cheers,
Mako
On 11 June 2011 19:44, tomchristie <
[email protected]>wrote:
Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)
Reply to this email directly or view it on GitHub:
from django-rest-framework.
Oops, ignore my latest github ticket then :)
Nice work.
I'll pull this bit in tomorrow...
On 11 June 2011 19:36, markotibold <
[email protected]>wrote:
Ok, I got it all implemented and tested. Check out my latest commits. Did
some proper refactoring on last nights work.Cheers,
Mako
On 11 June 2011 19:44, tomchristie <
[email protected]>wrote:Fair point. Would be fine yeah. Call it PerViewThrottling tho' ;)
Reply to this email directly or view it on GitHub:
Reply to this email directly or view it on GitHub:
from django-rest-framework.
Related Issues (20)
- 3.15.0 - bug in rendering `%` characters from `ValidationError` HOT 4
- `permissions.DjangoModelPermissionsOrAnonReadOnly` doesn't actually enable anonymous read-only access in 3.15 HOT 3
- Error: An admin for model "User" has to be registered to be referenced by TokenAdmin.autocomplete_fields. HOT 6
- 3.15 not backwards compatible with 3.14 - "View' should either include a `queryset` attribute, or override the `get_queryset()` method." HOT 11
- 3.15 backward compatibility issue with 3.14 - `rest_framework.filters.SearchFilter.get_search_terms` returns `str` instead of `list` HOT 3
- New handling of default= for ModelSerializer HOT 6
- 3.15 regression: ListSerializer ValidationErrors silently changed return type
- 3.15 regression: ListSerializer ValidationError nested structure silently changed HOT 1
- 3.15 regression: UpdateModelMixin breaks views using Manager objects as queryset HOT 4
- Version 3.15.1 HOT 1
- 3.15 regression: Unset default namespace version suddenly raises 404 HOT 3
- 3.15(.1?) regression: optional fields in serializers are suddenly required (or need explicit None passed) HOT 11
- UniqueConstraint violation_error_message as error response in drf
- rest-framework Supports async class views ?
- 3.15 regression: Serializer validation failed for unique together constraint HOT 1
- Revert changes to `CursorPagination` that caused serious performance regression HOT 1
- Router.register cannot merge with urlpatters HOT 3
- UniqueTogetherValidator does not comply to Database standards
- HyperlinkedModelSerializer doesn't respect SECURE_PROXY_SSL_HEADER settings
- 3.15 is raising required error on model nullable fields HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-framework.