Skip to content

Utilize {% querystring %} template tag #13638

@nijel

Description

@nijel

Describe the problem

The querystring handling pagination currently has quite complex logic in weblate.trans.forms.SearchForm. Most likely it can be fully eliminated by using the {% querystring %} template tag introduced in Django 5.1 (required by Weblate since #13636) see https://docs.djangoproject.com/en/5.1/releases/5.1/#querystring-template-tag.

Describe the solution you would like

I believe using {% querystring %} in the template can replace items, urlencode and reset_offset methods in the form.

Describe alternatives you have considered

No response

Screenshots

No response

Additional context

def items(self):
items = []
# Skip checksum and offset as these change
ignored = {"offset", "checksum"}
for param in sorted(self.cleaned_data):
value = self.cleaned_data[param]
# We don't care about empty values or ignored ones
if value is None or param in ignored:
continue
if isinstance(value, bool):
# Only store true values
if value:
items.append((param, "1"))
elif isinstance(value, int):
# Avoid storing 0 values
if value > 0:
items.append((param, str(value)))
elif isinstance(value, datetime):
# Convert date to string
items.append((param, value.date().isoformat()))
elif isinstance(value, list):
items.extend((param, val) for val in value)
elif isinstance(value, User):
items.append((param, value.username))
elif value:
# It should be a string here
items.append((param, value))
return items
def urlencode(self):
return urlencode(self.items())
def reset_offset(self):
"""
Reset form offset.
This is needed to avoid issues when using the form as the default for
any new search.
"""
data = copy.copy(self.data) # pylint: disable=access-member-before-definition
data["offset"] = "1"
data["checksum"] = ""
self.data = data
return self

Metadata

Metadata

Assignees

No one assigned

    Labels

    Waiting for: DemandLow priority for development. Pull requests welcome. Can be prioritized by sponsorship.enhancementAdding or requesting a new feature.good first issueOpportunity for newcoming contributors.

    Type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions