diff --git a/oioioi/default_settings.py b/oioioi/default_settings.py index 3312bbeb5..8ab0ad963 100755 --- a/oioioi/default_settings.py +++ b/oioioi/default_settings.py @@ -239,7 +239,7 @@ 'oioioi.su.middleware.SuFirstTimeRedirectionMiddleware', 'oioioi.base.middleware.UserInfoInErrorMessage', 'django.contrib.messages.middleware.MessageMiddleware', - 'dj_pagination.middleware.PaginationMiddleware', + 'pagination.middleware.PaginationMiddleware', 'oioioi.contests.middleware.CurrentContestMiddleware', 'oioioi.base.middleware.HttpResponseNotAllowedMiddleware', 'oioioi.base.middleware.CheckLoginMiddleware', @@ -305,7 +305,7 @@ 'registration', 'django_extensions', 'compressor', - 'dj_pagination', + 'pagination', 'mptt', 'django.contrib.admin', @@ -391,7 +391,6 @@ # For dj_pagination PAGINATION_DEFAULT_WINDOW = 4 -PAGINATION_DEFAULT_MARGIN = 1 FILES_ON_PAGE = 100 PROBLEMS_ON_PAGE = 100 CONTESTS_ON_PAGE = 20 diff --git a/oioioi/deployment/settings.py.template b/oioioi/deployment/settings.py.template index af940f221..49f268060 100755 --- a/oioioi/deployment/settings.py.template +++ b/oioioi/deployment/settings.py.template @@ -273,7 +273,6 @@ FILETRACKER_CACHE_ROOT = '__DIR__/cache' # For dj_pagination # PAGINATION_DEFAULT_WINDOW = 4 -# PAGINATION_DEFAULT_MARGIN = 1 # FILES_ON_PAGE = 100 # PROBLEMS_ON_PAGE = 100 # CONTESTS_ON_PAGE = 20 diff --git a/oioioi/rankings/controllers.py b/oioioi/rankings/controllers.py index 5ccc2ff85..326737572 100644 --- a/oioioi/rankings/controllers.py +++ b/oioioi/rankings/controllers.py @@ -190,9 +190,16 @@ def _fake_request(self, page): fake_req = RequestFactory().get("/?page=" + str(page)) fake_req.user = AnonymousUser() fake_req.contest = self.contest - # This is required by dj-pagination - # Normally they monkey patch this function in their middleware - fake_req.page = lambda _: page + # django-pagination-py3 reads request.page as a property returning an int. + # We create a per-call subclass so we can override the property cleanly + # without mutating the shared WSGIRequest class (which the middleware + # already patches at the class level). + page_number = page + fake_req.__class__ = type( + "PaginatedRequest", + (type(fake_req),), + {"page": property(lambda self: page_number)}, + ) return fake_req def _render_ranking_page(self, key, data, page): diff --git a/pyproject.toml b/pyproject.toml index 929644ab4..d25727ea6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ "django-registration-redux>=2.12,<2.13", "Celery>=5.5,<5.6", "drf-spectacular>=0.28.0", - "dj-pagination>=2.5,<2.6", + "django-pagination-py3>=2.3.0", "django-compressor>=4.6,<4.7", "Pygments>=2.19,<2.20", "django-libsass>=0.9,<0.10",