Fixed #30722 -- Added default rate-limiting requests to admin's Select2 widget.
This commit is contained in:
parent
691def10a0
commit
8f6860863e
|
@ -410,6 +410,7 @@ class AutocompleteMixin:
|
||||||
attrs.setdefault('class', '')
|
attrs.setdefault('class', '')
|
||||||
attrs.update({
|
attrs.update({
|
||||||
'data-ajax--cache': 'true',
|
'data-ajax--cache': 'true',
|
||||||
|
'data-ajax--delay': 250,
|
||||||
'data-ajax--type': 'GET',
|
'data-ajax--type': 'GET',
|
||||||
'data-ajax--url': self.get_url(),
|
'data-ajax--url': self.get_url(),
|
||||||
'data-theme': 'admin-autocomplete',
|
'data-theme': 'admin-autocomplete',
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.admin.tests import AdminSeleniumTestCase
|
from django.contrib.admin.tests import AdminSeleniumTestCase
|
||||||
|
@ -189,6 +190,12 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
self.assertEqual(len(results), PAGINATOR_SIZE + 11)
|
self.assertEqual(len(results), PAGINATOR_SIZE + 11)
|
||||||
# Limit the results with the search field.
|
# Limit the results with the search field.
|
||||||
search.send_keys('Who')
|
search.send_keys('Who')
|
||||||
|
# Ajax request is delayed.
|
||||||
|
self.assertTrue(result_container.is_displayed())
|
||||||
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
|
self.assertEqual(len(results), PAGINATOR_SIZE + 12)
|
||||||
|
# Wait for ajax delay.
|
||||||
|
time.sleep(0.25)
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertTrue(result_container.is_displayed())
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
@ -223,6 +230,12 @@ class SeleniumTests(AdminSeleniumTestCase):
|
||||||
self.assertEqual(len(results), 31)
|
self.assertEqual(len(results), 31)
|
||||||
# Limit the results with the search field.
|
# Limit the results with the search field.
|
||||||
search.send_keys('Who')
|
search.send_keys('Who')
|
||||||
|
# Ajax request is delayed.
|
||||||
|
self.assertTrue(result_container.is_displayed())
|
||||||
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
|
self.assertEqual(len(results), 32)
|
||||||
|
# Wait for ajax delay.
|
||||||
|
time.sleep(0.25)
|
||||||
self.assertTrue(result_container.is_displayed())
|
self.assertTrue(result_container.is_displayed())
|
||||||
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
results = result_container.find_elements_by_css_selector('.select2-results__option')
|
||||||
self.assertEqual(len(results), 1)
|
self.assertEqual(len(results), 1)
|
||||||
|
|
|
@ -52,6 +52,7 @@ class AutocompleteMixinTests(TestCase):
|
||||||
self.assertEqual(attrs, {
|
self.assertEqual(attrs, {
|
||||||
'class': 'my-class admin-autocomplete',
|
'class': 'my-class admin-autocomplete',
|
||||||
'data-ajax--cache': 'true',
|
'data-ajax--cache': 'true',
|
||||||
|
'data-ajax--delay': 250,
|
||||||
'data-ajax--type': 'GET',
|
'data-ajax--type': 'GET',
|
||||||
'data-ajax--url': '/admin_widgets/band/autocomplete/',
|
'data-ajax--url': '/admin_widgets/band/autocomplete/',
|
||||||
'data-theme': 'admin-autocomplete',
|
'data-theme': 'admin-autocomplete',
|
||||||
|
|
Loading…
Reference in New Issue