diff --git a/bookwyrm/templates/goal.html b/bookwyrm/templates/goal.html index 79d694de5..c02a5474d 100644 --- a/bookwyrm/templates/goal.html +++ b/bookwyrm/templates/goal.html @@ -3,23 +3,40 @@

{{ year }} Reading Progress

- {% if not goal and user == request.user %} - {% now 'Y' as year %} -
-
-

- {{ year }} reading goal -

-
-
-

Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.

+ {% if user == request.user %} +
+ {% if goal %} + + + {% endif %} +
+
+ +
+ {% now 'Y' as year %} +
+
+

+ {{ year }} reading goal +

+
+
+

Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.

- {% include 'snippets/goal_form.html' %} -
-
- {% elif not goal and user != request.user %} + {% include 'snippets/goal_form.html' with goal=goal year=year %} +
+
+ + + {% endif %} + + {% if not goal and user != request.user %}

{{ user.display_name }} hasn't set a reading goal for {{ year }}.

- {% else %} + {% endif %} + + {% if goal %} {% include 'snippets/goal_progress.html' with goal=goal %} {% endif %}
diff --git a/bookwyrm/templates/snippets/goal_form.html b/bookwyrm/templates/snippets/goal_form.html index 2e23aedd2..b856b8796 100644 --- a/bookwyrm/templates/snippets/goal_form.html +++ b/bookwyrm/templates/snippets/goal_form.html @@ -1,6 +1,6 @@
{% csrf_token %} - +
@@ -8,7 +8,7 @@
- +

books

@@ -16,7 +16,7 @@
@@ -27,5 +27,8 @@

+ {% if goal %} + {% include 'snippets/toggle/toggle_button.html' with text="Cancel" controls_text="hide-edit-goal" %} + {% endif %}

diff --git a/bookwyrm/templates/user.html b/bookwyrm/templates/user.html index ef5552c3c..a41623a8a 100644 --- a/bookwyrm/templates/user.html +++ b/bookwyrm/templates/user.html @@ -40,6 +40,17 @@ See all {{ shelf_count }} shelves +{% if goal %} +
+

{% now 'Y' %} Reading Goal

+ {% include 'snippets/goal_progress.html' with goal=goal %} +
+{% elif user == request.user %} +
+

Set a reading goal for {% now 'Y' %}

+
+{% endif %} +

User Activity

diff --git a/bookwyrm/views/goal.py b/bookwyrm/views/goal.py index 4252af078..fa919b76f 100644 --- a/bookwyrm/views/goal.py +++ b/bookwyrm/views/goal.py @@ -7,7 +7,7 @@ from django.utils.decorators import method_decorator from django.views import View from bookwyrm import forms, models -from .helpers import get_user_from_username +from .helpers import get_user_from_username, object_visible_to_user # pylint: disable= no-self-use @@ -24,10 +24,8 @@ class Goal(View): if not goal and user != request.user: return redirect('/') - if goal and user != request.user: - if goal.privacy == 'direct' or \ - (goal.privacy == 'followers' and not follower): - return HttpResponseNotFound() + if goal and not object_visible_to_user(request.user, goal): + return HttpResponseNotFound() data = { 'title': '%s\'s %d Reading' % (user.display_name, year), diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index 3036e5683..354b8bf62 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -34,16 +34,17 @@ def is_bookworm_request(request): return True -def status_visible_to_user(viewer, status): - ''' is a user authorized to view a status? ''' - if viewer == status.user or status.privacy in ['public', 'unlisted']: +def object_visible_to_user(viewer, obj): + ''' is a user authorized to view an object? ''' + if viewer == obj.user or obj.privacy in ['public', 'unlisted']: return True - if status.privacy == 'followers' and \ - status.user.followers.filter(id=viewer.id).first(): - return True - if status.privacy == 'direct' and \ - status.mention_users.filter(id=viewer.id).first(): + if obj.privacy == 'followers' and \ + obj.user.followers.filter(id=viewer.id).first(): return True + if isinstance(obj, models.Status): + if obj.privacy == 'direct' and \ + obj.mention_users.filter(id=viewer.id).first(): + return True return False def get_activity_feed( diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py index 39cd60775..c1f3486fb 100644 --- a/bookwyrm/views/status.py +++ b/bookwyrm/views/status.py @@ -16,7 +16,7 @@ from bookwyrm.settings import DOMAIN from bookwyrm.status import create_notification, delete_status from bookwyrm.utils import regex from .helpers import get_user_from_username, handle_remote_webfinger -from .helpers import is_api_request, is_bookworm_request, status_visible_to_user +from .helpers import is_api_request, is_bookworm_request, object_visible_to_user # pylint: disable= no-self-use @@ -35,7 +35,7 @@ class Status(View): return HttpResponseNotFound() # make sure the user is authorized to see the status - if not status_visible_to_user(request.user, status): + if not object_visible_to_user(request.user, status): return HttpResponseNotFound() if is_api_request(request): diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 9a22c47cc..aeec18646 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -9,6 +9,7 @@ from django.core.paginator import Paginator from django.http import HttpResponseNotFound from django.shortcuts import redirect from django.template.response import TemplateResponse +from django.utils import timezone from django.utils.decorators import method_decorator from django.views import View @@ -17,6 +18,7 @@ from bookwyrm.activitypub import ActivitypubResponse from bookwyrm.broadcast import broadcast from bookwyrm.settings import PAGE_LENGTH from .helpers import get_activity_feed, get_user_from_username, is_api_request +from .helpers import object_visible_to_user # pylint: disable= no-self-use @@ -70,6 +72,10 @@ class User(View): queryset=models.Status.objects.filter(user=user) ) paginated = Paginator(activities, PAGE_LENGTH) + goal = models.AnnualGoal.objects.filter( + user=user, year=timezone.now().year).first() + if not object_visible_to_user(request.user, goal): + goal = None data = { 'title': user.name, 'user': user, @@ -77,6 +83,7 @@ class User(View): 'shelves': shelf_preview, 'shelf_count': shelves.count(), 'activities': paginated.page(page), + 'goal': goal, } return TemplateResponse(request, 'user.html', data)