Opened 3 days ago

Closed 2 days ago

Last modified 2 days ago

#36270 closed New feature (needsinfo)

Allow removal of keys starting with a specific prefix in the querystring template tag.

Reported by: Antoliny Owned by: Antoliny
Component: Template system Version: dev
Severity: Normal Keywords: querystring
Cc: David Feeley, Tom Carrick Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I think it would be great if the querystring template tag also had a feature to remove all queries that start with a specific prefix.
I believe adding a feature that removes all queries starting with a specific prefix would be useful when excluding certain items from filtered query parameters.

class ChangeList:
    ...
    def get_query_string(self, new_params=None, remove=None):
        if new_params is None:
            new_params = {}
        if remove is None:
            remove = []
        p = self.filter_params.copy()
        for r in remove:
            for k in list(p):
                if k.startswith(r):
                    del p[k]
        for k, v in new_params.items():
            if v is None:
                if k in p:
                    del p[k]
            else:
                p[k] = v
        return "?%s" % urlencode(sorted(p.items()), doseq=True)

This feature is actually one of the functionalities provided by the get_query_string method in the ChangeList class, which serves almost the same purpose as querystring template tag.

Change History (3)

comment:1 by Antoliny, 3 days ago

Owner: set to Antoliny
Status: newassigned

comment:2 by Natalia Bidart, 2 days ago

Cc: David Feeley Tom Carrick added
Resolution: needsinfo
Status: assignedclosed

Hello Antoliny, thank you for taking the time to create the ticket!

I can see the use case in the admin, but to be honest, this feels somewhat like an antipattern when considering the querystring template tag in isolation. Before completing the triage, could you share how you envision integrating this feature into the current syntax? I'll mark this as needsinfo for now, but please reopen it once you can provide those details.

Thank you again!

comment:3 by Natalia Bidart, 2 days ago

Summary: Remove queries starting with a specific prefix from the querystring template tag.Allow removal of keys starting with a specific prefix in the querystring template tag.
Note: See TracTickets for help on using tickets.
Back to Top