Refactor image chooser pagination to check WAGTAILIMAGES_CHOOSER_PAGE_SIZE at runtime #11898
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reworking of #11884, to fix #11813.
The problem with setting
per_page
as an attribute on the viewset is that it requires reading the setting on module load, which means we can't useoverride_settings
to test it. Instead, make it a property onBaseImageChooseView
so that it gets read back at runtime. (Which in turn means that theconstruct_view
logic in the base ViewSet class needs to take care not to write to attributes on the view if they're actually properties.)We could also have done this by adding a
get_per_page
method on the generic chooser view (defaulting to just returningself.per_page
) and making it overrideable on the viewset usinginject_view_methods
- but we've pretty much settled on using properties rather thanget_foo
methods in our generic views now.I also took the liberty of increasing the default page size to 20, since this bug inadvertently created an ambiguity over whether the "correct" value is 10 (which works for rows of 5) or 12 (which works for rows of 4) - this way it works equally well for both :-)