django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.73k stars 574 forks source link

Sorting of Files seems broken for 3.0.x versions #1415

Closed filipweidemann closed 10 months ago

filipweidemann commented 10 months ago

Hey there,

we recently upgraded one of projects to django-filer 3.0.5 and it seems that the sorting logic is doing something funny.

In our old versions everything was sorted correctly, either by name of filename, and was even merged together (alas, when you had some files with a dedicated name and some without, therefore inheriting the label as their filename, everything was correctly sorted still.)

We already skimmed through the code to find some answers but couldn't really wrap our heads around the issue since nothing of importance seems to have been changed..

Is anyone else experiencing the same problems? Is it intentional? Or maybe even some kind of bug?

In either way, we're more than happy to support with code changes, just let us know if this is something which is, indeed, a bug and if not, how we could work around this new ordering mechanism.

Thanks and have a good day.

filipweidemann commented 10 months ago

Edit: we had another look at the diff between versions 2.2.6 & 3.0.5 and spotted something which might be the issue: https://github.com/django-cms/django-filer/blob/2.2.6/filer/admin/folderadmin.py#L346

Here we can see that in the old 2.x.x branch, if no order_by was set as a query param, we would do a .sort() on the folder files.

However, this line no longer exists. Instead, we only do an order_by on the database with a default value of ["file"], which explains our issue.

Was there a reason for the removal of the in-memory sorting?

fsbraun commented 10 months ago

Well spotted! I am not aware of a reason. It can be added back. Would you like to create a PR?

filipweidemann commented 10 months ago

Yeah I'll start working on this tomorrow!