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

Hide "year in the books" for newly registered users #3207

Merged
merged 9 commits into from
Jan 30, 2024

Conversation

rsk2
Copy link
Contributor

@rsk2 rsk2 commented Jan 9, 2024

Fixes #3187

@rsk2 rsk2 changed the title Issue 3187 Hide "year in the books" for newly registered users Jan 10, 2024
@rsk2 rsk2 marked this pull request as ready for review January 10, 2024 15:24
Copy link
Contributor

@hughrun hughrun left a comment

Choose a reason for hiding this comment

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

This is great! Just a couple of little things to fix and a suggestion to make it a little more specific.

bookwyrm/templates/feed/feed.html Outdated Show resolved Hide resolved
bookwyrm/views/feed.py Outdated Show resolved Hide resolved
bookwyrm/views/feed.py Outdated Show resolved Hide resolved
@bSolt
Copy link
Contributor

bSolt commented Jan 16, 2024

I'd like to help you out and add a test for this. Would that be alright with you? I'll probably try to create a PR that merges into your branch. :)

@@ -66,6 +72,7 @@ def get(self, request, tab, filters_applied=False):
"path": f"/{tab['key']}",
"annual_summary_year": get_annual_summary_year(),
"has_tour": True,
"has_read_throughs": len(readthroughs) > 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are filtering on the date as well, can we name this property "has_summary_read_throughs" instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

That does actually make sense and will avoid potential confusion in future.

I've also just realised the value could simply be len(readthroughs) because 0 is falsy.

@rsk2 do you mind making those two small changes? Then we'll stop bike-shedding this and I'll pull it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, done!

@rsk2
Copy link
Contributor Author

rsk2 commented Jan 18, 2024

I'd like to help you out and add a test for this. Would that be alright with you? I'll probably try to create a PR that merges into your branch. :)

@bSolt Thanks :)

@bSolt
Copy link
Contributor

bSolt commented Jan 18, 2024

Need to get better familiarized with the tests and patterns used here myself, actually. I am also new to the project and I had some trouble with how to test this specific feature. Getting this merged to fix the bug sooner is probably a better priority IMO.

Copy link
Contributor

@bSolt bSolt left a comment

Choose a reason for hiding this comment

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

Let me know if you would like a primer on the tests anyway, but this is looking fine to me for now. Thanks!

@hughrun
Copy link
Contributor

hughrun commented Jan 18, 2024

Need to get better familiarized with the tests and patterns used here myself, actually. I am also new to the project and I had some trouble with how to test this specific feature. Getting this merged to fix the bug sooner is probably a better priority IMO.

I'm planning to add some info to the docs about writing and updating tests, as it can be very confusing for people new to the project and/or Django (as I know from my own experience!) There have been some fairly urgent other things to resolve recently but I'll try to get back to that soon.

@hughrun
Copy link
Contributor

hughrun commented Jan 19, 2024

Hmm, I think I have led you astray here with get_annual_summary_year. I'm looking into it.

@hughrun
Copy link
Contributor

hughrun commented Jan 19, 2024

Ok @rsk2 sorry about this, I gave you some bad advice.

get_annual_summary_year returns this year if the current date is after 15 Dec and before 1 January, or last year if the current date is after 31 Dec but before 16 January. But if it's any other date, it returns None. I momentarily forgot this is the point of this utility function. It was all working because we were looking at this within that period of time. But now time has passed!

So that's why the test is failing: because you can't make a date with a year value of None.

However, you can fix this reasonably easily because we only need to know whether the user has_summary_readthroughs when get_annual_summary_year is True (otherwise the annual summary isn't displayed anyway):

cutoff = (
    date(get_annual_summary_year(), 12, 31)
    if get_annual_summary_year()
    else None
)
readthroughs = (
    models.ReadThrough.objects.filter(
        user=request.user, finish_date__lte=cutoff
    )
    if get_annual_summary_year()
    else []
)

@rsk2
Copy link
Contributor Author

rsk2 commented Jan 24, 2024

@hughrun no worries. Thanks for the fix.

@hughrun hughrun merged commit 21a8570 into bookwyrm-social:main Jan 30, 2024
10 checks passed
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.

"year in the books" should not appear for newly registered users
3 participants