forked from mirrors/bookwyrm
Merge pull request #1249 from bookwyrm-social/goal-page
Handle goal pages for unset years
This commit is contained in:
commit
708a813905
3 changed files with 16 additions and 10 deletions
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
{% block panel %}
|
{% block panel %}
|
||||||
<section class="block">
|
<section class="block">
|
||||||
{% if user == request.user %}
|
{% now 'Y' as current_year %}
|
||||||
|
{% if user == request.user and year == current_year %}
|
||||||
<div class="block">
|
<div class="block">
|
||||||
{% now 'Y' as year %}
|
|
||||||
<section class="card {% if goal %}is-hidden{% endif %}" id="show-edit-goal">
|
<section class="card {% if goal %}is-hidden{% endif %}" id="show-edit-goal">
|
||||||
<header class="card-header">
|
<header class="card-header">
|
||||||
<h2 class="card-header-title has-background-primary has-text-white" tabindex="0" id="edit-form-header">
|
<h2 class="card-header-title has-background-primary has-text-white" tabindex="0" id="edit-form-header">
|
||||||
|
|
|
@ -39,6 +39,7 @@ class GoalViews(TestCase):
|
||||||
)
|
)
|
||||||
self.anonymous_user = AnonymousUser
|
self.anonymous_user = AnonymousUser
|
||||||
self.anonymous_user.is_authenticated = False
|
self.anonymous_user.is_authenticated = False
|
||||||
|
self.year = timezone.now().year
|
||||||
models.SiteSettings.objects.create()
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
def test_goal_page_no_goal(self):
|
def test_goal_page_no_goal(self):
|
||||||
|
@ -47,7 +48,7 @@ class GoalViews(TestCase):
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.rat
|
request.user = self.rat
|
||||||
|
|
||||||
result = view(request, self.local_user.localname, 2020)
|
result = view(request, self.local_user.localname, self.year)
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
def test_goal_page_no_goal_self(self):
|
def test_goal_page_no_goal_self(self):
|
||||||
|
@ -56,7 +57,7 @@ class GoalViews(TestCase):
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
|
|
||||||
result = view(request, self.local_user.localname, 2020)
|
result = view(request, self.local_user.localname, self.year)
|
||||||
result.render()
|
result.render()
|
||||||
self.assertIsInstance(result, TemplateResponse)
|
self.assertIsInstance(result, TemplateResponse)
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ class GoalViews(TestCase):
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.anonymous_user
|
request.user = self.anonymous_user
|
||||||
|
|
||||||
result = view(request, self.local_user.localname, 2020)
|
result = view(request, self.local_user.localname, self.year)
|
||||||
self.assertEqual(result.status_code, 302)
|
self.assertEqual(result.status_code, 302)
|
||||||
|
|
||||||
def test_goal_page_public(self):
|
def test_goal_page_public(self):
|
||||||
|
@ -94,13 +95,13 @@ class GoalViews(TestCase):
|
||||||
def test_goal_page_private(self):
|
def test_goal_page_private(self):
|
||||||
"""view a user's private goal"""
|
"""view a user's private goal"""
|
||||||
models.AnnualGoal.objects.create(
|
models.AnnualGoal.objects.create(
|
||||||
user=self.local_user, year=2020, goal=15, privacy="followers"
|
user=self.local_user, year=self.year, goal=15, privacy="followers"
|
||||||
)
|
)
|
||||||
view = views.Goal.as_view()
|
view = views.Goal.as_view()
|
||||||
request = self.factory.get("")
|
request = self.factory.get("")
|
||||||
request.user = self.rat
|
request.user = self.rat
|
||||||
|
|
||||||
result = view(request, self.local_user.localname, 2020)
|
result = view(request, self.local_user.localname, self.year)
|
||||||
self.assertEqual(result.status_code, 404)
|
self.assertEqual(result.status_code, 404)
|
||||||
|
|
||||||
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
@patch("bookwyrm.activitystreams.ActivityStream.add_status")
|
||||||
|
@ -112,19 +113,19 @@ class GoalViews(TestCase):
|
||||||
{
|
{
|
||||||
"user": self.local_user.id,
|
"user": self.local_user.id,
|
||||||
"goal": 10,
|
"goal": 10,
|
||||||
"year": 2020,
|
"year": self.year,
|
||||||
"privacy": "unlisted",
|
"privacy": "unlisted",
|
||||||
"post-status": True,
|
"post-status": True,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"):
|
||||||
view(request, self.local_user.localname, 2020)
|
view(request, self.local_user.localname, self.year)
|
||||||
|
|
||||||
goal = models.AnnualGoal.objects.get()
|
goal = models.AnnualGoal.objects.get()
|
||||||
self.assertEqual(goal.user, self.local_user)
|
self.assertEqual(goal.user, self.local_user)
|
||||||
self.assertEqual(goal.goal, 10)
|
self.assertEqual(goal.goal, 10)
|
||||||
self.assertEqual(goal.year, 2020)
|
self.assertEqual(goal.year, self.year)
|
||||||
self.assertEqual(goal.privacy, "unlisted")
|
self.assertEqual(goal.privacy, "unlisted")
|
||||||
|
|
||||||
status = models.GeneratedNote.objects.get()
|
status = models.GeneratedNote.objects.get()
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.http import HttpResponseNotFound
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
@ -26,6 +27,10 @@ class Goal(View):
|
||||||
if not goal and user != request.user:
|
if not goal and user != request.user:
|
||||||
return HttpResponseNotFound()
|
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):
|
if goal and not goal.visible_to_user(request.user):
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue