forked from mirrors/bookwyrm
Edit goal
This commit is contained in:
parent
112b9f9332
commit
f3f6592e72
7 changed files with 70 additions and 33 deletions
|
@ -3,23 +3,40 @@
|
|||
|
||||
<section class="block">
|
||||
<h1 class="title">{{ year }} Reading Progress</h1>
|
||||
{% if not goal and user == request.user %}
|
||||
{% now 'Y' as year %}
|
||||
<article class="card">
|
||||
<header class="card-header">
|
||||
<h2 class="card-header-title has-background-primary has-text-white">
|
||||
<span class="icon icon-book is-size-3 mr-2" aria-hidden="true"></span> {{ year }} reading goal
|
||||
</h2>
|
||||
</header>
|
||||
<section class="card-content content">
|
||||
<p>Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.</p>
|
||||
{% if user == request.user %}
|
||||
<div class="block">
|
||||
{% if goal %}
|
||||
<input type="radio" class="toggle-control" name="edit-goal" id="hide-edit-goal" checked>
|
||||
<div class="toggle-content hidden">
|
||||
{% include 'snippets/toggle/toggle_button.html' with text="Edit goal" controls_text="show-edit-goal" %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="block">
|
||||
<input type="radio" class="toggle-control" name="edit-goal" id="show-edit-goal">
|
||||
<div class="toggle-content{% if goal %} hidden{% endif %}">
|
||||
{% now 'Y' as year %}
|
||||
<article class="card">
|
||||
<header class="card-header">
|
||||
<h2 class="card-header-title has-background-primary has-text-white">
|
||||
<span class="icon icon-book is-size-3 mr-2" aria-hidden="true"></span> {{ year }} reading goal
|
||||
</h2>
|
||||
</header>
|
||||
<section class="card-content content">
|
||||
<p>Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.</p>
|
||||
|
||||
{% include 'snippets/goal_form.html' %}
|
||||
</section>
|
||||
</article>
|
||||
{% elif not goal and user != request.user %}
|
||||
{% include 'snippets/goal_form.html' with goal=goal year=year %}
|
||||
</section>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not goal and user != request.user %}
|
||||
<p>{{ user.display_name }} hasn't set a reading goal for {{ year }}.</p>
|
||||
{% else %}
|
||||
{% endif %}
|
||||
|
||||
{% if goal %}
|
||||
{% include 'snippets/goal_progress.html' with goal=goal %}
|
||||
{% endif %}
|
||||
</section>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<form method="post" name="goal" action="{{ request.user.local_path }}/goal/{{ year }}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="year" value="{{ year }}">
|
||||
<input type="hidden" name="year" value="{% if goal %}{{ goal.year }}{% else %}{{ year }}{% endif %}">
|
||||
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||
|
||||
<div class="columns">
|
||||
|
@ -8,7 +8,7 @@
|
|||
<label class="label" for="id_goal">Reading goal:</label>
|
||||
<div class="field has-addons">
|
||||
<div class="control">
|
||||
<input type="number" class="input" name="goal" id="id_goal" value="12">
|
||||
<input type="number" class="input" name="goal" id="id_goal" value="{% if goal %}{{ goal.goal }}{% else %}12{% endif %}">
|
||||
</div>
|
||||
<p class="button is-static">books</p>
|
||||
</div>
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
<div class="column">
|
||||
<label class="label"><p class="mb-2">Goal privacy:</p>
|
||||
{% include 'snippets/privacy_select.html' with no_label=True %}
|
||||
{% include 'snippets/privacy_select.html' with no_label=True current=goal.privacy %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,5 +27,8 @@
|
|||
|
||||
<p>
|
||||
<button type="submit" class="button is-link">Set goal</button>
|
||||
{% if goal %}
|
||||
{% include 'snippets/toggle/toggle_button.html' with text="Cancel" controls_text="hide-edit-goal" %}
|
||||
{% endif %}
|
||||
</p>
|
||||
</form>
|
||||
|
|
|
@ -40,6 +40,17 @@
|
|||
<small><a href="{{ user.local_path }}/shelves">See all {{ shelf_count }} shelves</a></small>
|
||||
</div>
|
||||
|
||||
{% if goal %}
|
||||
<div class="block">
|
||||
<h2 class="title">{% now 'Y' %} Reading Goal</h2>
|
||||
{% include 'snippets/goal_progress.html' with goal=goal %}
|
||||
</div>
|
||||
{% elif user == request.user %}
|
||||
<div class="block">
|
||||
<h2 class="title is-4"><a href="{{ user.local_path }}/goal/{% now 'Y' %}">Set a reading goal for {% now 'Y' %}</a></h2>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
<div class="block">
|
||||
<h2 class="title">User Activity</h2>
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue