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

Adds filtering by post author's native languages to post list (#140) #421

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alexcjwei
Copy link
Contributor

Adds additional dropdown to filter posts by the author's native language with test.

  • Adds another select option with new variables for author native languages, modifying data-link accordingly
  • Shows counts of posts that would be shown by the filter, same as before

Looking for any feedback, from code cleanliness and best practices, better ideas for logos for clarity, and suggestions to improve mobile if any.

Examples from local browser below:
Screenshot 2024-01-17 at 4 53 01 PM

Screenshot 2024-01-17 at 4 53 39 PM Screenshot 2024-01-17 at 4 56 13 PM

@alexcjwei alexcjwei changed the title Adds filtering by post author's native languages to post list Adds filtering by post author's native languages to post list (#140) Jan 18, 2024
langcorrect/posts/views.py Outdated Show resolved Hide resolved
Copy link
Contributor

@danielzeljko danielzeljko Jan 18, 2024

Choose a reason for hiding this comment

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

Recording.2024-01-18.150627.mp4

We have a couple of issues:

Posts do not filter correctly when lang_code is None

See video.

http://127.0.0.1:8000/journals/?mode=teach&author_native_lang_code=ja&lang_code=None

    def get_lang_code(self):
        return self.request.GET.get("lang_code", None)

What's happening here is that language code will evaluate to the string "None" which is a truthy value. So, we will either need to update the conditionals or explicitly check for this and return None:

    def get_lang_code(self):
       code = self.request.GET.get("lang_code", None)
       if code == "None"
         return None
       return code

I would also look into your get_author_native_lang_code method.

Incorrect post counts when both the native language and language codes are selected

See video. The count is displayed is 12, but the actual count is 14.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue comes from how we're setting the query params from the frontend. In get_context_data, we return the result of these getters, which in Python are None. These get passed back as selected_lang_code, which we use to create the url in post_list.html, and end up making the url look like ?mode=teach&author_native_lang_code=all&lang_code=None If we modify the getters to just default to the value "all", then we won't receive "None" in the query params.

    def get_lang_code(self):  
        return self.request.GET.get("lang_code", "all") 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to look into incorrect post counts, should look for discrepancy btwn posts/views.py and posts/helpers.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, right now the native language counts are a subset of the original language code (i.e it should always be less than or equal to the count of the original language code). This make it a little confusing if you try to set the original language code after first setting the native language code. Not sure what the best solution is -- maybe for consistency, the count should always reflect the posts that would be shown as a result of applying that filter? In which case we'd have to update the original one to take into account the native language filter. Do you agree?

Screenshot 2024-01-18 at 3 01 49 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my observations, the native speaking language filter seems to always be off by one (lower)

Copy link
Contributor

Choose a reason for hiding this comment

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

... If we modify the getters to just default to the value "all", then we won't receive "None" in the query params.

I like your solution 💯

Not sure what the best solution is -- maybe for consistency, the count should always reflect the posts that would be shown as a result of applying that filter? In which case we'd have to update the original one to take into account the native language filter. Do you agree?

Good point -- let's make it consistent. I'm not sure where else that function is currently being used, so we would need to make sure it doesn't break elsewhere.

langcorrect/posts/views.py Outdated Show resolved Hide resolved
langcorrect/static/js/post_list.js Outdated Show resolved Hide resolved
langcorrect/posts/helpers.py Outdated Show resolved Hide resolved
@danielzeljko
Copy link
Contributor

danielzeljko commented Jan 18, 2024

Let me get back to you about the logo (icon) and mobile responsiveness!

There's a PR (#403) about setting up mock data. You can check it out and run the python manage.py setup_mock_data command to generate some mock data. You will need to delete the db and recreate an empty one. The command will run the migrations.

@danielzeljko danielzeljko self-requested a review January 19, 2024 09:17
@danielzeljko
Copy link
Contributor

@alexcjwei I'm just checking in. Do you have any questions or need any help?

@alexcjwei
Copy link
Contributor Author

Screenshot 2024-02-10 at 2 45 22 PM

Not entirely sure what the most logical way to express the number of posts is.

I think a better way might be a simple toggle that filters for posts by users that are of a "language match", which is shown by the handshake?

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.

2 participants