mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Hide goal using database field instead of localstorage
This commit is contained in:
parent
284366e46f
commit
9a20b5dbd5
7 changed files with 38 additions and 6 deletions
18
bookwyrm/migrations/0052_user_show_goal.py
Normal file
18
bookwyrm/migrations/0052_user_show_goal.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.7 on 2021-03-18 15:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bookwyrm', '0051_auto_20210316_1950'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='show_goal',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
|
@ -102,6 +102,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
|
|||
updated_date = models.DateTimeField(auto_now=True)
|
||||
last_active_date = models.DateTimeField(auto_now=True)
|
||||
manually_approves_followers = fields.BooleanField(default=False)
|
||||
show_goal = models.BooleanField(default=True)
|
||||
|
||||
name_field = "username"
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
</div>
|
||||
|
||||
{# announcements and system messages #}
|
||||
{% if not goal and tab == 'home' %}
|
||||
{% if request.user.show_goal and not goal and tab == 'home' %}
|
||||
{% now 'Y' as year %}
|
||||
<section class="block hidden" aria-title="{% trans 'Announcements' %}" data-hide="hide-{{ year }}-reading-goal">
|
||||
<section class="block" aria-title="{% trans 'Announcements' %}">
|
||||
{% include 'snippets/goal_card.html' with year=year %}
|
||||
<hr>
|
||||
</section>
|
||||
|
|
|
@ -17,8 +17,9 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block card-footer %}
|
||||
<div class="card-footer-item is-flex-direction-column">
|
||||
<button class="button is-danger is-light is-block set-display" data-id="hide-{{ year }}-reading-goal" data-value="true">{% trans "Dismiss message" %}</button>
|
||||
<form class="card-footer-item is-flex-direction-column" method="post" action="{% url 'hide-goal' %}">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="button is-danger is-light is-block set-display" >{% trans "Dismiss message" %}</button>
|
||||
<p class="help">{% blocktrans with path=request.user.local_path %}You can set or change your reading goal any time from your <a href="{{ path }}">profile page</a>{% endblocktrans %}</p>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -109,11 +109,13 @@ urlpatterns = [
|
|||
),
|
||||
re_path(r"%s/shelves/?$" % user_path, views.user_shelves_page, name="user-shelves"),
|
||||
re_path(r"%s/lists/?$" % user_path, views.UserLists.as_view(), name="user-lists"),
|
||||
# goals
|
||||
re_path(
|
||||
r"%s/goal/(?P<year>\d{4})/?$" % user_path,
|
||||
views.Goal.as_view(),
|
||||
name="user-goal",
|
||||
),
|
||||
re_path(r"^hide-goal/?$", views.hide_goal, name="hide-goal"),
|
||||
# lists
|
||||
re_path(r"^list/?$", views.Lists.as_view(), name="lists"),
|
||||
re_path(r"^list/(?P<list_id>\d+)(.json)?/?$", views.List.as_view(), name="list"),
|
||||
|
|
|
@ -9,7 +9,7 @@ from .federation import Federation
|
|||
from .feed import DirectMessage, Feed, Replies, Status
|
||||
from .follow import follow, unfollow
|
||||
from .follow import accept_follow_request, delete_follow_request
|
||||
from .goal import Goal
|
||||
from .goal import Goal, hide_goal
|
||||
from .import_data import Import, ImportStatus
|
||||
from .inbox import Inbox
|
||||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.template.loader import get_template
|
|||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from bookwyrm import forms, models
|
||||
from bookwyrm.status import create_generated_note
|
||||
|
@ -65,3 +66,12 @@ class Goal(View):
|
|||
)
|
||||
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
||||
|
||||
@require_POST
|
||||
@login_required
|
||||
def hide_goal(request):
|
||||
""" don't keep bugging people to set a goal """
|
||||
request.user.show_goal = False
|
||||
request.user.save(broadcast=False)
|
||||
return redirect(request.headers.get("Referer", "/"))
|
||||
|
|
Loading…
Reference in a new issue