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

Utilize {% querystring %} template tag #13638

Open
nijel opened this issue Jan 23, 2025 · 1 comment
Open

Utilize {% querystring %} template tag #13638

nijel opened this issue Jan 23, 2025 · 1 comment
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.

Comments

@nijel
Copy link
Member

nijel commented Jan 23, 2025

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

@nijel nijel added enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed. labels Jan 23, 2025
Copy link

This issue seems to be a good fit for newbie contributors. You are welcome to contribute to Weblate! Don't hesitate to ask any questions you would have while implementing this.

You can learn about how to get started in our contributors documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding or requesting a new feature. good first issue Opportunity for newcoming contributors. hacktoberfest This is suitable for Hacktoberfest. Don’t try to spam. help wanted Extra attention is needed.
Projects
None yet
Development

No branches or pull requests

1 participant