Display books timeline

This commit is contained in:
Mouse Reeve 2021-08-04 17:53:44 -07:00
parent 5a9dbc50da
commit 9d75bc3982
5 changed files with 22 additions and 27 deletions

View file

@ -4,9 +4,9 @@ from django.db.models import signals, Q
from bookwyrm import models from bookwyrm import models
from bookwyrm.redis_store import RedisStore, r from bookwyrm.redis_store import RedisStore, r
from bookwyrm.settings import STREAMS
from bookwyrm.views.helpers import privacy_filter from bookwyrm.views.helpers import privacy_filter
class ActivityStream(RedisStore): class ActivityStream(RedisStore):
"""a category of activity stream (like home, local, federated)""" """a category of activity stream (like home, local, federated)"""
@ -218,13 +218,13 @@ class BooksStream(ActivityStream):
) )
streams = { available_streams = [s["key"] for s in STREAMS]
streams = {k:v for (k, v) in {
"home": HomeStream(), "home": HomeStream(),
"local": LocalStream(), "local": LocalStream(),
"federated": FederatedStream(), "federated": FederatedStream(),
"books": BooksStream(), "books": BooksStream(),
} }.items() if k in available_streams}
@receiver(signals.post_save) @receiver(signals.post_save)
# pylint: disable=unused-argument # pylint: disable=unused-argument

View file

@ -118,7 +118,11 @@ REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379)
REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None) REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None)
MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200)) MAX_STREAM_LENGTH = int(env("MAX_STREAM_LENGTH", 200))
STREAMS = ["home", "books"]
STREAMS = [
{"key": "home", "name": _("Home Timeline"), "shortname": _("Home")},
{"key": "books", "name": _("Books Timeline"), "shortname": _("Books")},
]
# Database # Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases # https://docs.djangoproject.com/en/3.2/ref/settings/#databases

View file

@ -4,35 +4,25 @@
{% block panel %} {% block panel %}
<h1 class="title"> <h1 class="title">
{% if tab == 'home' %} {{ tab.name }}
{% trans "Home Timeline" %}
{% elif tab == 'local' %}
{% trans "Local Timeline" %}
{% else %}
{% trans "Federated Timeline" %}
{% endif %}
</h1> </h1>
<div class="tabs"> <div class="tabs">
<ul> <ul>
<li class="{% if tab == 'home' %}is-active{% endif %}"{% if tab == 'home' %} aria-current="page"{% endif %}> {% for stream in streams %}
<a href="/#feed">{% trans "Home" %}</a> <li class="{% if tab.key == stream.key %}is-active{% endif %}"{% if tab.key == stream.key %} aria-current="page"{% endif %}>
</li> <a href="/{{ stream.key }}#feed">{{ stream.shortname }}</a>
<li class="{% if tab == 'local' %}is-active{% endif %}"{% if tab == 'local' %} aria-current="page"{% endif %}>
<a href="/local#feed">{% trans "Local" %}</a>
</li>
<li class="{% if tab == 'federated' %}is-active{% endif %}"{% if tab == 'federated' %} aria-current="page"{% endif %}>
<a href="/federated#feed">{% trans "Federated" %}</a>
</li> </li>
{% endfor %}
</ul> </ul>
</div> </div>
{# announcements and system messages #} {# announcements and system messages #}
{% if not activities.number > 1 %} {% if not activities.number > 1 %}
<a href="{{ request.path }}" class="transition-y is-hidden notification is-primary is-block" data-poll-wrapper> <a href="{{ request.path }}" class="transition-y is-hidden notification is-primary is-block" data-poll-wrapper>
{% blocktrans %}load <span data-poll="stream/{{ tab }}">0</span> unread status(es){% endblocktrans %} {% blocktrans %}load <span data-poll="stream/{{ tab.key }}">0</span> unread status(es){% endblocktrans %}
</a> </a>
{% if request.user.show_goal and not goal and tab == 'home' %} {% if request.user.show_goal and not goal and tab.key == streams.first.key %}
{% now 'Y' as year %} {% now 'Y' as year %}
<section class="block"> <section class="block">
{% include 'snippets/goal_card.html' with year=year %} {% include 'snippets/goal_card.html' with year=year %}

View file

@ -23,7 +23,7 @@ STATUS_PATH = r"%s/(%s)/(?P<status_id>\d+)" % (USER_PATH, "|".join(status_types)
BOOK_PATH = r"^book/(?P<book_id>\d+)" BOOK_PATH = r"^book/(?P<book_id>\d+)"
STREAMS = "|".join(settings.STREAMS) STREAMS = "|".join(s["key"] for s in settings.STREAMS)
urlpatterns = [ urlpatterns = [
path("admin/", admin.site.urls), path("admin/", admin.site.urls),

View file

@ -23,10 +23,10 @@ class Feed(View):
def get(self, request, tab): def get(self, request, tab):
"""user's homepage with activity feed""" """user's homepage with activity feed"""
if not tab in STREAMS: tab = [s for s in STREAMS if s["key"] == tab]
tab = "home" tab = tab[0] or STREAMS[0]
activities = activitystreams.streams[tab].get_activity_stream(request.user) activities = activitystreams.streams[tab["key"]].get_activity_stream(request.user)
paginated = Paginator(activities, PAGE_LENGTH) paginated = Paginator(activities, PAGE_LENGTH)
suggestions = suggested_users.get_suggestions(request.user) suggestions = suggested_users.get_suggestions(request.user)
@ -38,8 +38,9 @@ class Feed(View):
"activities": paginated.get_page(request.GET.get("page")), "activities": paginated.get_page(request.GET.get("page")),
"suggested_users": suggestions, "suggested_users": suggestions,
"tab": tab, "tab": tab,
"streams": STREAMS,
"goal_form": forms.GoalForm(), "goal_form": forms.GoalForm(),
"path": "/%s" % tab, "path": "/%s" % tab["key"],
}, },
} }
return TemplateResponse(request, "feed/feed.html", data) return TemplateResponse(request, "feed/feed.html", data)