prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Locked pages report renders all users in "locked_by" filter
  ### Issue Summary
  
  Currently, the select-field for the "locked_by" filter on the "Locked pages"-report renders all users unfiltered from the user table.
  This breaks the view for one of our projects, which tries to list all 500k users...
  Actually, only the users which have locked a page should be listed.
  
  I will try to make a PR for that, in the meantime this quickfix works for us (with wagtail 4.0, django 3.2):
  ```python
  # in one of our apps.py
  from django.apps import AppConfig
  
  class BaseConfig(AppConfig):
      name = "base"
  
      def ready(self):
          patch_locked_pages_filter()
  
  def patch_locked_pages_filter():
      import django_filters
      from django.contrib.auth import get_user_model
  
      from wagtail.admin.views.reports.locked_pages import LockedPagesView, LockedPagesReportFilterSet
  
      def get_users_for_filter():
          User = get_user_model()
          return User.objects.filter(locked_pages__isnull=False).order_by(User.USERNAME_FIELD)
  
      class PatchedLockedPagesReportFilterSet(LockedPagesReportFilterSet):
          locked_by = django_filters.ModelChoiceFilter(
              field_name="locked_by", queryset=lambda request: get_users_for_filter()
          )
  
      LockedPagesView.filterset_class = PatchedLockedPagesReportFilterSet
  
  ```
  
  ### Steps to Reproduce
  
  1. Start a new project with `wagtail start myproject`
  2. Create many users, no matter if they have access to the CMS or not
  3. Open `/admin/reports/locked/` and find all those users in the "locked_by" dropdown on the right
  
  -   I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
  
  ### Technical details
  
  -   Python version: 3.10
  -   Django version: 3.2
  -   Wagtail version: 4.0, 2.15,... (according to the git history seems to be there from the beginning)
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `wagtail/admin/views/reports/locked_pages.py`
  Content:
  ```
  1 import datetime
  2 
  3 import django_filters
  4 from django.conf import settings
  5 from django.core.exceptions import PermissionDenied
  6 from django.utils.translation import gettext_lazy as _
  7 
  8 from wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet
  9 from wagtail.models import Page, UserPagePermissionsProxy
  10 
  11 from .base import PageReportView
  12 
  13 
  14 class LockedPagesReportFilterSet(WagtailFilterSet):
  15     locked_at = django_filters.DateFromToRangeFilter(widget=DateRangePickerWidget)
  16 
  17     class Meta:
  18         model = Page
  19         fields = ["locked_by", "locked_at", "live"]
  20 
  21 
  22 class LockedPagesView(PageReportView):
  23     template_name = "wagtailadmin/reports/locked_pages.html"
  24     title = _("Locked pages")
  25     header_icon = "lock"
  26     list_export = PageReportView.list_export + [
  27         "locked_at",
  28         "locked_by",
  29     ]
  30     filterset_class = LockedPagesReportFilterSet
  31 
  32     def get_filename(self):
  33         return "locked-pages-report-{}".format(
  34             datetime.datetime.today().strftime("%Y-%m-%d")
  35         )
  36 
  37     def get_queryset(self):
  38         pages = (
  39             (
  40                 UserPagePermissionsProxy(self.request.user).editable_pages()
  41                 | Page.objects.filter(locked_by=self.request.user)
  42             )
  43             .filter(locked=True)
  44             .specific(defer=True)
  45         )
  46 
  47         if getattr(settings, "WAGTAIL_I18N_ENABLED", False):
  48             pages = pages.select_related("locale")
  49 
  50         self.queryset = pages
  51         return super().get_queryset()
  52 
  53     def dispatch(self, request, *args, **kwargs):
  54         if not UserPagePermissionsProxy(request.user).can_remove_locks():
  55             raise PermissionDenied
  56         return super().dispatch(request, *args, **kwargs)
  57
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/wagtail/admin/views/reports/locked_pages.py b/wagtail/admin/views/reports/locked_pages.py
  --- a/wagtail/admin/views/reports/locked_pages.py
  +++ b/wagtail/admin/views/reports/locked_pages.py
  @@ -2,6 +2,7 @@
   
   import django_filters
   from django.conf import settings
  +from django.contrib.auth import get_user_model
   from django.core.exceptions import PermissionDenied
   from django.utils.translation import gettext_lazy as _
   
  @@ -11,8 +12,16 @@
   from .base import PageReportView
   
   
  +def get_users_for_filter():
  +    User = get_user_model()
  +    return User.objects.filter(locked_pages__isnull=False).order_by(User.USERNAME_FIELD)
  +
  +
   class LockedPagesReportFilterSet(WagtailFilterSet):
       locked_at = django_filters.DateFromToRangeFilter(widget=DateRangePickerWidget)
  +    locked_by = django_filters.ModelChoiceFilter(
  +        field_name="locked_by", queryset=lambda request: get_users_for_filter()
  +    )
   
       class Meta:
           model = Page
  
verification_info: {"golden_diff": "diff --git a/wagtail/admin/views/reports/locked_pages.py b/wagtail/admin/views/reports/locked_pages.py\n--- a/wagtail/admin/views/reports/locked_pages.py\n+++ b/wagtail/admin/views/reports/locked_pages.py\n@@ -2,6 +2,7 @@\n \n import django_filters\n from django.conf import settings\n+from django.contrib.auth import get_user_model\n from django.core.exceptions import PermissionDenied\n from django.utils.translation import gettext_lazy as _\n \n@@ -11,8 +12,16 @@\n from .base import PageReportView\n \n \n+def get_users_for_filter():\n+    User = get_user_model()\n+    return User.objects.filter(locked_pages__isnull=False).order_by(User.USERNAME_FIELD)\n+\n+\n class LockedPagesReportFilterSet(WagtailFilterSet):\n     locked_at = django_filters.DateFromToRangeFilter(widget=DateRangePickerWidget)\n+    locked_by = django_filters.ModelChoiceFilter(\n+        field_name=\"locked_by\", queryset=lambda request: get_users_for_filter()\n+    )\n \n     class Meta:\n         model = Page\n", "issue": "Locked pages report renders all users in \"locked_by\" filter\n### Issue Summary\r\n\r\nCurrently, the select-field for the \"locked_by\" filter on the \"Locked pages\"-report renders all users unfiltered from the user table.\r\nThis breaks the view for one of our projects, which tries to list all 500k users...\r\nActually, only the users which have locked a page should be listed.\r\n\r\nI will try to make a PR for that, in the meantime this quickfix works for us (with wagtail 4.0, django 3.2):\r\n```python\r\n# in one of our apps.py\r\nfrom django.apps import AppConfig\r\n\r\nclass BaseConfig(AppConfig):\r\n    name = \"base\"\r\n\r\n    def ready(self):\r\n        patch_locked_pages_filter()\r\n\r\ndef patch_locked_pages_filter():\r\n    import django_filters\r\n    from django.contrib.auth import get_user_model\r\n\r\n    from wagtail.admin.views.reports.locked_pages import LockedPagesView, LockedPagesReportFilterSet\r\n\r\n    def get_users_for_filter():\r\n        User = get_user_model()\r\n        return User.objects.filter(locked_pages__isnull=False).order_by(User.USERNAME_FIELD)\r\n\r\n    class PatchedLockedPagesReportFilterSet(LockedPagesReportFilterSet):\r\n        locked_by = django_filters.ModelChoiceFilter(\r\n            field_name=\"locked_by\", queryset=lambda request: get_users_for_filter()\r\n        )\r\n\r\n    LockedPagesView.filterset_class = PatchedLockedPagesReportFilterSet\r\n\r\n```\r\n\r\n### Steps to Reproduce\r\n\r\n1. Start a new project with `wagtail start myproject`\r\n2. Create many users, no matter if they have access to the CMS or not\r\n3. Open `/admin/reports/locked/` and find all those users in the \"locked_by\" dropdown on the right\r\n\r\n-   I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes\r\n\r\n### Technical details\r\n\r\n-   Python version: 3.10\r\n-   Django version: 3.2\r\n-   Wagtail version: 4.0, 2.15,... (according to the git history seems to be there from the beginning)\r\n\n", "before_files": [{"content": "import datetime\n\nimport django_filters\nfrom django.conf import settings\nfrom django.core.exceptions import PermissionDenied\nfrom django.utils.translation import gettext_lazy as _\n\nfrom wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet\nfrom wagtail.models import Page, UserPagePermissionsProxy\n\nfrom .base import PageReportView\n\n\nclass LockedPagesReportFilterSet(WagtailFilterSet):\n    locked_at = django_filters.DateFromToRangeFilter(widget=DateRangePickerWidget)\n\n    class Meta:\n        model = Page\n        fields = [\"locked_by\", \"locked_at\", \"live\"]\n\n\nclass LockedPagesView(PageReportView):\n    template_name = \"wagtailadmin/reports/locked_pages.html\"\n    title = _(\"Locked pages\")\n    header_icon = \"lock\"\n    list_export = PageReportView.list_export + [\n        \"locked_at\",\n        \"locked_by\",\n    ]\n    filterset_class = LockedPagesReportFilterSet\n\n    def get_filename(self):\n        return \"locked-pages-report-{}\".format(\n            datetime.datetime.today().strftime(\"%Y-%m-%d\")\n        )\n\n    def get_queryset(self):\n        pages = (\n            (\n                UserPagePermissionsProxy(self.request.user).editable_pages()\n                | Page.objects.filter(locked_by=self.request.user)\n            )\n            .filter(locked=True)\n            .specific(defer=True)\n        )\n\n        if getattr(settings, \"WAGTAIL_I18N_ENABLED\", False):\n            pages = pages.select_related(\"locale\")\n\n        self.queryset = pages\n        return super().get_queryset()\n\n    def dispatch(self, request, *args, **kwargs):\n        if not UserPagePermissionsProxy(request.user).can_remove_locks():\n            raise PermissionDenied\n        return super().dispatch(request, *args, **kwargs)\n", "path": "wagtail/admin/views/reports/locked_pages.py"}], "after_files": [{"content": "import datetime\n\nimport django_filters\nfrom django.conf import settings\nfrom django.contrib.auth import get_user_model\nfrom django.core.exceptions import PermissionDenied\nfrom django.utils.translation import gettext_lazy as _\n\nfrom wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet\nfrom wagtail.models import Page, UserPagePermissionsProxy\n\nfrom .base import PageReportView\n\n\ndef get_users_for_filter():\n    User = get_user_model()\n    return User.objects.filter(locked_pages__isnull=False).order_by(User.USERNAME_FIELD)\n\n\nclass LockedPagesReportFilterSet(WagtailFilterSet):\n    locked_at = django_filters.DateFromToRangeFilter(widget=DateRangePickerWidget)\n    locked_by = django_filters.ModelChoiceFilter(\n        field_name=\"locked_by\", queryset=lambda request: get_users_for_filter()\n    )\n\n    class Meta:\n        model = Page\n        fields = [\"locked_by\", \"locked_at\", \"live\"]\n\n\nclass LockedPagesView(PageReportView):\n    template_name = \"wagtailadmin/reports/locked_pages.html\"\n    title = _(\"Locked pages\")\n    header_icon = \"lock\"\n    list_export = PageReportView.list_export + [\n        \"locked_at\",\n        \"locked_by\",\n    ]\n    filterset_class = LockedPagesReportFilterSet\n\n    def get_filename(self):\n        return \"locked-pages-report-{}\".format(\n            datetime.datetime.today().strftime(\"%Y-%m-%d\")\n        )\n\n    def get_queryset(self):\n        pages = (\n            (\n                UserPagePermissionsProxy(self.request.user).editable_pages()\n                | Page.objects.filter(locked_by=self.request.user)\n            )\n            .filter(locked=True)\n            .specific(defer=True)\n        )\n\n        if getattr(settings, \"WAGTAIL_I18N_ENABLED\", False):\n            pages = pages.select_related(\"locale\")\n\n        self.queryset = pages\n        return super().get_queryset()\n\n    def dispatch(self, request, *args, **kwargs):\n        if not UserPagePermissionsProxy(request.user).can_remove_locks():\n            raise PermissionDenied\n        return super().dispatch(request, *args, **kwargs)\n", "path": "wagtail/admin/views/reports/locked_pages.py"}]}