Skip to content

Commit 3a8a4fa

Browse files
committed
Code refactor
1 parent 9518c72 commit 3a8a4fa

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

ninja_extra/pagination.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"LimitOffsetPagination",
3333
"paginate",
3434
"PaginatedResponseSchema",
35+
"PaginatorOperation",
36+
"AsyncPaginatorOperation",
3537
]
3638

3739

@@ -202,8 +204,16 @@ def __init__(
202204
logger.debug(
203205
f"function {view_func.__name__} should have **kwargs if you want to use pagination parameters"
204206
)
205-
206-
self.as_view = wraps(view_func)(self.get_view_function())
207+
paginator_view = self.get_view_function()
208+
paginator_view._ninja_contribute_args = [ # type: ignore
209+
(
210+
self.paginator_kwargs_name,
211+
self.paginator.Input,
212+
self.paginator.InputSource,
213+
),
214+
]
215+
setattr(paginator_view, "paginator_operation", self)
216+
self.as_view = wraps(view_func)(paginator_view)
207217

208218
def get_view_function(self) -> Callable:
209219
def as_view(controller: "ControllerBase", *args: Any, **kw: Any) -> Any:
@@ -219,13 +229,6 @@ def as_view(controller: "ControllerBase", *args: Any, **kw: Any) -> Any:
219229
params["request"] = controller.context.request
220230
return self.paginator.paginate_queryset(items, **params)
221231

222-
as_view._ninja_contribute_args = [ # type: ignore
223-
(
224-
self.paginator_kwargs_name,
225-
self.paginator.Input,
226-
self.paginator.InputSource,
227-
),
228-
]
229232
return as_view
230233

231234

@@ -248,11 +251,4 @@ async def as_view(controller: "ControllerBase", *args: Any, **kw: Any) -> Any:
248251
)
249252
return await paginate_queryset(items, **params)
250253

251-
as_view._ninja_contribute_args = [ # type: ignore
252-
(
253-
self.paginator_kwargs_name,
254-
self.paginator.Input,
255-
self.paginator.InputSource,
256-
),
257-
]
258254
return as_view

0 commit comments

Comments
 (0)