M README.md +2 -2
@@ 361,8 361,8 @@ It is optional, and defaults to False (i
MAX_FILTER_SIZE
The max number of items acceptable in the admin list filters. If the
-number of items exceeds this, then the filter is removed (just shows
-all). This is used by the "Filter by impersonator" filter.
+number of items exceeds this, then the filter list is the size of the settings
+value. This is used by the "Filter by impersonator" filter.
It is optional, and defaults to 100.
M impersonate/admin.py +7 -6
@@ 80,22 80,23 @@ class ImpersonatorFilter(admin.SimpleLis
.order_by()
.values_list('impersonator_id', flat=True,)
.distinct('impersonator_id')
- )
+ )[:MAX_FILTER_SIZE]
except (NotSupportedError, NotImplementedError):
# Unit tests use sqlite db backend which doesn't support distinct.
- qs = model_admin.get_queryset(request).only('impersonator_id')
+ qs = model_admin.get_queryset(request).only('impersonator_id')[
+ :MAX_FILTER_SIZE
+ ]
ids = set([x.impersonator_id for x in qs])
if len(ids) > MAX_FILTER_SIZE:
- logger.debug(
+ logger.info(
(
- 'Hiding admin list filter as number of impersonators [{0}] '
- 'exceeds MAX_FILTER_SIZE [{1}]'
+ 'Limiting admin list filter as number of impersonators '
+ '[{0}] exceeds MAX_FILTER_SIZE [{1}]'
).format(
len(ids), MAX_FILTER_SIZE,
)
)
- return
impersonators = User.objects.filter(id__in=ids).order_by(
User.USERNAME_FIELD
M impersonate/tests.py +1 -1
@@ 720,7 720,7 @@ class TestImpersonation(TestCase):
opts = [
(_id, name) for _id, name in _filter.lookups(None, model_admin)
]
- self.assertEqual(len(opts), 0)
+ self.assertEqual(len(opts), 1)
def test_impersonatelog_admin_add_delete_permissions(self):
model_admin = ImpersonationLogAdmin(ImpersonationLog, AdminSite())