diff --git a/invest/template_views.py b/invest/template_views.py index 0a79c6f..0ad5587 100644 --- a/invest/template_views.py +++ b/invest/template_views.py @@ -41,10 +41,15 @@ def dashboard(request): performance = get_cashflow_adjusted_performance() risk = get_risk_summary() recent_transactions = Transaction.objects.select_related('portfolio').order_by('-date', '-created_at')[:30] - invest_tag = Tag.objects.filter(slug__iexact='invest').first() or Tag.objects.filter(name__iexact='invest').first() + invest_tags = list(Tag.objects.filter(slug__in=['invest', 'investment']).order_by('slug')) + invest_tag = next((tag for tag in invest_tags if tag.slug == 'invest'), None) or (invest_tags[0] if invest_tags else None) investment_posts = Post.objects.none() - if invest_tag: - investment_posts = invest_tag.posts.all().order_by('-created_at')[:12] + if invest_tags: + investment_posts = ( + Post.objects.filter(tags__in=invest_tags) + .distinct() + .order_by('-created_at')[:12] + ) return render(request, 'invest/dashboard.html', { 'overview': overview, diff --git a/tests/test_invest_api.py b/tests/test_invest_api.py index dec34ae..f1b2d07 100644 --- a/tests/test_invest_api.py +++ b/tests/test_invest_api.py @@ -203,8 +203,9 @@ def test_performance_chart_data_has_percentage_and_value_modes(): @pytest.mark.django_db -def test_dashboard_links_posts_tagged_invest(client): +def test_dashboard_links_posts_tagged_invest_or_investment(client): invest_tag = Tag.objects.create(name="invest", slug="invest") + investment_tag = Tag.objects.create(name="investment", slug="investment") other_tag = Tag.objects.create(name="life", slug="life") invest_post = Post.objects.create( title="Weekly investment report", @@ -212,6 +213,12 @@ def test_dashboard_links_posts_tagged_invest(client): content="details", ) invest_post.tags.add(invest_tag) + legacy_post = Post.objects.create( + title="Legacy investment report", + summary="Saved before the invest tag standard existed", + content="details", + ) + legacy_post.tags.add(investment_tag) other_post = Post.objects.create(title="Cooking note", summary="not shown", content="details") other_post.tags.add(other_tag) @@ -221,6 +228,8 @@ def test_dashboard_links_posts_tagged_invest(client): content = response.content.decode() assert "Investment Reports" in content assert "Weekly investment report" in content + assert "Legacy investment report" in content assert invest_post.get_absolute_url() in content + assert legacy_post.get_absolute_url() in content assert "Cooking note" not in content assert "View all posts tagged invest" in content