forked from mirrors/bookwyrm
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)
|
updated_date = models.DateTimeField(auto_now=True)
|
||||||
last_active_date = models.DateTimeField(auto_now=True)
|
last_active_date = models.DateTimeField(auto_now=True)
|
||||||
manually_approves_followers = fields.BooleanField(default=False)
|
manually_approves_followers = fields.BooleanField(default=False)
|
||||||
|
show_goal = models.BooleanField(default=True)
|
||||||
|
|
||||||
name_field = "username"
|
name_field = "username"
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{# announcements and system messages #}
|
{# 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 %}
|
{% 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 %}
|
{% include 'snippets/goal_card.html' with year=year %}
|
||||||
<hr>
|
<hr>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block card-footer %}
|
{% block card-footer %}
|
||||||
<div class="card-footer-item is-flex-direction-column">
|
<form class="card-footer-item is-flex-direction-column" method="post" action="{% url 'hide-goal' %}">
|
||||||
<button class="button is-danger is-light is-block set-display" data-id="hide-{{ year }}-reading-goal" data-value="true">{% trans "Dismiss message" %}</button>
|
{% 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>
|
<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 %}
|
{% endblock %}
|
||||||
|
|
|
@ -109,11 +109,13 @@ urlpatterns = [
|
||||||
),
|
),
|
||||||
re_path(r"%s/shelves/?$" % user_path, views.user_shelves_page, name="user-shelves"),
|
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"),
|
re_path(r"%s/lists/?$" % user_path, views.UserLists.as_view(), name="user-lists"),
|
||||||
|
# goals
|
||||||
re_path(
|
re_path(
|
||||||
r"%s/goal/(?P<year>\d{4})/?$" % user_path,
|
r"%s/goal/(?P<year>\d{4})/?$" % user_path,
|
||||||
views.Goal.as_view(),
|
views.Goal.as_view(),
|
||||||
name="user-goal",
|
name="user-goal",
|
||||||
),
|
),
|
||||||
|
re_path(r"^hide-goal/?$", views.hide_goal, name="hide-goal"),
|
||||||
# lists
|
# lists
|
||||||
re_path(r"^list/?$", views.Lists.as_view(), name="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"),
|
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 .feed import DirectMessage, Feed, Replies, Status
|
||||||
from .follow import follow, unfollow
|
from .follow import follow, unfollow
|
||||||
from .follow import accept_follow_request, delete_follow_request
|
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 .import_data import Import, ImportStatus
|
||||||
from .inbox import Inbox
|
from .inbox import Inbox
|
||||||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
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.template.response import TemplateResponse
|
||||||
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 bookwyrm import forms, models
|
from bookwyrm import forms, models
|
||||||
from bookwyrm.status import create_generated_note
|
from bookwyrm.status import create_generated_note
|
||||||
|
@ -65,3 +66,12 @@ class Goal(View):
|
||||||
)
|
)
|
||||||
|
|
||||||
return redirect(request.headers.get("Referer", "/"))
|
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