From 535ff5e6d8ceb8ed68a8105a8a4cd94aa6fcc571 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Aug 2021 12:05:24 -0700 Subject: [PATCH] Handle goal pages for unset years --- bookwyrm/templates/goal.html | 4 ++-- bookwyrm/views/goal.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/goal.html b/bookwyrm/templates/goal.html index 134f419f..b285eec4 100644 --- a/bookwyrm/templates/goal.html +++ b/bookwyrm/templates/goal.html @@ -17,9 +17,9 @@ {% block panel %}
- {% if user == request.user %} + {% now 'Y' as current_year %} + {% if user == request.user and year == current_year %}
- {% now 'Y' as year %}

diff --git a/bookwyrm/views/goal.py b/bookwyrm/views/goal.py index 84091fe3..80b6af3c 100644 --- a/bookwyrm/views/goal.py +++ b/bookwyrm/views/goal.py @@ -4,6 +4,7 @@ from django.http import HttpResponseNotFound from django.shortcuts import redirect from django.template.loader import get_template from django.template.response import TemplateResponse +from django.utils import timezone from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.http import require_POST @@ -26,6 +27,10 @@ class Goal(View): if not goal and user != request.user: return HttpResponseNotFound() + current_year = timezone.now().year + if not goal and year != timezone.now().year: + return redirect('user-goal', username, current_year) + if goal and not goal.visible_to_user(request.user): return HttpResponseNotFound()