Skip to content

Add case_sensitive parameter for groupby() filter #1463

@wombatonfire

Description

@wombatonfire

groupby() filter performs auto sorting under the hood, and it should support specifying case sensitivity for the sort order, the same way sort() filter does.

Current groupby() implementation always performs case-sensitive sorting under the hood, which makes it inflexible, and behave inconsistently with how the sort() filter works (case-insensitive by default). When used in the same template for the same dataset, groupby() and sort() filters produce different sort order on the same fields.

I think, I would personally prefer to not have any implicit sorting in groupby(), and chain it with sort() explicitly, but I do understand that auto sorting was, probably, added to groupby() for convenience.

Implementing an option to control case sensitivity seems to be pretty straightforward:

  • A case_sensitive parameter can be added to do_groupby() function, similar to do_sort().
  • make_attrgetter() inside do_groupby() should be called with postprocess=ignore_case if case_sensitive==False.

If this feature request looks reasonable, I should be able to submit a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions