From 9d75bc39827d94319d50519e57890c03a677cb11 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 4 Aug 2021 17:53:44 -0700 Subject: [PATCH] Display books timeline --- bookwyrm/activitystreams.py | 8 ++++---- bookwyrm/settings.py | 6 +++++- bookwyrm/templates/feed/feed.html | 24 +++++++----------------- bookwyrm/urls.py | 2 +- bookwyrm/views/feed.py | 9 +++++---- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py index 4e464b3cb..2f1555384 100644 --- a/bookwyrm/activitystreams.py +++ b/bookwyrm/activitystreams.py @@ -4,9 +4,9 @@ from django.db.models import signals, Q from bookwyrm import models from bookwyrm.redis_store import RedisStore, r +from bookwyrm.settings import STREAMS from bookwyrm.views.helpers import privacy_filter - class ActivityStream(RedisStore): """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(), "local": LocalStream(), "federated": FederatedStream(), "books": BooksStream(), -} - +}.items() if k in available_streams} @receiver(signals.post_save) # pylint: disable=unused-argument diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index a10f128d6..180191d98 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -118,7 +118,11 @@ REDIS_ACTIVITY_PORT = env("REDIS_ACTIVITY_PORT", 6379) REDIS_ACTIVITY_PASSWORD = env("REDIS_ACTIVITY_PASSWORD", None) 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 # https://docs.djangoproject.com/en/3.2/ref/settings/#databases diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 65cf97e19..780f1d171 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -4,35 +4,25 @@ {% block panel %}

- {% if tab == 'home' %} - {% trans "Home Timeline" %} - {% elif tab == 'local' %} - {% trans "Local Timeline" %} - {% else %} - {% trans "Federated Timeline" %} - {% endif %} + {{ tab.name }}

{# announcements and system messages #} {% if not activities.number > 1 %} -{% 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 %}
{% include 'snippets/goal_card.html' with year=year %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 3d39b9d52..d3e2dad1a 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -23,7 +23,7 @@ STATUS_PATH = r"%s/(%s)/(?P\d+)" % (USER_PATH, "|".join(status_types) BOOK_PATH = r"^book/(?P\d+)" -STREAMS = "|".join(settings.STREAMS) +STREAMS = "|".join(s["key"] for s in settings.STREAMS) urlpatterns = [ path("admin/", admin.site.urls), diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 3001c86e2..d28166a3f 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -23,10 +23,10 @@ class Feed(View): def get(self, request, tab): """user's homepage with activity feed""" - if not tab in STREAMS: - tab = "home" + tab = [s for s in STREAMS if s["key"] == tab] + 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) suggestions = suggested_users.get_suggestions(request.user) @@ -38,8 +38,9 @@ class Feed(View): "activities": paginated.get_page(request.GET.get("page")), "suggested_users": suggestions, "tab": tab, + "streams": STREAMS, "goal_form": forms.GoalForm(), - "path": "/%s" % tab, + "path": "/%s" % tab["key"], }, } return TemplateResponse(request, "feed/feed.html", data)