mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 17:39:48 +03:00
added docstring
This commit is contained in:
parent
3d3d0ffa53
commit
76321de748
|
@ -26,7 +26,13 @@ from rest_framework.settings import api_settings
|
|||
|
||||
|
||||
class SearchFilterForm(forms.Form):
|
||||
"""
|
||||
A form to sanitize incoming search parameter value.
|
||||
"""
|
||||
def __init__(self, search_field, *args, **kwargs):
|
||||
"""
|
||||
Override to pass search_param name (e.g. "search") and dynamically set as a CharField.
|
||||
"""
|
||||
super(SearchFilterForm, self).__init__(*args, **kwargs)
|
||||
self.fields[search_field] = forms.CharField()
|
||||
|
||||
|
@ -72,7 +78,8 @@ class SearchFilter(BaseFilterBackend):
|
|||
def get_search_terms(self, request):
|
||||
"""
|
||||
Search terms are set by a ?search=... query parameter,
|
||||
and may be comma and/or whitespace delimited.
|
||||
and may be comma and/or whitespace delimited. Sanitize
|
||||
the search param string by running it through a form.
|
||||
"""
|
||||
form = SearchFilterForm(self.search_param, request.query_params.dict())
|
||||
if form.is_valid():
|
||||
|
|
Loading…
Reference in New Issue
Block a user