From 1c802ca2a9d3c66fb723695fe7ea597fb4802402 Mon Sep 17 00:00:00 2001 From: Maxim Milovanov Date: Wed, 6 Oct 2021 10:01:31 +0300 Subject: [PATCH] Fixed #33156 -- Used sessionStorage to preserve quick filter for admin's navigation sidebar. --- django/contrib/admin/static/admin/js/nav_sidebar.js | 4 ++-- tests/admin_views/test_nav_sidebar.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/contrib/admin/static/admin/js/nav_sidebar.js b/django/contrib/admin/static/admin/js/nav_sidebar.js index d262c26bb2..86cb1cf837 100644 --- a/django/contrib/admin/static/admin/js/nav_sidebar.js +++ b/django/contrib/admin/static/admin/js/nav_sidebar.js @@ -74,7 +74,7 @@ } else { event.target.classList.add('no-results'); } - localStorage.setItem('django.admin.navSidebarFilterValue', filterValue); + sessionStorage.setItem('django.admin.navSidebarFilterValue', filterValue); } const nav = document.getElementById('nav-filter'); @@ -82,7 +82,7 @@ nav.addEventListener('input', checkValue, false); nav.addEventListener('keyup', checkValue, false); - const storedValue = localStorage.getItem('django.admin.navSidebarFilterValue'); + const storedValue = sessionStorage.getItem('django.admin.navSidebarFilterValue'); if (storedValue) { nav.value = storedValue; checkValue({target: nav, key: ''}); diff --git a/tests/admin_views/test_nav_sidebar.py b/tests/admin_views/test_nav_sidebar.py index c2e45d91a2..102e4d0064 100644 --- a/tests/admin_views/test_nav_sidebar.py +++ b/tests/admin_views/test_nav_sidebar.py @@ -167,7 +167,7 @@ class SeleniumTests(AdminSeleniumTestCase): reverse('test_with_sidebar:auth_user_changelist') ) filter_value_script = ( - "return localStorage.getItem('django.admin.navSidebarFilterValue')" + "return sessionStorage.getItem('django.admin.navSidebarFilterValue')" ) self.assertIsNone(self.selenium.execute_script(filter_value_script)) filter_input = self.selenium.find_element_by_css_selector('#nav-filter')