Add polygon centroid sorting
Closes #1403 (closed)
This adds ?order={horizontal,vertical}-{lr,rl}
to ListElements
, ListElementChildren
and ListElementParents
, which is easier to do than doing it specifically on ListElementChildren
, since all three endpoints share their behavior. Quick tests on my local DB show that these orderings take as much time as sorting by name.
To do so cleanly, I extended the existing Centroid
function so it would be available as a transform, just like what we had done before with ST_MemSize
or ST_NumPoints
, and also added the missing ST_X
and ST_Y
functions, which are required to customize the coordinate sorting. This allows to use polygon__centroid__x
.
The ELEMENT_ORDERING_FIELDS
constant, which was originally meant to just allow to order by a single field on the Element model and no related field or Django transform, is renamed to ELEMENT_ORDERINGS
and holds all the parameters for order_by()
. This made it easier to handle edge cases with elements without polygons and to experiment with different ordering methods.
While troubleshooting issues with null values appearing first when they should have be last, I noticed we could use QuerySet.reverse()
to handle descending orders, so the order_direction
handling is now much simpler for all orderings.
Please read the API docs for the order
parameter very carefully to check that the behavior matches what was asked for in the Redmine issue, since I do not have access to it.