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.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

View file

@ -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

View file

@ -4,35 +4,25 @@
{% block panel %}
<h1 class="title">
{% if tab == 'home' %}
{% trans "Home Timeline" %}
{% elif tab == 'local' %}
{% trans "Local Timeline" %}
{% else %}
{% trans "Federated Timeline" %}
{% endif %}
{{ tab.name }}
</h1>
<div class="tabs">
<ul>
<li class="{% if tab == 'home' %}is-active{% endif %}"{% if tab == 'home' %} aria-current="page"{% endif %}>
<a href="/#feed">{% trans "Home" %}</a>
</li>
<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>
{% for stream in streams %}
<li class="{% if tab.key == stream.key %}is-active{% endif %}"{% if tab.key == stream.key %} aria-current="page"{% endif %}>
<a href="/{{ stream.key }}#feed">{{ stream.shortname }}</a>
</li>
{% endfor %}
</ul>
</div>
{# announcements and system messages #}
{% if not activities.number > 1 %}
<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>
{% 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 %}
<section class="block">
{% 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+)"
STREAMS = "|".join(settings.STREAMS)
STREAMS = "|".join(s["key"] for s in settings.STREAMS)
urlpatterns = [
path("admin/", admin.site.urls),

View file

@ -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)