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

💻 Preselect language filter based on user language #6044

Merged
merged 8 commits into from
Dec 19, 2024
Merged

Conversation

boryanagoncharenko
Copy link
Collaborator

This PR makes the following changes:

  • when a user opens the public adventures page, the user language is used to preset the language filter, so that we show language-relevant adventures. Note that if there are no adventures for the language of the user, no language filter is set, so that we display some adventures rather than no adventures at all.
  • public adventures which do not have a language property set used to be displayed as if they are in the language of the current user. Now this is changed, so that if a language filter is applied, only adventures with specified language are displayed. Language-less adventures appear only when there is no language filter applied.

Fixes #5368

How to test
Ensure that you have public adventures for at least 2 languages (e.g. English and Dutch) and also adventures that do not have language set.

  • If the user's preferred language is set to Dutch, ensure that opening the public adventures page will have the Dutch language filter pre-selected and only Dutch adventures are displayed. If the user changes the language filter to English, then only English adventures should be displayed. If the user clears the language filter, then the all adventures should be displayed: English, Dutch and the ones without a language.
  • If the user's preferred language is set to anything other than English or Dutch, opening the public adventures page should not preset a language filter. Thus, all adventures should be displayed: English, Dutch and language-less.
  • Editing and cloning adventures should work. If changed or cloned adventure does not have language set, the language of the user should be set as a property of the adventure.

Please note that clearing the filter on tags is not possible right now. This seems like a bug which is not in the scope of the current task and perhaps should be addressed in the future. However, it will impact your testing.

@@ -37,10 +37,12 @@
hx-target="#public_adventures"
value="">{{_('select_lang')}}</option>
{% for lang in available_languages %}
{% if lang %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it be nicer to ensure that a None doesn't make it into this array in the Python code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed, it is filtered

self.available_tags.update(adv_tags)
def update_lang_filter(self, adventures):
langs = [a['language'] for a in adventures if a.get('language')]
self.available_languages = set(langs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It scares me a little that these seem to be instance members that go into a Flask template.

At best, they get overwritten on every request, and them being instance members is not necessary.

At worst, we write code expecting them to persist between requests and (because it works on a local dev setup) we ship that code and now the code behaves basically randomly on the production server.

Are we sure that these won't pollute into different requests?

Copy link
Contributor

mergify bot commented Dec 18, 2024

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

Copy link
Contributor

mergify bot commented Dec 19, 2024

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit dcf4b36 into main Dec 19, 2024
11 checks passed
@mergify mergify bot deleted the adventures_5368 branch December 19, 2024 01:25
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.

💻Public adventures, select the language automatically?
3 participants