Expand description
Shared list-endpoint query-parameter helpers — one place that owns the
reserved-key skip list, ?ordering= parsing and ?page_size= clamping,
so viewset::handle_list and template_views::ListView cannot drift
apart.
Query-parameter parsing shared by list endpoints.
viewset::handle_list and the
ListView CBV read the same
parameters: ?page=N, ?ordering=col, ?search=term, and the
model’s own filter keys. This module holds the parts they must
agree on:
RESERVED_LIST_KEYS/is_reserved_list_key— parameters that control paging, sorting and search, so they are never filters.parse_ordering— splits?ordering=col,-col2.clamp_page_size— resolves?page_size=N.parse_page/page_offset—?page=Nand its overflow-safe offset.split_in_list— a__invalue, capped atMAX_IN_VALUES;in_values_budgetcaps all lists of a request together.
Each layer still builds its own WHERE clause, because viewset supports a richer filter syntax than the CBV.
Enums§
- InList
TooLong - A
__inlist longer thanMAX_IN_VALUES, or__inlists whose sum passesin_values_budget.
Constants§
- MAX_
IN_ VALUES - Most values one
?field__in=list may carry. Far under every dialect’s bind limit, so a long list is a 400, not a driver error (#1865). - RESERVED_
LIST_ KEYS - Query keys that control paging, sorting and search. A list handler must never treat one of these as a model filter, even if a column has the same name.
Functions§
- clamp_
page_ size - Work out the page size from
?page_size=N. - in_
values_ budget - Most
__invalues one request may carry over all its lists, so a dialect withmax_bind_paramsbinds gets a 400 rather than a driver 500. - is_
reserved_ list_ key truewhenkeyis one ofRESERVED_LIST_KEYS. Use it to skip these keys before parsing filters:- page_
offset - Row offset of 1-based
page. Saturates, so a huge page is an empty page rather than a wrapped negative OFFSET (#1865). - parse_
ordering - Parse
?ordering=col,-col2,col3intoOrderItems. A leading-means descending. - parse_
page ?page=N, 1-based. Missing, garbage, zero or negative gives page 1.- split_
in_ list - Split a comma-separated
__invalue, dropping empty entries. Stops reading past the cap, so a 2 MB body is not split in full.