websauna.system.crud.paginator module

Paginator.

class websauna.system.crud.paginator.Batch(seq, request, url=None, default_size=10, toggle_size=40, seqlen=None)[source]

Bases: object

Present one paginator batch in the list rendering output.

Originally courtesy of SubstanceD project.

Given a sequence named seq, and a Pyramid request, return an object with the following attributes:

items

A list representing a slice of seq. It will contain the number of elements in request.params['batch_size'] or the default_size number if such a key does not exist in request.params or the key is invalid. The slice will begin at request.params['batch_num'] or zero if such a key does not exist in request.params or the batch_num key could not successfully be converted to a positive integer.

This value can be iterated over via the __iter__ of the batch object.

size

The value obtained from request.params['batch_size'] or default_size if no batch_size parameter exists in request.params or the batch_size parameter could not successfully be converted to a positive interger.

num

The value obtained from request.params['batch_num'] or 0 if no batch_num parameter exists in request.params or if the batch_num parameter could not successfully be converted to a positive integer. Batch numbers are indexed from zero, so batch 0 is the first batch, batch 1 the second, and so forth.

length

This is length of the current batch. It is usually equal to size but may be different in the very last batch. For example, if the seq is [1,2,3,4] and the batch size is 3, the first batch’s length will be 3 because the batch content will be [1,2,3]; but the second and final batch’s length will be 1 because the batch content will be [4].

last

The batch number computed from the sequence length of the last batch (indexed from zero).

first_url

The URL of the first batch. This will be a URL with batch_num and batch_size in its query string. The base URL will be taken from the url value passed to this function. If a url value is not passed to this function, the URL will be taken from request.url. This value will be None if the current batch_num is 0.

prev_url

The URL of the previous batch. This will be a URL with batch_num and batch_size in its query string. The base URL will be taken from the url value passed to this function. If a url value is not passed to this function, the URL will be taken from request.url. This value will be None if there is no previous batch.

next_url

The URL of the next batch. This will be a URL with batch_num and batch_size in its query string. The base URL will be taken from the url value passed to this function. If a url value is not passed to this function, the URL will be taken from request.url. This value will be None if there is no next batch.

last_url

The URL of the next batch. This will be a URL with batch_num and batch_size in its query string. The base URL will be taken from the url value passed to this function. If a url value is not passed to this function, the URL will be taken from request.url. This value will be None if there is no next batch.

required

True if either next_url or prev_url are True (meaning batching is required).

multicolumn

True if the current view should be rendered in multiple columns.

toggle_url

The URL to be used for the multicolumn/single column toggle button. The batch_size, batch_num, and multicolumn parameters are converted to their multicolumn or single column equivalents. If a user is viewing items 40-80 in multiple columns, the toggle will switch to items 40-50 in a single column. If a user is viewing items 50-60 in a single column, the toggle will switch to items 40-80 in multiple columns.

toggle_text

The text to display on the multi-column/single column toggle.

make_columns

A method to split items into a nested list representing columns.

seqlen

This is total length of the sequence (across all batches).

startitem

The item number that starts this batch (indexed from zero).

enditem

The item number that ends this batch (indexed from zero).

make_columns(column_size=10, num_columns=4)[source]

Break self.items into a nested list representing columns.

class websauna.system.crud.paginator.DefaultPaginator(template=None, default_size=None)[source]

Bases: object

Default pagination implementation for CRUD, having 20 items per page.

default_size = 20
paginate(seq, request, count, url=None)[source]
Return type

Batch

template = 'crud/paginator.html'
websauna.system.crud.paginator.merge_url_qs(url, **kw)[source]

Merge the query string elements of a URL with the ones in kw.

If any query string element exists in url that also exists in kw, replace it.

Parameters
  • url (str) – An URL.

  • kw – Dictionary with keyword arguments.

Return type

str

Returns

An URL with keyword arguments merged into the query string.