Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add alphabetical sorting as default (fixes #1415) #1416

Merged
merged 9 commits into from
Sep 5, 2023

Conversation

filipweidemann
Copy link
Contributor

@filipweidemann filipweidemann commented Sep 1, 2023

Description

This PR intends to hotfix #1415 by reintroducing the .sort() function on file_qs inside the filer/admin/folderadmin.py logic.

We did not modify any existing tests or added new ones because the function is returning rendered HTML and it is currently unclear how we could test this in an elegant way.

We are also aware that there are better ways to accomplish the same result, e.g. by using Django's QuerySet.annotate and Coalesce DB functions to add a correct sort target to the queryset, so that .order_by() works as intended.

However, we did not want to refactor the existing solution right now but rather hotfix the (currently broken) behaviour.

Related resources

Checklist

  • I have opened this pull request against master
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #workgroup-pr-review on
    Slack to find a “pr review buddy” who is going to review my pull request.

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Patch coverage: 87.50% and project coverage change: +0.20% 🎉

Comparison is base (3940e1c) 75.00% compared to head (07a1e0f) 75.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1416      +/-   ##
==========================================
+ Coverage   75.00%   75.21%   +0.20%     
==========================================
  Files          75       75              
  Lines        3449     3454       +5     
  Branches      554      555       +1     
==========================================
+ Hits         2587     2598      +11     
+ Misses        694      691       -3     
+ Partials      168      165       -3     
Files Changed Coverage Δ
filer/admin/folderadmin.py 75.65% <87.50%> (+0.46%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fsbraun
Copy link
Member

fsbraun commented Sep 1, 2023

@filipweidemann Thanks for creating this PR! Just a quick question: Since you seem to have run black it is hard for me to identify the actual content changes. I assume it's the file_list, its sorting and passing the file_list into the context if it exists. Did I miss anything?

Can you add a test that verifies files are sorted? This feature got lost since a test did not cover it. It would be great if we fixed this for the future.

@filipweidemann
Copy link
Contributor Author

filipweidemann commented Sep 1, 2023

@fsbraun okay good catch, running black was not intentional, I just use it for everything by default and forgot to turn it off. I'll fix that and try to add some tests as well.

And yes, file_list is basically all of the fix, we just have to make sure that it'll only be created when there is no explicit order_by set, so it is wrapped inside a conditional check and only gets passed into the context of the render function when it is explicitly used, else we just use file_qs.

@filipweidemann
Copy link
Contributor Author

Okay @fsbraun, here we go.

I reverted the black formatting and added some tests with the expected sort behaviour.

I really was not happy with using QuerySet objects by default and falling back to a list just to do the sorting inside the Python code.

So I did a quick refactoring and implemented the solution I already talked about inside the PR description.
Currently we are using Coalesce to create a temporary coalesce_sort_field that priorititzes the name field and falls back to the original_filename for all objects without a set name. I used Case to catch the empty strings of the name field since the default behaviour of Coalesce does not interpret empty strings and NoneType equally, but we want to fall back on empty strings as well.

Would be nice if you could have a quick look & maybe kick off the CI again.

If something is still unclear or needs another refactor, let me know.
Thanks.

@filipweidemann filipweidemann changed the title Re-add in-memory sorting of file_qs (fixes #1415) Re-add alphabetical sorting as default (fixes #1415) Sep 1, 2023
Copy link
Member

@fsbraun fsbraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work!

@filipweidemann
Copy link
Contributor Author

Hey, quick question: when will this get merged & released? I don't want to pressure anyone but a quick estimate would be nice because right now I'm thinking about shipping the fork to prod environments to bridge the gap until the release is there.

But I would obviously avoid that if you're saying that this will be released this week or something :)

Thanks!

@fsbraun fsbraun merged commit ac3985d into django-cms:master Sep 5, 2023
23 checks passed
@fsbraun
Copy link
Member

fsbraun commented Sep 5, 2023

@filipweidemann Will release it the next days as 3.0.6. (Merged right now. - I typically do not merge immediately after reviewing to give other community members a chance of looking at it.)

@filipweidemann
Copy link
Contributor Author

Great stuff, that's all I needed to know. :)
Thanks for explaining the workflow and handling the release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants