From d6f7f76c4d8c35ebafb994f6f4ee01b932ae2bf0 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 11:37:01 -0800 Subject: [PATCH 01/23] Removes outdated/unused version and updating code I had the bright idea of creating this update script but it doesn't work and hasn't been maintained, so it's just sitting there causing confusing and requiring weird things to exist in other places. Now, the unused `version` field can be removed and I can scrap the management command for getting versions. --- .../management/commands/instance_version.py | 54 ------------------- ..._version_sitesettings_available_version.py | 18 +++++++ bookwyrm/models/site.py | 2 +- bookwyrm/views/admin/dashboard.py | 18 ++----- update.sh | 37 ------------- 5 files changed, 24 insertions(+), 105 deletions(-) delete mode 100644 bookwyrm/management/commands/instance_version.py create mode 100644 bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py delete mode 100755 update.sh diff --git a/bookwyrm/management/commands/instance_version.py b/bookwyrm/management/commands/instance_version.py deleted file mode 100644 index ca150d640..000000000 --- a/bookwyrm/management/commands/instance_version.py +++ /dev/null @@ -1,54 +0,0 @@ -""" Get your admin code to allow install """ -from django.core.management.base import BaseCommand - -from bookwyrm import models -from bookwyrm.settings import VERSION - - -# pylint: disable=no-self-use -class Command(BaseCommand): - """command-line options""" - - help = "What version is this?" - - def add_arguments(self, parser): - """specify which function to run""" - parser.add_argument( - "--current", - action="store_true", - help="Version stored in database", - ) - parser.add_argument( - "--target", - action="store_true", - help="Version stored in settings", - ) - parser.add_argument( - "--update", - action="store_true", - help="Update database version", - ) - - # pylint: disable=unused-argument - def handle(self, *args, **options): - """execute init""" - site = models.SiteSettings.objects.get() - current = site.version or "0.0.1" - target = VERSION - if options.get("current"): - print(current) - return - - if options.get("target"): - print(target) - return - - if options.get("update"): - site.version = target - site.save() - return - - if current != target: - print(f"{current}/{target}") - else: - print(current) diff --git a/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py new file mode 100644 index 000000000..219ae32f6 --- /dev/null +++ b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.23 on 2024-01-02 19:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0191_merge_20240102_0326'), + ] + + operations = [ + migrations.RenameField( + model_name='sitesettings', + old_name='version', + new_name='available_version', + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index bd53f1f07..7ca7e0015 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -45,7 +45,7 @@ class SiteSettings(SiteModel): default_theme = models.ForeignKey( "Theme", null=True, blank=True, on_delete=models.SET_NULL ) - version = models.CharField(null=True, blank=True, max_length=10) + available_version = models.CharField(null=True, blank=True, max_length=10) # admin setup options install_mode = models.BooleanField(default=False) diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 9d256fc6c..c5648ff11 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -15,7 +15,6 @@ from django.views import View from csp.decorators import csp_update from bookwyrm import models, settings -from bookwyrm.connectors.abstract_connector import get_data from bookwyrm.utils import regex @@ -59,18 +58,11 @@ class Dashboard(View): == site._meta.get_field("privacy_policy").get_default() ) - # check version - - try: - release = get_data(settings.RELEASE_API, timeout=3) - available_version = release.get("tag_name", None) - if available_version and version.parse(available_version) > version.parse( - settings.VERSION - ): - data["current_version"] = settings.VERSION - data["available_version"] = available_version - except: # pylint: disable= bare-except - pass + if site.available_version and version.parse(site.available_version) > version.parse( + settings.VERSION + ): + data["current_version"] = settings.VERSION + data["available_version"] = site.available_version return TemplateResponse(request, "settings/dashboard/dashboard.html", data) diff --git a/update.sh b/update.sh deleted file mode 100755 index 727ce1b24..000000000 --- a/update.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -set -e - -# determine inital and target versions -initial_version="`./bw-dev runweb python manage.py instance_version --current`" -target_version="`./bw-dev runweb python manage.py instance_version --target`" - -initial_version="`echo $initial_version | tail -n 1 | xargs`" -target_version="`echo $target_version | tail -n 1 | xargs`" -if [[ "$initial_version" = "$target_version" ]]; then - echo "Already up to date; version $initial_version" - exit -fi - -echo "---------------------------------------" -echo "Updating from version: $initial_version" -echo ".......... to version: $target_version" -echo "---------------------------------------" - -function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } - -# execute scripts between initial and target -for version in `ls -A updates/ | sort -V `; do - if version_gt $initial_version $version; then - # too early - continue - fi - if version_gt $version $target_version; then - # too late - continue - fi - echo "Running tasks for version $version" - ./updates/$version -done - -./bw-dev runweb python manage.py instance_version --update -echo "✨ ----------- Done! --------------- ✨" From 5509941aa4d14fc5422644cac5e8ff658e1fbd5b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 12:23:32 -0800 Subject: [PATCH 02/23] Adds schedule-able task to check for version updates --- ..._version_sitesettings_available_version.py | 8 +++---- bookwyrm/models/site.py | 14 ++++++++++++ .../settings/dashboard/dashboard.html | 4 ++++ .../dashboard/warnings/check_for_updates.html | 22 +++++++++++++++++++ bookwyrm/views/admin/dashboard.py | 21 +++++++++++++++++- 5 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html diff --git a/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py index 219ae32f6..db67b4e92 100644 --- a/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py +++ b/bookwyrm/migrations/0192_rename_version_sitesettings_available_version.py @@ -6,13 +6,13 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('bookwyrm', '0191_merge_20240102_0326'), + ("bookwyrm", "0191_merge_20240102_0326"), ] operations = [ migrations.RenameField( - model_name='sitesettings', - old_name='version', - new_name='available_version', + model_name="sitesettings", + old_name="version", + new_name="available_version", ), ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index 7ca7e0015..f82a4d94b 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -10,8 +10,11 @@ from django.dispatch import receiver from django.utils import timezone from model_utils import FieldTracker +from bookwyrm.connectors.abstract_connector import get_data from bookwyrm.preview_images import generate_site_preview_image_task from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES, STATIC_FULL_URL +from bookwyrm.settings import RELEASE_API +from bookwyrm.tasks import app, MISC from .base_model import BookWyrmModel, new_access_code from .user import User from .fields import get_absolute_url @@ -244,3 +247,14 @@ def preview_image(instance, *args, **kwargs): if len(changed_fields) > 0: generate_site_preview_image_task.delay() + + +@app.task(queue=MISC) +def check_for_updates_task(): + """ See if git remote knows about a new version """ + site = SiteSettings.objects.get() + release = get_data(RELEASE_API, timeout=3) + available_version = release.get("tag_name", None) + if available_version: + site.available_version = available_version + site.save(update_fields=["available_version"]) diff --git a/bookwyrm/templates/settings/dashboard/dashboard.html b/bookwyrm/templates/settings/dashboard/dashboard.html index 4c109c7e1..d43b3bade 100644 --- a/bookwyrm/templates/settings/dashboard/dashboard.html +++ b/bookwyrm/templates/settings/dashboard/dashboard.html @@ -45,6 +45,10 @@ {% include 'settings/dashboard/warnings/update_version.html' with warning_level="warning" fullwidth=True %} {% endif %} + {% if schedule_form %} + {% include 'settings/dashboard/warnings/check_for_updates.html' with warning_level="success" fullwidth=True %} + {% endif %} + {% if missing_privacy or missing_conduct %}
{% if missing_privacy %} diff --git a/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html new file mode 100644 index 000000000..07f11a62d --- /dev/null +++ b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html @@ -0,0 +1,22 @@ +{% extends 'settings/dashboard/warnings/layout.html' %} +{% load i18n %} + +{% block warning_text %} + +
+ {% csrf_token %} + +

+ {% blocktrans trimmed with current=current_version available=available_version %} + Check for available version updates? (Recommended) + {% endblocktrans %} +

+ + {{ schedule_form.every.as_hidden }} + {{ schedule_form.period.as_hidden }} + + +
+ +{% endblock %} + diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index c5648ff11..ea0675f59 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -6,15 +6,18 @@ from dateutil.parser import parse from packaging import version from django.contrib.auth.decorators import login_required, permission_required +from django.db import transaction from django.db.models import Q +from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils import timezone from django.utils.decorators import method_decorator from django.views import View +from django_celery_beat.models import PeriodicTask from csp.decorators import csp_update -from bookwyrm import models, settings +from bookwyrm import forms, models, settings from bookwyrm.utils import regex @@ -64,8 +67,24 @@ class Dashboard(View): data["current_version"] = settings.VERSION data["available_version"] = site.available_version + if not PeriodicTask.objects.filter(name="check-for-updates").exists(): + data["schedule_form"] = forms.IntervalScheduleForm({"every": 1, "period": "days"}) + return TemplateResponse(request, "settings/dashboard/dashboard.html", data) + def post(self, request): + """ Create a schedule task to check for updates """ + schedule_form = forms.IntervalScheduleForm(request.POST) + + with transaction.atomic(): + schedule = schedule_form.save(request) + PeriodicTask.objects.get_or_create( + interval=schedule, + name="check-for-updates", + task="bookwyrm.models.site.check_for_updates_task" + ) + return redirect("settings-dashboard") + def get_charts_and_stats(request): """Defines the dashboard charts""" From f36af42f414196f3e12d30a843470979cbcb9713 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 13:05:44 -0800 Subject: [PATCH 03/23] Adds view to see scheduled tasks --- bookwyrm/models/site.py | 2 +- bookwyrm/templates/settings/layout.html | 4 + bookwyrm/templates/settings/schedules.html | 116 +++++++++++++++++++++ bookwyrm/urls.py | 5 + bookwyrm/views/__init__.py | 1 + bookwyrm/views/admin/dashboard.py | 14 +-- bookwyrm/views/admin/schedule.py | 23 ++++ 7 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 bookwyrm/templates/settings/schedules.html create mode 100644 bookwyrm/views/admin/schedule.py diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index f82a4d94b..ad0dbff64 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -251,7 +251,7 @@ def preview_image(instance, *args, **kwargs): @app.task(queue=MISC) def check_for_updates_task(): - """ See if git remote knows about a new version """ + """See if git remote knows about a new version""" site = SiteSettings.objects.get() release = get_data(RELEASE_API, timeout=3) available_version = release.get("tag_name", None) diff --git a/bookwyrm/templates/settings/layout.html b/bookwyrm/templates/settings/layout.html index dcaaaeb38..70c7ef0f4 100644 --- a/bookwyrm/templates/settings/layout.html +++ b/bookwyrm/templates/settings/layout.html @@ -85,6 +85,10 @@ {% url 'settings-celery' as url %} {% trans "Celery status" %} +
  • + {% url 'settings-schedules' as url %} + {% trans "Scheduled tasks" %} +
  • {% url 'settings-email-config' as url %} {% trans "Email Configuration" %} diff --git a/bookwyrm/templates/settings/schedules.html b/bookwyrm/templates/settings/schedules.html new file mode 100644 index 000000000..fe096092d --- /dev/null +++ b/bookwyrm/templates/settings/schedules.html @@ -0,0 +1,116 @@ +{% extends 'settings/layout.html' %} +{% load i18n %} +{% load humanize %} +{% load utilities %} + +{% block title %} +{% trans "Scheduled tasks" %} +{% endblock %} + +{% block header %} +{% trans "Scheduled tasks" %} +{% endblock %} + +{% block panel %} + +
    +

    {% trans "Tasks" %}

    +
    + + + + + + + + + + + {% for task in tasks %} + + + + + + + + + + {% empty %} + + + + {% endfor %} +
    + {% trans "Name" %} + + {% trans "Celery task" %} + + {% trans "Date changed" %} + + {% trans "Last run at" %} + + {% trans "Schedule" %} + + {% trans "Schedule ID" %} + + {% trans "Enabled" %} +
    + {{ task.name }} + + {{ task.task }} + + {{ task.date_changed }} + + {{ task.last_run_at }} + + {% firstof task.interval task.crontab "None" %} + + {{ task.interval.id }} + + {{ task.enabled|yesno }} +
    + {% trans "No scheduled tasks" %} +
    +
    +
    + +
    +

    {% trans "Schedules" %}

    +
    + + + + + + + {% for schedule in schedules %} + + + + + + {% empty %} + + + + {% endfor %} +
    + {% trans "ID" %} + + {% trans "Schedule" %} + + {% trans "Tasks" %} +
    + {{ schedule.id }} + + {{ schedule }} + + {{ schedule.periodictask_set.count }} +
    + {% trans "No schedules found" %} +
    +
    +
    + +{% endblock %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 76e60245b..64742347a 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -359,6 +359,11 @@ urlpatterns = [ re_path( r"^settings/celery/ping/?$", views.celery_ping, name="settings-celery-ping" ), + re_path( + r"^settings/schedules/?$", + views.ScheduledTasks.as_view(), + name="settings-schedules", + ), re_path( r"^settings/email-config/?$", views.EmailConfig.as_view(), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3be813208..d77f2675f 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -5,6 +5,7 @@ from .admin.announcements import EditAnnouncement, delete_announcement from .admin.automod import AutoMod, automod_delete, run_automod from .admin.automod import schedule_automod_task, unschedule_automod_task from .admin.celery_status import CeleryStatus, celery_ping +from .admin.schedule import ScheduledTasks from .admin.dashboard import Dashboard from .admin.federation import Federation, FederatedServer from .admin.federation import AddFederatedServer, ImportServerBlocklist diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index ea0675f59..4b2575fa6 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -61,19 +61,21 @@ class Dashboard(View): == site._meta.get_field("privacy_policy").get_default() ) - if site.available_version and version.parse(site.available_version) > version.parse( - settings.VERSION - ): + if site.available_version and version.parse( + site.available_version + ) > version.parse(settings.VERSION): data["current_version"] = settings.VERSION data["available_version"] = site.available_version if not PeriodicTask.objects.filter(name="check-for-updates").exists(): - data["schedule_form"] = forms.IntervalScheduleForm({"every": 1, "period": "days"}) + data["schedule_form"] = forms.IntervalScheduleForm( + {"every": 1, "period": "days"} + ) return TemplateResponse(request, "settings/dashboard/dashboard.html", data) def post(self, request): - """ Create a schedule task to check for updates """ + """Create a schedule task to check for updates""" schedule_form = forms.IntervalScheduleForm(request.POST) with transaction.atomic(): @@ -81,7 +83,7 @@ class Dashboard(View): PeriodicTask.objects.get_or_create( interval=schedule, name="check-for-updates", - task="bookwyrm.models.site.check_for_updates_task" + task="bookwyrm.models.site.check_for_updates_task", ) return redirect("settings-dashboard") diff --git a/bookwyrm/views/admin/schedule.py b/bookwyrm/views/admin/schedule.py new file mode 100644 index 000000000..ce5944ee5 --- /dev/null +++ b/bookwyrm/views/admin/schedule.py @@ -0,0 +1,23 @@ +""" Scheduled celery tasks """ +from django.contrib.auth.decorators import login_required, permission_required +from django.template.response import TemplateResponse +from django.utils.decorators import method_decorator +from django.views import View +from django_celery_beat.models import PeriodicTask, IntervalSchedule + + +@method_decorator(login_required, name="dispatch") +@method_decorator( + permission_required("bookwyrm.edit_instance_settings", raise_exception=True), + name="dispatch", +) +# pylint: disable=no-self-use +class ScheduledTasks(View): + """Manage automated flagging""" + + def get(self, request): + """view schedules""" + data = {} + data["tasks"] = PeriodicTask.objects.all() + data["schedules"] = IntervalSchedule.objects.all() + return TemplateResponse(request, "settings/schedules.html", data) From 8be9e91d2162871faae0aaabbecdf8da449b6c2d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 13:16:53 -0800 Subject: [PATCH 04/23] Re-use schedules rather than creating new ones --- bookwyrm/views/admin/automod.py | 4 ++-- bookwyrm/views/admin/dashboard.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/views/admin/automod.py b/bookwyrm/views/admin/automod.py index 9a32dd9ee..58818ad9b 100644 --- a/bookwyrm/views/admin/automod.py +++ b/bookwyrm/views/admin/automod.py @@ -6,7 +6,7 @@ from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.http import require_POST -from django_celery_beat.models import PeriodicTask +from django_celery_beat.models import PeriodicTask, IntervalSchedule from bookwyrm import forms, models @@ -54,7 +54,7 @@ def schedule_automod_task(request): return TemplateResponse(request, "settings/automod/rules.html", data) with transaction.atomic(): - schedule = form.save(request) + schedule, _ = IntervalSchedule.objects.get_or_create(**form.cleaned_data) PeriodicTask.objects.get_or_create( interval=schedule, name="automod-task", diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 4b2575fa6..a4c630067 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -13,7 +13,7 @@ from django.template.response import TemplateResponse from django.utils import timezone from django.utils.decorators import method_decorator from django.views import View -from django_celery_beat.models import PeriodicTask +from django_celery_beat.models import PeriodicTask, IntervalSchedule from csp.decorators import csp_update @@ -79,7 +79,9 @@ class Dashboard(View): schedule_form = forms.IntervalScheduleForm(request.POST) with transaction.atomic(): - schedule = schedule_form.save(request) + schedule, _ = IntervalSchedule.objects.get_or_create( + **schedule_form.cleaned_data + ) PeriodicTask.objects.get_or_create( interval=schedule, name="check-for-updates", From 193a1c7d54564c3ab35be20e27681566c2305581 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 13:28:25 -0800 Subject: [PATCH 05/23] updates wording and fixes get or create logic --- VERSION | 2 +- .../settings/dashboard/warnings/check_for_updates.html | 4 ++-- bookwyrm/views/admin/dashboard.py | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 39e898a4f..ee6cdce3c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.1 +0.6.1 diff --git a/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html index 07f11a62d..f0a2a8013 100644 --- a/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html +++ b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html @@ -8,14 +8,14 @@

    {% blocktrans trimmed with current=current_version available=available_version %} - Check for available version updates? (Recommended) + Would you like to automatically check for new BookWyrm releases? (recommended) {% endblocktrans %}

    {{ schedule_form.every.as_hidden }} {{ schedule_form.period.as_hidden }} - + {% endblock %} diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index a4c630067..21b19bf16 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -77,6 +77,8 @@ class Dashboard(View): def post(self, request): """Create a schedule task to check for updates""" schedule_form = forms.IntervalScheduleForm(request.POST) + if not schedule_form.is_valid(): + raise schedule_form.ValidationError(schedule_form.errors) with transaction.atomic(): schedule, _ = IntervalSchedule.objects.get_or_create( From d287581620a5d1238988803d05ce2ce9c6cbf52b Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 2 Jan 2024 13:31:18 -0800 Subject: [PATCH 06/23] Fixes html validation error --- .../settings/dashboard/warnings/check_for_updates.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html index f0a2a8013..00f320824 100644 --- a/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html +++ b/bookwyrm/templates/settings/dashboard/warnings/check_for_updates.html @@ -1,6 +1,8 @@ {% extends 'settings/dashboard/warnings/layout.html' %} {% load i18n %} +{% block warning_link %}#{% endblock %} + {% block warning_text %}
    From 6cd2c9113506cf71756fc1bb5f025297fbcc4f53 Mon Sep 17 00:00:00 2001 From: Wesley Aptekar-Cassels Date: Thu, 4 Jan 2024 18:58:12 -0500 Subject: [PATCH 07/23] Allow page numbers to be text, instead of integers. Fixes: #2640 --- .../0192_make_page_positions_text.py | 23 +++++++++++++++++++ bookwyrm/models/status.py | 10 ++++---- .../snippets/create_status/quotation.html | 6 ++--- bookwyrm/tests/views/books/test_book.py | 8 ++++--- 4 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 bookwyrm/migrations/0192_make_page_positions_text.py diff --git a/bookwyrm/migrations/0192_make_page_positions_text.py b/bookwyrm/migrations/0192_make_page_positions_text.py new file mode 100644 index 000000000..940a9e941 --- /dev/null +++ b/bookwyrm/migrations/0192_make_page_positions_text.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.23 on 2024-01-04 23:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0191_merge_20240102_0326"), + ] + + operations = [ + migrations.AlterField( + model_name="quotation", + name="endposition", + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name="quotation", + name="position", + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index cc44fe2bf..f33c32824 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -338,11 +338,13 @@ class Quotation(BookStatus): quote = fields.HtmlField() raw_quote = models.TextField(blank=True, null=True) - position = models.IntegerField( - validators=[MinValueValidator(0)], null=True, blank=True + position = models.TextField( + null=True, + blank=True, ) - endposition = models.IntegerField( - validators=[MinValueValidator(0)], null=True, blank=True + endposition = models.TextField( + null=True, + blank=True, ) position_mode = models.CharField( max_length=3, diff --git a/bookwyrm/templates/snippets/create_status/quotation.html b/bookwyrm/templates/snippets/create_status/quotation.html index bd1d817ad..dc17585a9 100644 --- a/bookwyrm/templates/snippets/create_status/quotation.html +++ b/bookwyrm/templates/snippets/create_status/quotation.html @@ -56,8 +56,7 @@ uuid: a unique identifier used to make html "id" attributes unique and clarify j Date: Sat, 20 Jan 2024 16:15:14 +0100 Subject: [PATCH 08/23] Replace python-requests with BookWyrm in user agent Fixes #3108 --- bookwyrm/settings.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index cc941da84..adc9bd0ef 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -347,8 +347,7 @@ USE_L10N = True USE_TZ = True -agent = requests.utils.default_user_agent() -USER_AGENT = f"{agent} (BookWyrm/{VERSION}; +https://{DOMAIN}/)" +USER_AGENT = f"BookWyrm (BookWyrm/{VERSION}; +https://{DOMAIN}/)" # Imagekit generated thumbnails ENABLE_THUMBNAIL_GENERATION = env.bool("ENABLE_THUMBNAIL_GENERATION", False) From f7b4d9ea50ca4593bdfe24518ead29da5093679b Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Fri, 19 Jan 2024 21:35:12 +0100 Subject: [PATCH 09/23] Give individual status page a title and OpenGraph description --- bookwyrm/models/status.py | 45 +++++++++++++++++++++++++++++ bookwyrm/templates/feed/status.html | 12 ++++---- bookwyrm/views/feed.py | 2 ++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index cc44fe2bf..04fb8daa3 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -12,6 +12,8 @@ from django.db.models import Q from django.dispatch import receiver from django.template.loader import get_template from django.utils import timezone +from django.utils.translation import gettext_lazy as _ +from django.utils.translation import ngettext_lazy from model_utils import FieldTracker from model_utils.managers import InheritanceManager @@ -178,6 +180,16 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """you can't boost dms""" return self.privacy in ["unlisted", "public"] + @property + def page_title(self): + """title of the page when only this status is shown""" + return _("%(display_name)s's status") % {"display_name": self.user.display_name} + + @property + def page_description(self): + """description of the page in meta tags when only this status is shown""" + return None + def to_replies(self, **kwargs): """helper function for loading AP serialized replies to a status""" return self.to_ordered_collection( @@ -332,6 +344,13 @@ class Comment(BookStatus): activity_serializer = activitypub.Comment + @property + def page_title(self): + return _("%(display_name)s's comment on %(book_title)s") % { + "display_name": self.user.display_name, + "book_title": self.book.title, + } + class Quotation(BookStatus): """like a review but without a rating and transient""" @@ -374,6 +393,13 @@ class Quotation(BookStatus): activity_serializer = activitypub.Quotation + @property + def page_title(self): + return _("%(display_name)s's quote from %(book_title)s") % { + "display_name": self.user.display_name, + "book_title": self.book.title, + } + class Review(BookStatus): """a book review""" @@ -403,6 +429,13 @@ class Review(BookStatus): """indicate the book in question for mastodon (or w/e) users""" return self.content + @property + def page_title(self): + return _("%(display_name)s's review of %(book_title)s") % { + "display_name": self.user.display_name, + "book_title": self.book.title, + } + activity_serializer = activitypub.Review pure_type = "Article" @@ -426,6 +459,18 @@ class ReviewRating(Review): template = get_template("snippets/generated_status/rating.html") return template.render({"book": self.book, "rating": self.rating}).strip() + @property + def page_description(self): + return ngettext_lazy( + "%(display_name)s rated %(book_title)s: %(display_rating).1f star", + "%(display_name)s rated %(book_title)s: %(display_rating).1f stars", + "display_rating", + ) % { + "display_name": self.user.display_name, + "book_title": self.book.title, + "display_rating": self.rating, + } + activity_serializer = activitypub.Rating pure_type = "Note" diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index c05d2ba46..b381c3714 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -2,13 +2,11 @@ {% load feed_page_tags %} {% load i18n %} +{% block title %}{{ title }}{% endblock %} + + {% block opengraph %} - {% firstof status.book status.mention_books.first as book %} - {% if book %} - {% include 'snippets/opengraph.html' with image=preview %} - {% else %} - {% include 'snippets/opengraph.html' %} - {% endif %} + {% include 'snippets/opengraph.html' with image=preview %} {% endblock %} @@ -41,4 +39,4 @@
  • -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 17218b93e..2d91990d0 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -197,6 +197,8 @@ class Status(View): "status": status, "children": children, "ancestors": ancestors, + "title": status.page_title, + "description": status.page_description, "preview": preview, }, } From ad56024ffe8adac7a8cab916b160b2f18edd2f1d Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sat, 20 Jan 2024 17:18:50 +0100 Subject: [PATCH 10/23] Add Status.page_image property --- bookwyrm/models/status.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 04fb8daa3..236826a2b 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -190,6 +190,15 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """description of the page in meta tags when only this status is shown""" return None + @property + def page_image(self): + """image to use as preview in meta tags when only this status is shown""" + if self.mention_books.exists(): + book = self.mention_books.first() + return book.preview_image + else: + return self.user.preview_image + def to_replies(self, **kwargs): """helper function for loading AP serialized replies to a status""" return self.to_ordered_collection( @@ -313,6 +322,10 @@ class BookStatus(Status): abstract = True + @property + def page_image(self): + return self.book.preview_image or super().page_image + class Comment(BookStatus): """like a review but without a rating and transient""" From 290ee997b3c935297811f033d8da0a564ba48f52 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sat, 20 Jan 2024 17:24:20 +0100 Subject: [PATCH 11/23] Refactor OpenGraph tags logic --- bookwyrm/templates/snippets/opengraph.html | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bookwyrm/templates/snippets/opengraph.html b/bookwyrm/templates/snippets/opengraph.html index 1e87a464f..78a6b1b3f 100644 --- a/bookwyrm/templates/snippets/opengraph.html +++ b/bookwyrm/templates/snippets/opengraph.html @@ -1,24 +1,25 @@ {% load static %} -{% if preview_images_enabled is True %} +{% firstof image site.preview_image as page_image %} +{% if page_image %} - {% if image %} - - - {% else %} - - - {% endif %} + + +{% elif site.logo %} + + + + {% else %} - - + + + {% endif %} - - - - +{% firstof description site.instance_tagline as description %} + + From ea9d3f8ba1ac3db3a050b0355bd3de3d20cd061e Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sat, 20 Jan 2024 17:25:20 +0100 Subject: [PATCH 12/23] Use Status.page_image for OpenGraph tags --- bookwyrm/templates/feed/status.html | 4 ++-- bookwyrm/views/feed.py | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index b381c3714..64e992a01 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -6,7 +6,7 @@ {% block opengraph %} - {% include 'snippets/opengraph.html' with image=preview %} + {% include 'snippets/opengraph.html' with image=page_image %} {% endblock %} @@ -39,4 +39,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 2d91990d0..d1feb278e 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -185,12 +185,6 @@ class Status(View): params=[status.id, visible_thread, visible_thread], ) - preview = None - if hasattr(status, "book"): - preview = status.book.preview_image - elif status.mention_books.exists(): - preview = status.mention_books.first().preview_image - data = { **feed_page_data(request.user), **{ @@ -199,7 +193,7 @@ class Status(View): "ancestors": ancestors, "title": status.page_title, "description": status.page_description, - "preview": preview, + "page_image": status.page_image, }, } return TemplateResponse(request, "feed/status.html", data) From 646b27b7a7e1099e81d5c3fa4c2b0008f54c889e Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sat, 20 Jan 2024 17:28:51 +0100 Subject: [PATCH 13/23] OpenGraph: fall back on book cover when preview images are disabled --- bookwyrm/models/status.py | 4 ++-- bookwyrm/templates/book/book.html | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 236826a2b..94893d6ae 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -195,7 +195,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """image to use as preview in meta tags when only this status is shown""" if self.mention_books.exists(): book = self.mention_books.first() - return book.preview_image + return book.preview_image or book.cover else: return self.user.preview_image @@ -324,7 +324,7 @@ class BookStatus(Status): @property def page_image(self): - return self.book.preview_image or super().page_image + return self.book.preview_image or self.book.cover or super().page_image class Comment(BookStatus): diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 8e76fb014..4c345832e 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -9,7 +9,8 @@ {% block title %}{{ book|book_title }}{% endblock %} {% block opengraph %} - {% include 'snippets/opengraph.html' with title=book.title description=book|book_description image=book.preview_image %} + {% firstof book.preview_image book.cover as book_image %} + {% include 'snippets/opengraph.html' with title=book.title description=book|book_description image=book_image %} {% endblock %} {% block content %} From eb6bea013fd1634f178da689e4843adcd05a6296 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Sun, 21 Jan 2024 11:04:08 +0100 Subject: [PATCH 14/23] Fix pylint warning --- bookwyrm/models/status.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 94893d6ae..0c9b18cc9 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -196,8 +196,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): if self.mention_books.exists(): book = self.mention_books.first() return book.preview_image or book.cover - else: - return self.user.preview_image + return self.user.preview_image def to_replies(self, **kwargs): """helper function for loading AP serialized replies to a status""" From 2d4b11aaeedd9530ad4ddcfcea6f8aeb2b55dda9 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Thu, 25 Jan 2024 01:50:10 +0300 Subject: [PATCH 15/23] Adding FictionBook format ("FB2", "FB3") to autocomplete options in "Get a copy" block. --- bookwyrm/static/js/autocomplete.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bookwyrm/static/js/autocomplete.js b/bookwyrm/static/js/autocomplete.js index a98cd9634..6836d356d 100644 --- a/bookwyrm/static/js/autocomplete.js +++ b/bookwyrm/static/js/autocomplete.js @@ -111,6 +111,10 @@ const tries = { }, }, f: { + b: { + 2: "FB2", + 3: "FB3", + }, l: { a: { c: "FLAC", From 31babdfa510d88f89d08cbfb56de94cd8c0ac028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Fri, 26 Jan 2024 06:01:34 -0300 Subject: [PATCH 16/23] Always prefer shared inboxes when computing receipent lists This avoids duplicate submissions to remote instances when mentioning followers (i.e., `POST /user/foo/inbox` followed by `POST /inbox`, which results in two separate `add_status` tasks, and might generate duplicates in the target instance). --- bookwyrm/models/activitypub_mixin.py | 2 +- bookwyrm/tests/models/test_activitypub_mixin.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index d0a941f43..41772a162 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -153,7 +153,7 @@ class ActivitypubMixin: mentions = self.recipients if hasattr(self, "recipients") else [] # we always send activities to explicitly mentioned users' inboxes - recipients = [u.inbox for u in mentions or [] if not u.local] + recipients = [u.shared_inbox or u.inbox for u in mentions if not u.local] # unless it's a dm, all the followers should receive the activity if privacy != "direct": diff --git a/bookwyrm/tests/models/test_activitypub_mixin.py b/bookwyrm/tests/models/test_activitypub_mixin.py index cad970412..2f6fad76d 100644 --- a/bookwyrm/tests/models/test_activitypub_mixin.py +++ b/bookwyrm/tests/models/test_activitypub_mixin.py @@ -227,14 +227,18 @@ class ActivitypubMixins(TestCase): shared_inbox="http://example.com/inbox", outbox="https://example.com/users/nutria/outbox", ) - MockSelf = namedtuple("Self", ("privacy", "user")) - mock_self = MockSelf("public", self.local_user) + MockSelf = namedtuple("Self", ("privacy", "user", "recipients")) self.local_user.followers.add(self.remote_user) self.local_user.followers.add(another_remote_user) + mock_self = MockSelf("public", self.local_user, []) recipients = ActivitypubMixin.get_recipients(mock_self) - self.assertEqual(len(recipients), 1) - self.assertEqual(recipients[0], "http://example.com/inbox") + self.assertCountEqual(recipients, ["http://example.com/inbox"]) + + # should also work with recipient that is a follower + mock_self.recipients.append(another_remote_user) + recipients = ActivitypubMixin.get_recipients(mock_self) + self.assertCountEqual(recipients, ["http://example.com/inbox"]) def test_get_recipients_software(self, *_): """should differentiate between bookwyrm and other remote users""" From 8ac873419fe66de65cdddf6a25560ed24c4e4a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Fri, 26 Jan 2024 06:29:59 -0300 Subject: [PATCH 17/23] refactor: eagerly use a set in recipients, get_recipients --- bookwyrm/models/activitypub_mixin.py | 25 +++++++++++++------------ bookwyrm/models/status.py | 6 +++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 41772a162..db737b8bc 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -152,8 +152,9 @@ class ActivitypubMixin: # find anyone who's tagged in a status, for example mentions = self.recipients if hasattr(self, "recipients") else [] - # we always send activities to explicitly mentioned users' inboxes - recipients = [u.shared_inbox or u.inbox for u in mentions if not u.local] + # we always send activities to explicitly mentioned users (using shared inboxes + # where available to avoid duplicate submissions to a given instance) + recipients = {u.shared_inbox or u.inbox for u in mentions if not u.local} # unless it's a dm, all the followers should receive the activity if privacy != "direct": @@ -173,18 +174,18 @@ class ActivitypubMixin: if user: queryset = queryset.filter(following=user) - # ideally, we will send to shared inboxes for efficiency - shared_inboxes = ( - queryset.filter(shared_inbox__isnull=False) - .values_list("shared_inbox", flat=True) - .distinct() + # as above, we prefer shared inboxes if available + recipients.update( + queryset.filter(shared_inbox__isnull=False).values_list( + "shared_inbox", flat=True + ) ) - # but not everyone has a shared inbox - inboxes = queryset.filter(shared_inbox__isnull=True).values_list( - "inbox", flat=True + recipients.update( + queryset.filter(shared_inbox__isnull=True).values_list( + "inbox", flat=True + ) ) - recipients += list(shared_inboxes) + list(inboxes) - return list(set(recipients)) + return list(recipients) def to_activity_dataclass(self): """convert from a model to an activity""" diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index cc44fe2bf..0d1d0d839 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -107,14 +107,14 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): @property def recipients(self): """tagged users who definitely need to get this status in broadcast""" - mentions = [u for u in self.mention_users.all() if not u.local] + mentions = {u for u in self.mention_users.all() if not u.local} if ( hasattr(self, "reply_parent") and self.reply_parent and not self.reply_parent.user.local ): - mentions.append(self.reply_parent.user) - return list(set(mentions)) + mentions.add(self.reply_parent.user) + return list(mentions) @classmethod def ignore_activity( From 940274b1c22e08fc870e92cc95e5ae6a95f5297e Mon Sep 17 00:00:00 2001 From: Braden Solt Date: Fri, 26 Jan 2024 15:47:55 -0700 Subject: [PATCH 18/23] classes that fix widths --- bookwyrm/templates/confirm_email/confirm_email.html | 4 ++-- bookwyrm/templates/landing/invite.html | 4 ++-- bookwyrm/templates/landing/login.html | 12 +++++++----- bookwyrm/templates/landing/password_reset.html | 4 ++-- bookwyrm/templates/landing/reactivate.html | 12 +++++++----- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/bookwyrm/templates/confirm_email/confirm_email.html b/bookwyrm/templates/confirm_email/confirm_email.html index abdd3a734..49a1ebd2d 100644 --- a/bookwyrm/templates/confirm_email/confirm_email.html +++ b/bookwyrm/templates/confirm_email/confirm_email.html @@ -6,8 +6,8 @@ {% block content %}

    {% trans "Confirm your email address" %}

    -
    -
    +
    +

    {% trans "A confirmation code has been sent to the email address you used to register your account." %}

    diff --git a/bookwyrm/templates/landing/invite.html b/bookwyrm/templates/landing/invite.html index d56cad38c..3e3ddab85 100644 --- a/bookwyrm/templates/landing/invite.html +++ b/bookwyrm/templates/landing/invite.html @@ -6,8 +6,8 @@ {% block content %}

    {% trans "Create an Account" %}

    -
    -
    +
    +
    {% if valid %}
    diff --git a/bookwyrm/templates/landing/login.html b/bookwyrm/templates/landing/login.html index 369a72bd2..8ea828b74 100644 --- a/bookwyrm/templates/landing/login.html +++ b/bookwyrm/templates/landing/login.html @@ -6,7 +6,7 @@ {% block content %}

    {% trans "Log in" %}

    -
    +
    {% if login_form.non_field_errors %}

    {{ login_form.non_field_errors }}

    {% endif %} @@ -20,13 +20,15 @@
    - +
    - +
    {% include 'snippets/form_errors.html' with errors_list=login_form.password.errors id="desc_password" %} @@ -58,10 +60,10 @@ {% include 'snippets/about.html' %}

    - {% trans "More about this site" %} + {% trans "More about this site" %}

    -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/bookwyrm/templates/landing/password_reset.html b/bookwyrm/templates/landing/password_reset.html index 786eaa0ab..2f41c5505 100644 --- a/bookwyrm/templates/landing/password_reset.html +++ b/bookwyrm/templates/landing/password_reset.html @@ -4,8 +4,8 @@ {% block title %}{% trans "Reset Password" %}{% endblock %} {% block content %} -
    -
    +
    +

    {% trans "Reset Password" %}

    diff --git a/bookwyrm/templates/landing/reactivate.html b/bookwyrm/templates/landing/reactivate.html index da9e0b050..adb41238f 100644 --- a/bookwyrm/templates/landing/reactivate.html +++ b/bookwyrm/templates/landing/reactivate.html @@ -6,7 +6,7 @@ {% block content %}

    {% trans "Reactivate Account" %}

    -
    +
    {% if login_form.non_field_errors %}

    {{ login_form.non_field_errors }}

    {% endif %} @@ -16,13 +16,15 @@
    - +
    - +
    {% include 'snippets/form_errors.html' with errors_list=login_form.password.errors id="desc_password" %} @@ -51,10 +53,10 @@ {% include 'snippets/about.html' %}

    - {% trans "More about this site" %} + {% trans "More about this site" %}

    -{% endblock %} +{% endblock %} \ No newline at end of file From 6d5752fb4ee72287ed15b84726872a4608842159 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Feb 2024 07:40:23 -0800 Subject: [PATCH 19/23] Adds merge migration for page numbering fix --- bookwyrm/migrations/0193_merge_20240203_1539.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bookwyrm/migrations/0193_merge_20240203_1539.py diff --git a/bookwyrm/migrations/0193_merge_20240203_1539.py b/bookwyrm/migrations/0193_merge_20240203_1539.py new file mode 100644 index 000000000..a88568ba1 --- /dev/null +++ b/bookwyrm/migrations/0193_merge_20240203_1539.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.23 on 2024-02-03 15:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0192_make_page_positions_text"), + ("bookwyrm", "0192_sitesettings_user_exports_enabled"), + ] + + operations = [] From a1ac9494b28ecd1a1674926d7aad8e82d2502dcf Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Feb 2024 08:00:07 -0800 Subject: [PATCH 20/23] Allow admins to un-schedule tasks --- bookwyrm/templates/settings/schedules.html | 11 +++++++++++ bookwyrm/urls.py | 2 +- bookwyrm/views/admin/schedule.py | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/settings/schedules.html b/bookwyrm/templates/settings/schedules.html index fe096092d..20ced4b30 100644 --- a/bookwyrm/templates/settings/schedules.html +++ b/bookwyrm/templates/settings/schedules.html @@ -61,7 +61,18 @@ {{ task.interval.id }} + + {% if task.enabled %} + + {% endif %} {{ task.enabled|yesno }} + + {% if task.name != "celery.backend_cleanup" %} + + {% csrf_token %} + + + {% endif %} {% empty %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 64742347a..a40dcebea 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -360,7 +360,7 @@ urlpatterns = [ r"^settings/celery/ping/?$", views.celery_ping, name="settings-celery-ping" ), re_path( - r"^settings/schedules/?$", + r"^settings/schedules/(?P\d+)?$", views.ScheduledTasks.as_view(), name="settings-schedules", ), diff --git a/bookwyrm/views/admin/schedule.py b/bookwyrm/views/admin/schedule.py index ce5944ee5..c654dca9a 100644 --- a/bookwyrm/views/admin/schedule.py +++ b/bookwyrm/views/admin/schedule.py @@ -1,5 +1,6 @@ """ Scheduled celery tasks """ from django.contrib.auth.decorators import login_required, permission_required +from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils.decorators import method_decorator from django.views import View @@ -21,3 +22,10 @@ class ScheduledTasks(View): data["tasks"] = PeriodicTask.objects.all() data["schedules"] = IntervalSchedule.objects.all() return TemplateResponse(request, "settings/schedules.html", data) + + # pylint: disable=unused-argument + def post(self, request, task_id): + """un-schedule a task""" + task = PeriodicTask.objects.get(id=task_id) + task.delete() + return redirect("settings-schedules") From 4e2b8af1479bd35bf2b5c5973ff0ae2b4bb1a4fc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Feb 2024 08:02:51 -0800 Subject: [PATCH 21/23] Adds merge migration --- bookwyrm/migrations/0193_merge_20240203_1602.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 bookwyrm/migrations/0193_merge_20240203_1602.py diff --git a/bookwyrm/migrations/0193_merge_20240203_1602.py b/bookwyrm/migrations/0193_merge_20240203_1602.py new file mode 100644 index 000000000..e5f760539 --- /dev/null +++ b/bookwyrm/migrations/0193_merge_20240203_1602.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.23 on 2024-02-03 16:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0192_rename_version_sitesettings_available_version"), + ("bookwyrm", "0192_sitesettings_user_exports_enabled"), + ] + + operations = [] From 748c9349865f063689adcaa61e46a26fa3e3bcae Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Feb 2024 08:20:12 -0800 Subject: [PATCH 22/23] Merge migrations upon merge migrations --- ...193_merge_20240203_1602.py => 0194_merge_20240203_1619.py} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bookwyrm/migrations/{0193_merge_20240203_1602.py => 0194_merge_20240203_1619.py} (63%) diff --git a/bookwyrm/migrations/0193_merge_20240203_1602.py b/bookwyrm/migrations/0194_merge_20240203_1619.py similarity index 63% rename from bookwyrm/migrations/0193_merge_20240203_1602.py rename to bookwyrm/migrations/0194_merge_20240203_1619.py index e5f760539..a5c18e300 100644 --- a/bookwyrm/migrations/0193_merge_20240203_1602.py +++ b/bookwyrm/migrations/0194_merge_20240203_1619.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.23 on 2024-02-03 16:02 +# Generated by Django 3.2.23 on 2024-02-03 16:19 from django.db import migrations @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ ("bookwyrm", "0192_rename_version_sitesettings_available_version"), - ("bookwyrm", "0192_sitesettings_user_exports_enabled"), + ("bookwyrm", "0193_merge_20240203_1539"), ] operations = [] From db629255dba0546e4a1a59cb89e12167b118a66d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 3 Feb 2024 18:27:21 -0800 Subject: [PATCH 23/23] Fixes version number mistakenly reverted --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ee6cdce3c..7486fdbc5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.1 +0.7.2