The unpaginate decorator

Assuming you have a function that returns (or yields) one page of items, the following changes must be performed to use the Unpaginate library:

  • Decorate the function with @unpaginate(...)
  • Add a pagination parameter as first parameter of the decorated function
  • Use some attributes of pagination in the code to get the right items of the current page

Tip

If you decorate a class method instead of a function, the pagination parameter must be the second parameter instead, just after self.

Note

The pagination parameter is called by position and not by name, so you can use the / syntax from PEP 570 to reflect that. However, its name still needs to be called pagination.

Decorator parameters

These parameters can be passed when decorating the function. For example, decorate with @unpaginate(page=1) so that the index of the first page is 1.

page (int)

The initial value of pagination.page. Defaults to 0.

offset (int)

The initial value of pagination.offset. Defaults to 0.

context_factory (callable)

This function is called with no arguments to create the initial value of pagination.context. If not present, the initial value is None.

stop (callable)

Allows to specify the stop condition. Defaults to stop_when_empty.

Short form

It is possible to decorate with @unpaginate as a shortcut for @unpaginate().