From e2e5ed9aa345f86a58ec7838b6a23fc1b3d6bda0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 20 Jan 2022 16:04:42 -0800 Subject: [PATCH 01/36] Makes default language configurable --- .env.example | 2 ++ bookwyrm/settings.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 2000a716..ca6f65bb 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,8 @@ USE_HTTPS=true DOMAIN=your.domain.here EMAIL=your@email.here +# Instance defualt language (see options at bookwyrm/settings.py "LANGUAGES" +LANGUAGE_CODE="en-us" # Used for deciding which editions to prefer DEFAULT_LANGUAGE="English" diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 197e672c..e86d2792 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -243,7 +243,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ -LANGUAGE_CODE = "en-us" +LANGUAGE_CODE = env("LANGUAGE_CODE", "en-us") LANGUAGES = [ ("en-us", _("English")), ("de-de", _("Deutsch (German)")), From 3fc690e763667e079b459cc60d0cba57164d2a18 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 22 Jan 2022 17:03:48 -0800 Subject: [PATCH 02/36] Calculate and translate unread status counts in view --- bookwyrm/static/js/bookwyrm.js | 33 +------------------------------ bookwyrm/templates/feed/feed.html | 9 ++++++--- bookwyrm/urls.py | 2 +- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/feed.py | 1 - bookwyrm/views/updates.py | 26 +++++++++++++++++++----- 6 files changed, 30 insertions(+), 43 deletions(-) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 94163787..eccd4c55 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -122,39 +122,8 @@ let BookWyrm = new (class { */ updateCountElement(counter, data) { let count = data.count; - const count_by_type = data.count_by_type; const currentCount = counter.innerText; const hasMentions = data.has_mentions; - const allowedStatusTypesEl = document.getElementById("unread-notifications-wrapper"); - - // If we're on the right counter element - if (counter.closest("[data-poll-wrapper]").contains(allowedStatusTypesEl)) { - const allowedStatusTypes = JSON.parse(allowedStatusTypesEl.textContent); - - // For keys in common between allowedStatusTypes and count_by_type - // This concerns 'review', 'quotation', 'comment' - count = allowedStatusTypes.reduce(function (prev, currentKey) { - const currentValue = count_by_type[currentKey] | 0; - - return prev + currentValue; - }, 0); - - // Add all the "other" in count_by_type if 'everything' is allowed - if (allowedStatusTypes.includes("everything")) { - // Clone count_by_type with 0 for reviews/quotations/comments - const count_by_everything_else = Object.assign({}, count_by_type, { - review: 0, - quotation: 0, - comment: 0, - }); - - count = Object.keys(count_by_everything_else).reduce(function (prev, currentKey) { - const currentValue = count_by_everything_else[currentKey] | 0; - - return prev + currentValue; - }, count); - } - } if (count != currentCount) { this.addRemoveClass(counter.closest("[data-poll-wrapper]"), "is-hidden", count < 1); @@ -517,7 +486,7 @@ let BookWyrm = new (class { duplicateInput(event) { const trigger = event.currentTarget; - const input_id = trigger.dataset["duplicate"]; + const input_id = trigger.dataset.duplicate; const orig = document.getElementById(input_id); const parent = orig.parentNode; const new_count = parent.querySelectorAll("input").length + 1; diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index dbbc650f..9e625313 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -24,9 +24,12 @@ {# announcements and system messages #} {% if not activities.number > 1 %} - {% if request.user.show_goal and not goal and tab.key == 'home' %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 7cdfd92a..1d894eee 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -47,7 +47,7 @@ urlpatterns = [ re_path(r"^ostatus_subscribe/?$", views.ostatus_follow_request), # polling updates re_path("^api/updates/notifications/?$", views.get_notification_count), - re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_count), + re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_string), # authentication re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^login/(?Pconfirmed)/?$", views.Login.as_view(), name="login"), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3f57c274..ec7af64d 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -101,7 +101,7 @@ from .rss_feed import RssFeed from .search import Search from .status import CreateStatus, EditStatus, DeleteStatus, update_progress from .status import edit_readthrough -from .updates import get_notification_count, get_unread_status_count +from .updates import get_notification_count, get_unread_status_string from .user import User, Followers, Following, hide_suggestions, user_redirect from .wellknown import * from .annual_summary import ( diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index cb16371b..a8d8edd5 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -62,7 +62,6 @@ class Feed(View): "streams": STREAMS, "goal_form": forms.GoalForm(), "feed_status_types_options": FeedFilterChoices, - "allowed_status_types": request.user.feed_status_types, "filters_applied": filters_applied, "path": f"/{tab['key']}", "annual_summary_year": get_annual_summary_year(), diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py index 765865ef..7c2574f3 100644 --- a/bookwyrm/views/updates.py +++ b/bookwyrm/views/updates.py @@ -1,6 +1,7 @@ """ endpoints for getting updates about activity """ from django.contrib.auth.decorators import login_required from django.http import Http404, JsonResponse +from django.utils.translation import ngettext from bookwyrm import activitystreams @@ -17,14 +18,29 @@ def get_notification_count(request): @login_required -def get_unread_status_count(request, stream="home"): +def get_unread_status_string(request, stream="home"): """any unread statuses for this feed?""" stream = activitystreams.streams.get(stream) if not stream: raise Http404 + + counts_by_type = stream.get_unread_count_by_status_type(request.user).items() + print(counts_by_type) + if counts_by_type == {}: + count = stream.get_unread_count(request.user) + else: + # only consider the types that are visible in the feed + allowed_status_types = request.user.feed_status_types + count = sum(c for (k, c) in counts_by_type if k in allowed_status_types) + # if "everything else" is allowed, add other types to the sum + count += sum(c for (k, c) in counts_by_type if k not in ["review", "comment", "quotation"]) + + translation_string = lambda c: ngettext( + "Load %(count)d unread status", + "Load %(count)d unread statuses", + c + ) % {"count": c} + return JsonResponse( - { - "count": stream.get_unread_count(request.user), - "count_by_type": stream.get_unread_count_by_status_type(request.user), - } + {"total": translation_string(count)} ) From e5c850054706b270ef812b764d180049a50dca10 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 22 Jan 2022 17:05:31 -0800 Subject: [PATCH 03/36] Updates cache buster --- bookwyrm/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 197e672c..f607a1f7 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -14,7 +14,7 @@ VERSION = "0.2.0" PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") -JS_CACHE = "76c5ff1f" +JS_CACHE = "7b5303af" # email EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend") From 191079a9224068001a48ccd4a7ee2d9bd9ab9dde Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 22 Jan 2022 19:01:42 -0800 Subject: [PATCH 04/36] Python formatting --- bookwyrm/urls.py | 4 +++- bookwyrm/views/updates.py | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 1d894eee..bc47bb60 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -47,7 +47,9 @@ urlpatterns = [ re_path(r"^ostatus_subscribe/?$", views.ostatus_follow_request), # polling updates re_path("^api/updates/notifications/?$", views.get_notification_count), - re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_string), + re_path( + "^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_string + ), # authentication re_path(r"^login/?$", views.Login.as_view(), name="login"), re_path(r"^login/(?Pconfirmed)/?$", views.Login.as_view(), name="login"), diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py index 7c2574f3..3c3dc6af 100644 --- a/bookwyrm/views/updates.py +++ b/bookwyrm/views/updates.py @@ -33,14 +33,14 @@ def get_unread_status_string(request, stream="home"): allowed_status_types = request.user.feed_status_types count = sum(c for (k, c) in counts_by_type if k in allowed_status_types) # if "everything else" is allowed, add other types to the sum - count += sum(c for (k, c) in counts_by_type if k not in ["review", "comment", "quotation"]) + count += sum( + c + for (k, c) in counts_by_type + if k not in ["review", "comment", "quotation"] + ) translation_string = lambda c: ngettext( - "Load %(count)d unread status", - "Load %(count)d unread statuses", - c + "Load %(count)d unread status", "Load %(count)d unread statuses", c ) % {"count": c} - return JsonResponse( - {"total": translation_string(count)} - ) + return JsonResponse({"total": translation_string(count)}) From d0a4c78d02d867fe267b2f723ddfa7637e8ed4d6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 24 Jan 2022 12:01:17 -0800 Subject: [PATCH 05/36] Limit length on list item note --- .../migrations/0130_alter_listitem_notes.py | 21 +++++++++++++++++++ bookwyrm/models/list.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 bookwyrm/migrations/0130_alter_listitem_notes.py diff --git a/bookwyrm/migrations/0130_alter_listitem_notes.py b/bookwyrm/migrations/0130_alter_listitem_notes.py new file mode 100644 index 00000000..a12efd40 --- /dev/null +++ b/bookwyrm/migrations/0130_alter_listitem_notes.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.10 on 2022-01-24 20:01 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0129_auto_20220117_1716"), + ] + + operations = [ + migrations.AlterField( + model_name="listitem", + name="notes", + field=bookwyrm.models.fields.TextField( + blank=True, max_length=300, null=True + ), + ), + ] diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index d159bc4a..733ee044 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -125,7 +125,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel): user = fields.ForeignKey( "User", on_delete=models.PROTECT, activitypub_field="actor" ) - notes = fields.TextField(blank=True, null=True) + notes = fields.TextField(blank=True, null=True, max_length=300) approved = models.BooleanField(default=True) order = fields.IntegerField() endorsement = models.ManyToManyField("User", related_name="endorsers") From 5206d08dbb0d563a2d48ef6193a6d9c94f633fd5 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 24 Jan 2022 13:37:51 -0800 Subject: [PATCH 06/36] Adds demo display of comment in list entry --- bookwyrm/templates/lists/list.html | 36 +++++++++++++++++-------- bookwyrm/templates/snippets/avatar.html | 8 ++++-- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index c44d3fe3..a1da21e5 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -4,6 +4,7 @@ {% load book_display_tags %} {% load group_tags %} {% load markdown %} +{% load utilities %} {% block breadcrumbs %}