Features: 1) Enhance rate-limiting decorators with method_decorator for better compatibility.
Fixes: 1) Ensure consistent application of `ratelimit` across methods. Extra: 1) Minor readability improvement in views using `method_decorator`.
This commit is contained in:
parent
ac439d7ead
commit
eecb4c9ec4
1 changed files with 4 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ from django.core.cache import cache
|
|||
from django.core.exceptions import BadRequest
|
||||
from django.http import FileResponse, Http404, JsonResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.decorators.cache import cache_page
|
||||
|
|
@ -315,7 +316,7 @@ class ContactUsView(APIView):
|
|||
YAMLRenderer,
|
||||
]
|
||||
|
||||
@ratelimit(key="ip", rate="2/h")
|
||||
@method_decorator(ratelimit(key="ip", rate="2/h", method="POST", block=True))
|
||||
def post(self, request, *args, **kwargs):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
|
@ -351,7 +352,7 @@ class RequestCursedURLView(APIView):
|
|||
YAMLRenderer,
|
||||
]
|
||||
|
||||
@ratelimit(key="ip", rate="10/h")
|
||||
@method_decorator(ratelimit(key="ip", rate="10/h"))
|
||||
def post(self, request, *args, **kwargs):
|
||||
url = request.data.get("url")
|
||||
if not is_url_safe(url):
|
||||
|
|
@ -427,7 +428,7 @@ class BuyAsBusinessView(APIView):
|
|||
Handles the "POST" request to process a business purchase.
|
||||
"""
|
||||
|
||||
@ratelimit(key="ip", rate="2/h", block=True)
|
||||
@method_decorator(ratelimit(key="ip", rate="2/h", block=True))
|
||||
def post(self, request, *_args, **kwargs):
|
||||
serializer = BuyAsBusinessOrderSerializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue