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">
|
<section class="block">
|
||||||
<h1 class="title">{{ year }} Reading Progress</h1>
|
<h1 class="title">{{ year }} Reading Progress</h1>
|
||||||
{% if not goal and user == request.user %}
|
{% if user == request.user %}
|
||||||
{% now 'Y' as year %}
|
<div class="block">
|
||||||
<article class="card">
|
{% if goal %}
|
||||||
<header class="card-header">
|
<input type="radio" class="toggle-control" name="edit-goal" id="hide-edit-goal" checked>
|
||||||
<h2 class="card-header-title has-background-primary has-text-white">
|
<div class="toggle-content hidden">
|
||||||
<span class="icon icon-book is-size-3 mr-2" aria-hidden="true"></span> {{ year }} reading goal
|
{% include 'snippets/toggle/toggle_button.html' with text="Edit goal" controls_text="show-edit-goal" %}
|
||||||
</h2>
|
</div>
|
||||||
</header>
|
{% endif %}
|
||||||
<section class="card-content content">
|
</div>
|
||||||
<p>Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.</p>
|
<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' %}
|
{% include 'snippets/goal_form.html' with goal=goal year=year %}
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
{% elif not goal and user != request.user %}
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if not goal and user != request.user %}
|
||||||
<p>{{ user.display_name }} hasn't set a reading goal for {{ year }}.</p>
|
<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 %}
|
{% include 'snippets/goal_progress.html' with goal=goal %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<form method="post" name="goal" action="{{ request.user.local_path }}/goal/{{ year }}">
|
<form method="post" name="goal" action="{{ request.user.local_path }}/goal/{{ year }}">
|
||||||
{% csrf_token %}
|
{% 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 }}">
|
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
<label class="label" for="id_goal">Reading goal:</label>
|
<label class="label" for="id_goal">Reading goal:</label>
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control">
|
<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>
|
</div>
|
||||||
<p class="button is-static">books</p>
|
<p class="button is-static">books</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<label class="label"><p class="mb-2">Goal privacy:</p>
|
<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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -27,5 +27,8 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="button is-link">Set goal</button>
|
<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>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -40,6 +40,17 @@
|
||||||
<small><a href="{{ user.local_path }}/shelves">See all {{ shelf_count }} shelves</a></small>
|
<small><a href="{{ user.local_path }}/shelves">See all {{ shelf_count }} shelves</a></small>
|
||||||
</div>
|
</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>
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<h2 class="title">User Activity</h2>
|
<h2 class="title">User Activity</h2>
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import forms, models
|
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
|
# pylint: disable= no-self-use
|
||||||
|
@ -24,10 +24,8 @@ class Goal(View):
|
||||||
if not goal and user != request.user:
|
if not goal and user != request.user:
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
if goal and user != request.user:
|
if goal and not object_visible_to_user(request.user, goal):
|
||||||
if goal.privacy == 'direct' or \
|
return HttpResponseNotFound()
|
||||||
(goal.privacy == 'followers' and not follower):
|
|
||||||
return HttpResponseNotFound()
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'title': '%s\'s %d Reading' % (user.display_name, year),
|
'title': '%s\'s %d Reading' % (user.display_name, year),
|
||||||
|
|
|
@ -34,16 +34,17 @@ def is_bookworm_request(request):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def status_visible_to_user(viewer, status):
|
def object_visible_to_user(viewer, obj):
|
||||||
''' is a user authorized to view a status? '''
|
''' is a user authorized to view an object? '''
|
||||||
if viewer == status.user or status.privacy in ['public', 'unlisted']:
|
if viewer == obj.user or obj.privacy in ['public', 'unlisted']:
|
||||||
return True
|
return True
|
||||||
if status.privacy == 'followers' and \
|
if obj.privacy == 'followers' and \
|
||||||
status.user.followers.filter(id=viewer.id).first():
|
obj.user.followers.filter(id=viewer.id).first():
|
||||||
return True
|
|
||||||
if status.privacy == 'direct' and \
|
|
||||||
status.mention_users.filter(id=viewer.id).first():
|
|
||||||
return True
|
return True
|
||||||
|
if isinstance(obj, models.Status):
|
||||||
|
if obj.privacy == 'direct' and \
|
||||||
|
obj.mention_users.filter(id=viewer.id).first():
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_activity_feed(
|
def get_activity_feed(
|
||||||
|
|
|
@ -16,7 +16,7 @@ from bookwyrm.settings import DOMAIN
|
||||||
from bookwyrm.status import create_notification, delete_status
|
from bookwyrm.status import create_notification, delete_status
|
||||||
from bookwyrm.utils import regex
|
from bookwyrm.utils import regex
|
||||||
from .helpers import get_user_from_username, handle_remote_webfinger
|
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
|
# pylint: disable= no-self-use
|
||||||
|
@ -35,7 +35,7 @@ class Status(View):
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
# make sure the user is authorized to see the status
|
# 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()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
|
|
|
@ -9,6 +9,7 @@ from django.core.paginator import Paginator
|
||||||
from django.http import HttpResponseNotFound
|
from django.http import HttpResponseNotFound
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
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
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm.broadcast import broadcast
|
from bookwyrm.broadcast import broadcast
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
from .helpers import get_activity_feed, get_user_from_username, is_api_request
|
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
|
# pylint: disable= no-self-use
|
||||||
|
@ -70,6 +72,10 @@ class User(View):
|
||||||
queryset=models.Status.objects.filter(user=user)
|
queryset=models.Status.objects.filter(user=user)
|
||||||
)
|
)
|
||||||
paginated = Paginator(activities, PAGE_LENGTH)
|
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 = {
|
data = {
|
||||||
'title': user.name,
|
'title': user.name,
|
||||||
'user': user,
|
'user': user,
|
||||||
|
@ -77,6 +83,7 @@ class User(View):
|
||||||
'shelves': shelf_preview,
|
'shelves': shelf_preview,
|
||||||
'shelf_count': shelves.count(),
|
'shelf_count': shelves.count(),
|
||||||
'activities': paginated.page(page),
|
'activities': paginated.page(page),
|
||||||
|
'goal': goal,
|
||||||
}
|
}
|
||||||
|
|
||||||
return TemplateResponse(request, 'user.html', data)
|
return TemplateResponse(request, 'user.html', data)
|
||||||
|
|
Loading…
Reference in a new issue