+
diff --git a/bookwyrm/templates/notifications/items/leave.html b/bookwyrm/templates/notifications/items/leave.html
index 422a31de..c17a1986 100644
--- a/bookwyrm/templates/notifications/items/leave.html
+++ b/bookwyrm/templates/notifications/items/leave.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% load utilities %}
diff --git a/bookwyrm/templates/notifications/items/mention.html b/bookwyrm/templates/notifications/items/mention.html
index cda77163..ead3c8a6 100644
--- a/bookwyrm/templates/notifications/items/mention.html
+++ b/bookwyrm/templates/notifications/items/mention.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% load utilities %}
diff --git a/bookwyrm/templates/notifications/items/remove.html b/bookwyrm/templates/notifications/items/remove.html
index eba18fd8..84160c7b 100644
--- a/bookwyrm/templates/notifications/items/remove.html
+++ b/bookwyrm/templates/notifications/items/remove.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% load utilities %}
diff --git a/bookwyrm/templates/notifications/items/reply.html b/bookwyrm/templates/notifications/items/reply.html
index 883bbbb5..0aa664ce 100644
--- a/bookwyrm/templates/notifications/items/reply.html
+++ b/bookwyrm/templates/notifications/items/reply.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% load utilities %}
diff --git a/bookwyrm/templates/notifications/items/report.html b/bookwyrm/templates/notifications/items/report.html
index f537b525..fdd5f009 100644
--- a/bookwyrm/templates/notifications/items/report.html
+++ b/bookwyrm/templates/notifications/items/report.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
diff --git a/bookwyrm/templates/notifications/items/update.html b/bookwyrm/templates/notifications/items/update.html
index be796b78..7fc52cef 100644
--- a/bookwyrm/templates/notifications/items/update.html
+++ b/bookwyrm/templates/notifications/items/update.html
@@ -1,4 +1,4 @@
-{% extends 'notifications/items/item_layout.html' %}
+{% extends 'notifications/items/layout.html' %}
{% load i18n %}
{% load utilities %}
diff --git a/bookwyrm/templates/book/delete_readthrough_modal.html b/bookwyrm/templates/readthrough/delete_readthrough_modal.html
similarity index 100%
rename from bookwyrm/templates/book/delete_readthrough_modal.html
rename to bookwyrm/templates/readthrough/delete_readthrough_modal.html
diff --git a/bookwyrm/templates/readthrough/readthrough.html b/bookwyrm/templates/readthrough/readthrough.html
new file mode 100644
index 00000000..0b42017e
--- /dev/null
+++ b/bookwyrm/templates/readthrough/readthrough.html
@@ -0,0 +1,15 @@
+{% extends 'layout.html' %}
+{% load i18n %}
+{% load utilities %}
+
+{% block title %}
+{% blocktrans trimmed with title=book|book_title %}
+Update read dates for "
{{ title }} "
+{% endblocktrans %}
+{% endblock %}
+
+{% block content %}
+
+{% include "readthrough/readthrough_modal.html" with book=book active=True static=True %}
+
+{% endblock %}
diff --git a/bookwyrm/templates/snippets/readthrough_form.html b/bookwyrm/templates/readthrough/readthrough_form.html
similarity index 94%
rename from bookwyrm/templates/snippets/readthrough_form.html
rename to bookwyrm/templates/readthrough/readthrough_form.html
index 295ad7c6..1558dada 100644
--- a/bookwyrm/templates/snippets/readthrough_form.html
+++ b/bookwyrm/templates/readthrough/readthrough_form.html
@@ -4,6 +4,7 @@
{% csrf_token %}
+
{% trans "Started reading" %}
diff --git a/bookwyrm/templates/book/readthrough.html b/bookwyrm/templates/readthrough/readthrough_list.html
similarity index 77%
rename from bookwyrm/templates/book/readthrough.html
rename to bookwyrm/templates/readthrough/readthrough_list.html
index e711ecd0..9f9db9a5 100644
--- a/bookwyrm/templates/book/readthrough.html
+++ b/bookwyrm/templates/readthrough/readthrough_list.html
@@ -3,7 +3,7 @@
{% load tz %}
{% load utilities %}
-
+
{% trans "Progress Updates:" %}
@@ -58,7 +58,11 @@
{% trans "Edit read dates" as button_text %}
- {% include 'snippets/toggle/toggle_button.html' with class="is-small" text=button_text icon="pencil" controls_text="edit_readthrough" controls_uid=readthrough.id focus="edit_readthrough" %}
+
+
+ {{ button_text }}
+
+
{% trans "Delete these read dates" as button_text %}
@@ -74,16 +78,7 @@
-
-
{% trans "Edit read dates" %}
-
-
-{% join "delete_readthrough" readthrough.id as modal_id %}
-{% include 'book/delete_readthrough_modal.html' with id=modal_id %}
+{% join "edit_readthrough" readthrough.id as edit_modal_id %}
+{% include "readthrough/readthrough_modal.html" with readthrough=readthrough id=edit_modal_id %}
+{% join "delete_readthrough" readthrough.id as delete_modal_id %}
+{% include 'readthrough/delete_readthrough_modal.html' with id=delete_modal_id %}
diff --git a/bookwyrm/templates/readthrough/readthrough_modal.html b/bookwyrm/templates/readthrough/readthrough_modal.html
new file mode 100644
index 00000000..07d27b66
--- /dev/null
+++ b/bookwyrm/templates/readthrough/readthrough_modal.html
@@ -0,0 +1,80 @@
+{% extends "components/modal.html" %}
+{% load i18n %}
+{% load utilities %}
+
+{% block modal-title %}
+
+{% if readthrough %}
+{% blocktrans trimmed with title=book|book_title %}
+ Update read dates for "
{{ title }} "
+{% endblocktrans %}
+{% else %}
+{% blocktrans trimmed with title=book|book_title %}
+ Add read dates for "
{{ title }} "
+{% endblocktrans %}
+{% endif %}
+
+{% endblock %}
+
+{% block modal-form-open %}
+
+{% endblock %}
diff --git a/bookwyrm/templates/search/book.html b/bookwyrm/templates/search/book.html
index 0ce43676..ab62d473 100644
--- a/bookwyrm/templates/search/book.html
+++ b/bookwyrm/templates/search/book.html
@@ -75,9 +75,11 @@
diff --git a/bookwyrm/templates/settings/link_domains/link_table.html b/bookwyrm/templates/settings/link_domains/link_table.html
index 680132fd..62fa17ee 100644
--- a/bookwyrm/templates/settings/link_domains/link_table.html
+++ b/bookwyrm/templates/settings/link_domains/link_table.html
@@ -1,7 +1,7 @@
{% load i18n %}
{% load utilities %}
-
+
{% trans "URL" %}
{% trans "Added by" %}
@@ -9,7 +9,7 @@
{% trans "Book" %}
{% block additional_headers %}{% endblock %}
- {% for link in links%}
+ {% for link in links %}
{{ link.url }}
@@ -24,13 +24,19 @@
- {% if link.filelink.filetype %}
+ {% if link.filelink.book %}
{% with book=link.filelink.book %}
- {% include "snippets/book_titleby.html" with book=book %}
+ {% include "snippets/book_titleby.html" with book=book %}
{% endwith %}
{% endif %}
+
{% block additional_data %}{% endblock %}
{% endfor %}
+ {% if not links %}
+
+ {% trans "No links available for this domain." %}
+
+ {% endif %}
diff --git a/bookwyrm/templates/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html
index 0184ab1d..0e295a87 100644
--- a/bookwyrm/templates/shelf/shelf.html
+++ b/bookwyrm/templates/shelf/shelf.html
@@ -19,6 +19,17 @@
+
+
+
+
@@ -34,15 +45,7 @@
href="{{ shelf_tab.local_path }}"
{% if shelf_tab.identifier == shelf.identifier %} aria-current="page"{% endif %}
>
- {% if shelf_tab.identifier == 'to-read' %}
- {% trans "To Read" %}
- {% elif shelf_tab.identifier == 'reading' %}
- {% trans "Currently Reading" %}
- {% elif shelf_tab.identifier == 'read' %}
- {% trans "Read" %}
- {% else %}
- {{ shelf_tab.name }}
- {% endif %}
+ {% include 'user/books_header.html' with shelf=shelf_tab %}
{% endfor %}
diff --git a/bookwyrm/templates/snippets/filters_panel/filters_panel.html b/bookwyrm/templates/snippets/filters_panel/filters_panel.html
index 80e86892..84b27163 100644
--- a/bookwyrm/templates/snippets/filters_panel/filters_panel.html
+++ b/bookwyrm/templates/snippets/filters_panel/filters_panel.html
@@ -3,16 +3,15 @@
{% trans "Filters" %}
-
{% if filters_applied %}
- {{ _("Filters are applied") }}
+ {% trans "Filters are applied" %}
{% endif %}
- {% if request.GET %}
+ {% if method != "post" and request.GET %}
{% trans "Filters are applied" %}
diff --git a/bookwyrm/templates/snippets/follow_button.html b/bookwyrm/templates/snippets/follow_button.html
index f7025bba..0482bde0 100644
--- a/bookwyrm/templates/snippets/follow_button.html
+++ b/bookwyrm/templates/snippets/follow_button.html
@@ -1,13 +1,18 @@
{% load i18n %}
+{% load interaction %}
{% if request.user == user or not request.user.is_authenticated %}
-{% elif user in request.user.blocks.all %}
+{# nothing to see here -- either it's yourself or your logged out #}
+{% else %}
+
+{% get_relationship user as relationship %}
+{% if relationship.is_blocked %}
{% include 'snippets/block_button.html' with blocks=True %}
{% else %}
+
+{% endif %}
+
{% endif %}
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index 85ecc4ee..323e04a2 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -25,10 +25,7 @@
- {% if shelf.identifier == 'to-read' %}{% trans "To Read" %}
- {% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %}
- {% elif shelf.identifier == 'read' %}{% trans "Read" %}
- {% else %}{{ shelf.name }}{% endif %}
+ {% include "snippets/translated_shelf_name.html" with shelf=shelf %}
@@ -41,20 +38,23 @@
{% trans "Start reading" as button_text %}
{% url 'reading-status' 'start' book.id as fallback_url %}
-{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="start_reading" controls_uid=uuid focus="modal_title_start_reading" disabled=is_current fallback_url=fallback_url %}
+{% join "start_reading" uuid as modal_id %}
+{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
{% elif shelf.identifier == 'read' %}
{% trans "Read" as button_text %}
{% url 'reading-status' 'finish' book.id as fallback_url %}
-{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="finish_reading" controls_uid=uuid focus="modal_title_finish_reading" disabled=is_current fallback_url=fallback_url %}
+{% join "finish_reading" uuid as modal_id %}
+{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
{% elif shelf.identifier == 'to-read' %}
{% trans "Want to read" as button_text %}
{% url 'reading-status' 'want' book.id as fallback_url %}
-{% include 'snippets/toggle/toggle_button.html' with class=button_class text=button_text controls_text="want_to_read" controls_uid=uuid focus="modal_title_want_to_read" disabled=is_current fallback_url=fallback_url %}
+{% join "want_to_read" uuid as modal_id %}
+{% include 'snippets/shelve_button/modal_button.html' with class=button_class fallback_url=fallback_url %}
{% endif %}
@@ -95,7 +95,7 @@
{% include 'snippets/reading_modals/start_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id refresh=True class="" %}
{% join "finish_reading" uuid as modal_id %}
-{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
+{% include 'snippets/reading_modals/finish_reading_modal.html' with book=active_shelf.book id=modal_id move_from=current.id readthrough=readthrough refresh=True class="" %}
{% endwith %}
{% endblock %}
diff --git a/bookwyrm/templates/snippets/translated_shelf_name.html b/bookwyrm/templates/snippets/translated_shelf_name.html
new file mode 100644
index 00000000..4da47e37
--- /dev/null
+++ b/bookwyrm/templates/snippets/translated_shelf_name.html
@@ -0,0 +1,12 @@
+{% load i18n %}
+{% if shelf.identifier == 'all' %}
+ {% trans "All books" %}
+{% elif shelf.identifier == 'to-read' %}
+ {% trans "To Read" %}
+{% elif shelf.identifier == 'reading' %}
+ {% trans "Currently Reading" %}
+{% elif shelf.identifier == 'read' %}
+ {% trans "Read" %}
+{% else %}
+ {{ shelf.name }}
+{% endif %}
diff --git a/bookwyrm/templates/user/books_header.html b/bookwyrm/templates/user/books_header.html
index 7311e242..bd01e6b9 100644
--- a/bookwyrm/templates/user/books_header.html
+++ b/bookwyrm/templates/user/books_header.html
@@ -1,16 +1,10 @@
{% load i18n %}
{% if is_self %}
-{% if shelf.identifier == 'to-read' %}
-{% trans "To Read" %}
-{% elif shelf.identifier == 'reading' %}
-{% trans "Currently Reading" %}
-{% elif shelf.identifier == 'read' %}
-{% trans "Read" %}
-{% elif shelf.identifier == 'all' %}
-{% trans "Your books" %}
+ {% if shelf.identifier == 'all' %}
+ {% trans "Your books" %}
+ {% else %}
+ {% include "snippets/translated_shelf_name.html" with shelf=shelf %}
+ {% endif %}
{% else %}
-{{ shelf.name }}
-{% endif %}
-{% else %}
-{% blocktrans with username=user.display_name %}{{ username }}'s books{% endblocktrans %}
+ {% blocktrans with username=user.display_name %}{{ username }}'s books{% endblocktrans %}
{% endif %}
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index c6781f5a..a3e89d9e 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -3,6 +3,7 @@ from django import template
from django.db.models import Avg, StdDev, Count, F, Q
from bookwyrm import models
+from bookwyrm.utils import cache
from bookwyrm.views.feed import get_suggested_books
@@ -130,35 +131,55 @@ def related_status(notification):
@register.simple_tag(takes_context=True)
def active_shelf(context, book):
"""check what shelf a user has a book on, if any"""
- if hasattr(book, "current_shelves"):
- read_shelves = [
- s
- for s in book.current_shelves
- if s.shelf.identifier in models.Shelf.READ_STATUS_IDENTIFIERS
- ]
- return read_shelves[0] if len(read_shelves) else {"book": book}
-
- shelf = (
- models.ShelfBook.objects.filter(
- shelf__user=context["request"].user,
- book__parent_work__editions=book,
+ user = context["request"].user
+ return (
+ cache.get_or_set(
+ f"active_shelf-{user.id}-{book.id}",
+ lambda u, b: (
+ models.ShelfBook.objects.filter(
+ shelf__user=u,
+ book__parent_work__editions=b,
+ ).first()
+ ),
+ user,
+ book,
+ timeout=15552000,
)
- .select_related("book", "shelf")
- .first()
+ or {"book": book}
)
- return shelf if shelf else {"book": book}
@register.simple_tag(takes_context=False)
def latest_read_through(book, user):
"""the most recent read activity"""
- if hasattr(book, "active_readthroughs"):
- return book.active_readthroughs[0] if len(book.active_readthroughs) else None
+ return cache.get_or_set(
+ f"latest_read_through-{user.id}-{book.id}",
+ lambda u, b: (
+ models.ReadThrough.objects.filter(user=u, book=b, is_active=True)
+ .order_by("-start_date")
+ .first()
+ ),
+ user,
+ book,
+ timeout=15552000,
+ )
- return (
- models.ReadThrough.objects.filter(user=user, book=book, is_active=True)
- .order_by("-start_date")
- .first()
+
+@register.simple_tag(takes_context=False)
+def get_landing_books():
+ """list of books for the landing page"""
+ return list(
+ set(
+ models.Edition.objects.filter(
+ review__published_date__isnull=False,
+ review__deleted=False,
+ review__user__local=True,
+ review__privacy__in=["public", "unlisted"],
+ )
+ .exclude(cover__exact="")
+ .distinct()
+ .order_by("-review__published_date")[:6]
+ )
)
diff --git a/bookwyrm/templatetags/interaction.py b/bookwyrm/templatetags/interaction.py
index 90309aaf..89a25420 100644
--- a/bookwyrm/templatetags/interaction.py
+++ b/bookwyrm/templatetags/interaction.py
@@ -1,8 +1,8 @@
""" template filters for status interaction buttons """
from django import template
-from django.core.cache import cache
from bookwyrm import models
+from bookwyrm.utils.cache import get_or_set
register = template.Library()
@@ -11,20 +11,23 @@ register = template.Library()
@register.filter(name="liked")
def get_user_liked(user, status):
"""did the given user fav a status?"""
- return cache.get_or_set(
+ return get_or_set(
f"fav-{user.id}-{status.id}",
- models.Favorite.objects.filter(user=user, status=status).exists(),
- 259200,
+ lambda u, s: models.Favorite.objects.filter(user=u, status=s).exists(),
+ user,
+ status,
+ timeout=259200,
)
@register.filter(name="boosted")
def get_user_boosted(user, status):
"""did the given user fav a status?"""
- return cache.get_or_set(
+ return get_or_set(
f"boost-{user.id}-{status.id}",
- status.boosters.filter(user=user).exists(),
- 259200,
+ lambda u: status.boosters.filter(user=u).exists(),
+ user,
+ timeout=259200,
)
@@ -32,3 +35,32 @@ def get_user_boosted(user, status):
def get_user_saved_lists(user, book_list):
"""did the user save a list"""
return user.saved_lists.filter(id=book_list.id).exists()
+
+
+@register.simple_tag(takes_context=True)
+def get_relationship(context, user_object):
+ """caches the relationship between the logged in user and another user"""
+ user = context["request"].user
+ return get_or_set(
+ f"relationship-{user.id}-{user_object.id}",
+ get_relationship_name,
+ user,
+ user_object,
+ timeout=259200,
+ )
+
+
+def get_relationship_name(user, user_object):
+ """returns the relationship type"""
+ types = {
+ "is_following": False,
+ "is_follow_pending": False,
+ "is_blocked": False,
+ }
+ if user_object in user.blocks.all():
+ types["is_blocked"] = True
+ elif user_object in user.following.all():
+ types["is_following"] = True
+ elif user_object in user.follower_requests.all():
+ types["is_follow_pending"] = True
+ return types
diff --git a/bookwyrm/tests/views/admin/test_link_domains.py b/bookwyrm/tests/views/admin/test_link_domains.py
index 8c972ea1..5d440dc5 100644
--- a/bookwyrm/tests/views/admin/test_link_domains.py
+++ b/bookwyrm/tests/views/admin/test_link_domains.py
@@ -29,6 +29,7 @@ class LinkDomainViews(TestCase):
models.FileLink.objects.create(
book=self.book,
url="https://beep.com/book/1",
+ added_by=self.local_user,
)
models.SiteSettings.objects.create()
diff --git a/bookwyrm/tests/views/admin/test_reports.py b/bookwyrm/tests/views/admin/test_reports.py
index 137d17cb..d0f2e9d9 100644
--- a/bookwyrm/tests/views/admin/test_reports.py
+++ b/bookwyrm/tests/views/admin/test_reports.py
@@ -37,7 +37,7 @@ class ReportViews(TestCase):
def test_reports_page(self):
"""there are so many views, this just makes sure it LOADS"""
- view = views.Reports.as_view()
+ view = views.ReportsAdmin.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
@@ -49,7 +49,7 @@ class ReportViews(TestCase):
def test_reports_page_with_data(self):
"""there are so many views, this just makes sure it LOADS"""
- view = views.Reports.as_view()
+ view = views.ReportsAdmin.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
@@ -62,7 +62,7 @@ class ReportViews(TestCase):
def test_report_page(self):
"""there are so many views, this just makes sure it LOADS"""
- view = views.Report.as_view()
+ view = views.ReportAdmin.as_view()
request = self.factory.get("")
request.user = self.local_user
request.user.is_superuser = True
@@ -76,7 +76,7 @@ class ReportViews(TestCase):
def test_report_comment(self):
"""comment on a report"""
- view = views.Report.as_view()
+ view = views.ReportAdmin.as_view()
request = self.factory.post("", {"note": "hi"})
request.user = self.local_user
request.user.is_superuser = True
@@ -97,7 +97,7 @@ class ReportViews(TestCase):
request = self.factory.post("", form.data)
request.user = self.local_user
- views.make_report(request)
+ views.Report.as_view()(request)
report = models.Report.objects.get()
self.assertEqual(report.reporter, self.local_user)
diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py
index 1961bde0..9e051926 100644
--- a/bookwyrm/tests/views/books/test_links.py
+++ b/bookwyrm/tests/views/books/test_links.py
@@ -48,9 +48,9 @@ class LinkViews(TestCase):
models.SiteSettings.objects.create()
- def test_edit_link_page(self):
+ def test_add_link_page(self):
"""there are so many views, this just makes sure it LOADS"""
- view = views.FileLink.as_view()
+ view = views.AddFileLink.as_view()
request = self.factory.get("")
request.user = self.local_user
result = view(request, self.book.id)
@@ -59,14 +59,14 @@ class LinkViews(TestCase):
self.assertEqual(result.status_code, 200)
- def test_edit_link_post(self, *_):
+ def test_add_link_post(self, *_):
"""there are so many views, this just makes sure it LOADS"""
- view = views.FileLink.as_view()
+ view = views.AddFileLink.as_view()
form = forms.FileLinkForm()
form.data["url"] = "https://www.example.com"
form.data["filetype"] = "HTML"
form.data["book"] = self.book.id
- form.data["added_by"] = self.local_user
+ form.data["added_by"] = self.local_user.id
request = self.factory.post("", form.data)
request.user = self.local_user
diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py
index 052b47c4..43b18946 100644
--- a/bookwyrm/tests/views/inbox/test_inbox_update.py
+++ b/bookwyrm/tests/views/inbox/test_inbox_update.py
@@ -6,6 +6,7 @@ from unittest.mock import patch
from django.test import TestCase
from bookwyrm import models, views
+from bookwyrm.activitypub.base_activity import set_related_field
# pylint: disable=too-many-public-methods
@@ -147,6 +148,46 @@ class InboxUpdate(TestCase):
self.assertEqual(book.title, "Piranesi")
self.assertEqual(book.last_edited_by, self.remote_user)
+ def test_update_edition_links(self):
+ """add links to edition"""
+ datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json")
+ bookdata = json.loads(datafile.read_bytes())
+ del bookdata["authors"]
+ # pylint: disable=line-too-long
+ link_data = {
+ "href": "https://openlibrary.org/books/OL11645413M/Queen_Victoria/daisy",
+ "mediaType": "Daisy",
+ "attributedTo": self.remote_user.remote_id
+ }
+ bookdata["fileLinks"] = [link_data]
+
+ models.Work.objects.create(
+ title="Test Work", remote_id="https://bookwyrm.social/book/5988"
+ )
+ book = models.Edition.objects.create(
+ title="Test Book", remote_id="https://bookwyrm.social/book/5989"
+ )
+ self.assertFalse(book.file_links.exists())
+
+ with patch("bookwyrm.activitypub.base_activity.set_related_field.delay") as mock:
+ views.inbox.activity_task(
+ {
+ "type": "Update",
+ "to": [],
+ "cc": [],
+ "actor": "hi",
+ "id": "sdkjf",
+ "object": bookdata,
+ }
+ )
+ args = mock.call_args[0]
+ self.assertEqual(args[0], "FileLink")
+ self.assertEqual(args[1], "Edition")
+ self.assertEqual(args[2], "book")
+ self.assertEqual(args[3], book.remote_id)
+ self.assertEqual(args[4], link_data)
+ # idk how to test that related name works, because of the transaction
+
def test_update_work(self):
"""update an existing edition"""
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
diff --git a/bookwyrm/tests/views/test_reading.py b/bookwyrm/tests/views/test_reading.py
index 0d6c13aa..75986694 100644
--- a/bookwyrm/tests/views/test_reading.py
+++ b/bookwyrm/tests/views/test_reading.py
@@ -231,11 +231,12 @@ class ReadingViews(TestCase):
"finish_date": "2018-03-07",
"book": self.book.id,
"id": "",
+ "user": self.local_user.id,
},
)
request.user = self.local_user
- views.create_readthrough(request)
+ views.ReadThrough.as_view()(request)
readthrough = models.ReadThrough.objects.get()
self.assertEqual(readthrough.start_date.year, 2017)
self.assertEqual(readthrough.start_date.month, 1)
diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py
index 6697c0e0..f4ca3af6 100644
--- a/bookwyrm/tests/views/test_readthrough.py
+++ b/bookwyrm/tests/views/test_readthrough.py
@@ -41,10 +41,8 @@ class ReadThrough(TestCase):
self.assertEqual(self.edition.readthrough_set.count(), 0)
self.client.post(
- "/reading-status/start/{}".format(self.edition.id),
- {
- "start_date": "2020-11-27",
- },
+ f"/reading-status/start/{self.edition.id}",
+ {"start_date": "2020-11-27"},
)
readthroughs = self.edition.readthrough_set.all()
@@ -62,10 +60,8 @@ class ReadThrough(TestCase):
self.assertEqual(self.edition.readthrough_set.count(), 0)
self.client.post(
- "/reading-status/start/{}".format(self.edition.id),
- {
- "start_date": "2020-11-27",
- },
+ f"/reading-status/start/{self.edition.id}",
+ {"start_date": "2020-11-27"},
)
readthroughs = self.edition.readthrough_set.all()
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
index 5ec07289..99060149 100644
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -168,6 +168,7 @@ urlpatterns = [
views.LinkDomain.as_view(),
name="settings-link-domain",
),
+ # pylint: disable=line-too-long
re_path(
r"^setting/link-domains/(?P(pending|approved|blocked))/(?P\d+)/?$",
views.LinkDomain.as_view(),
@@ -468,12 +469,19 @@ urlpatterns = [
views.add_description,
name="add-description",
),
- re_path(rf"{BOOK_PATH}/filelink/?$", views.FileLink.as_view(), name="file-link"),
re_path(
- rf"{BOOK_PATH}/filelink/(?P\d+)/?$",
- views.FileLink.as_view(),
+ rf"{BOOK_PATH}/filelink/?$", views.BookFileLinks.as_view(), name="file-link"
+ ),
+ re_path(
+ rf"{BOOK_PATH}/filelink/(?P\d+)/delete/?$",
+ views.BookFileLinks.as_view(),
name="file-link",
),
+ re_path(
+ rf"{BOOK_PATH}/filelink/add/?$",
+ views.AddFileLink.as_view(),
+ name="file-link-add",
+ ),
re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
re_path(
@@ -500,7 +508,11 @@ urlpatterns = [
# reading progress
re_path(r"^edit-readthrough/?$", views.edit_readthrough, name="edit-readthrough"),
re_path(r"^delete-readthrough/?$", views.delete_readthrough),
- re_path(r"^create-readthrough/?$", views.create_readthrough),
+ re_path(
+ r"^create-readthrough/?$",
+ views.ReadThrough.as_view(),
+ name="create-readthrough",
+ ),
re_path(r"^delete-progressupdate/?$", views.delete_progressupdate),
# shelve actions
re_path(
diff --git a/bookwyrm/utils/cache.py b/bookwyrm/utils/cache.py
new file mode 100644
index 00000000..aebb8e75
--- /dev/null
+++ b/bookwyrm/utils/cache.py
@@ -0,0 +1,11 @@
+""" Custom handler for caching """
+from django.core.cache import cache
+
+
+def get_or_set(cache_key, function, *args, timeout=None):
+ """Django's built-in get_or_set isn't cutting it"""
+ value = cache.get(cache_key)
+ if value is None:
+ value = function(*args)
+ cache.set(cache_key, value, timeout=timeout)
+ return value
diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py
index 449e5111..2ec501de 100644
--- a/bookwyrm/views/__init__.py
+++ b/bookwyrm/views/__init__.py
@@ -37,7 +37,7 @@ from .books.books import (
from .books.books import update_book_from_remote
from .books.edit_book import EditBook, ConfirmEditBook
from .books.editions import Editions, switch_edition
-from .books.links import FileLink
+from .books.links import BookFileLinks, AddFileLink
# landing
from .landing.about import about, privacy, conduct
@@ -94,7 +94,7 @@ from .list import Lists, SavedLists, List, Curate, UserLists
from .list import save_list, unsave_list, delete_list, unsafe_embed_list
from .notifications import Notifications
from .outbox import Outbox
-from .reading import create_readthrough, delete_readthrough, delete_progressupdate
+from .reading import ReadThrough, delete_readthrough, delete_progressupdate
from .reading import ReadingStatus
from .report import Report
from .rss_feed import RssFeed
diff --git a/bookwyrm/views/admin/invite.py b/bookwyrm/views/admin/invite.py
index 8fd68b70..322c5fcb 100644
--- a/bookwyrm/views/admin/invite.py
+++ b/bookwyrm/views/admin/invite.py
@@ -16,7 +16,6 @@ from django.views.decorators.http import require_POST
from bookwyrm import emailing, forms, models
from bookwyrm.settings import PAGE_LENGTH
-from bookwyrm.views import helpers
# pylint: disable= no-self-use
@@ -174,7 +173,6 @@ class InviteRequest(View):
data = {
"request_form": form,
"request_received": received,
- "books": helpers.get_landing_books(),
}
return TemplateResponse(request, "landing/landing.html", data)
diff --git a/bookwyrm/views/books/links.py b/bookwyrm/views/books/links.py
index 1b6818ba..9dca41e4 100644
--- a/bookwyrm/views/books/links.py
+++ b/bookwyrm/views/books/links.py
@@ -7,29 +7,39 @@ from django.views import View
from django.utils.decorators import method_decorator
from bookwyrm import forms, models
-from bookwyrm.activitypub import ActivitypubResponse
# pylint: disable=no-self-use
+class BookFileLinks(View):
+ """View all links"""
+
+ def get(self, request, book_id):
+ """view links"""
+ book = get_object_or_404(models.Edition, id=book_id)
+ return TemplateResponse(request, "book/file_links/edit_links.html", {"book": book})
+
+ def post(self, request, book_id, link_id):
+ """delete link"""
+ link = get_object_or_404(models.FileLink, id=link_id, book=book_id)
+ link.delete()
+ return self.get(request, book_id)
+
+
@method_decorator(login_required, name="dispatch")
@method_decorator(
permission_required("bookwyrm.edit_book", raise_exception=True), name="dispatch"
)
-class FileLink(View):
+class AddFileLink(View):
"""a book! this is the stuff"""
- def get(self, request, book_id=None, link_id=None):
- """info about a book"""
- link = get_object_or_404(models.FileLink, id=link_id) if link_id else None
- if not book_id:
- return ActivitypubResponse(link.to_activity())
-
+ def get(self, request, book_id):
+ """Create link form"""
book = get_object_or_404(models.Edition, id=book_id)
data = {
- "file_link_form": forms.FileLinkForm(instance=link),
+ "file_link_form": forms.FileLinkForm(),
"book": book,
}
- return TemplateResponse(request, "book/file_link_page.html", data)
+ return TemplateResponse(request, "book/file_links/file_link_page.html", data)
@transaction.atomic
def post(self, request, book_id, link_id=None):
@@ -39,7 +49,7 @@ class FileLink(View):
form = forms.FileLinkForm(request.POST, instance=link)
if not form.is_valid():
data = {"file_link_form": form, "book": book}
- return TemplateResponse(request, "book/file_link_page.html", data)
+ return TemplateResponse(request, "book/file_links/file_link_page.html", data)
link = form.save()
book.file_links.add(link)
diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py
index 8cc0aea8..74d867b6 100644
--- a/bookwyrm/views/helpers.py
+++ b/bookwyrm/views/helpers.py
@@ -153,24 +153,6 @@ def is_blocked(viewer, user):
return False
-def get_landing_books():
- """list of books for the landing page"""
-
- return list(
- set(
- models.Edition.objects.filter(
- review__published_date__isnull=False,
- review__deleted=False,
- review__user__local=True,
- review__privacy__in=["public", "unlisted"],
- )
- .exclude(cover__exact="")
- .distinct()
- .order_by("-review__published_date")[:6]
- )
- )
-
-
def load_date_in_user_tz_as_utc(date_str: str, user: models.User) -> datetime:
"""ensures that data is stored consistently in the UTC timezone"""
if not date_str:
diff --git a/bookwyrm/views/landing/landing.py b/bookwyrm/views/landing/landing.py
index c1db28c7..cfd9b48b 100644
--- a/bookwyrm/views/landing/landing.py
+++ b/bookwyrm/views/landing/landing.py
@@ -3,7 +3,6 @@ from django.template.response import TemplateResponse
from django.views import View
from bookwyrm import forms
-from bookwyrm.views import helpers
from bookwyrm.views.feed import Feed
@@ -28,6 +27,5 @@ class Landing(View):
data = {
"register_form": forms.RegisterForm(),
"request_form": forms.InviteRequestForm(),
- "books": helpers.get_landing_books(),
}
return TemplateResponse(request, "landing/landing.html", data)
diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py
index c7eda10e..d90c0e9d 100644
--- a/bookwyrm/views/reading.py
+++ b/bookwyrm/views/reading.py
@@ -1,7 +1,6 @@
""" the good stuff! the books! """
from django.contrib.auth.decorators import login_required
from django.core.cache import cache
-from django.core.cache.utils import make_template_fragment_key
from django.db import transaction
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404, redirect
@@ -10,16 +9,16 @@ from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.http import require_POST
-from bookwyrm import models
+from bookwyrm import forms, models
from bookwyrm.views.shelf.shelf_actions import unshelve
from .status import CreateStatus
from .helpers import get_edition, handle_reading_status, is_api_request
from .helpers import load_date_in_user_tz_as_utc
-@method_decorator(login_required, name="dispatch")
# pylint: disable=no-self-use
# pylint: disable=too-many-return-statements
+@method_decorator(login_required, name="dispatch")
class ReadingStatus(View):
"""consider reading a book"""
@@ -46,12 +45,10 @@ class ReadingStatus(View):
if not identifier:
return HttpResponseBadRequest()
- # invalidate the template cache
- cache_keys = [
- make_template_fragment_key("shelve_button", [request.user.id, book_id]),
- make_template_fragment_key("suggested_books", [request.user.id]),
- ]
- cache.delete_many(cache_keys)
+ # invalidate related caches
+ cache.delete(
+ f"active_shelf-{request.user.id}-{book_id}",
+ )
desired_shelf = get_object_or_404(
models.Shelf, identifier=identifier, user=request.user
@@ -118,6 +115,45 @@ class ReadingStatus(View):
return redirect(referer)
+@method_decorator(login_required, name="dispatch")
+class ReadThrough(View):
+ """Add new read dates"""
+
+ def get(self, request, book_id, readthrough_id=None):
+ """standalone form in case of errors"""
+ book = get_object_or_404(models.Edition, id=book_id)
+ form = forms.ReadThroughForm()
+ data = {"form": form, "book": book}
+ if readthrough_id:
+ data["readthrough"] = get_object_or_404(
+ models.ReadThrough, id=readthrough_id
+ )
+ return TemplateResponse(request, "readthrough/readthrough.html", data)
+
+ def post(self, request):
+ """can't use the form normally because the dates are too finnicky"""
+ book_id = request.POST.get("book")
+ normalized_post = request.POST.copy()
+
+ normalized_post["start_date"] = load_date_in_user_tz_as_utc(
+ request.POST.get("start_date"), request.user
+ )
+ normalized_post["finish_date"] = load_date_in_user_tz_as_utc(
+ request.POST.get("finish_date"), request.user
+ )
+ form = forms.ReadThroughForm(request.POST)
+ if not form.is_valid():
+ book = get_object_or_404(models.Edition, id=book_id)
+ data = {"form": form, "book": book}
+ if request.POST.get("id"):
+ data["readthrough"] = get_object_or_404(
+ models.ReadThrough, id=request.POST.get("id")
+ )
+ return TemplateResponse(request, "readthrough/readthrough.html", data)
+ form.save()
+ return redirect("book", book_id)
+
+
@transaction.atomic
def update_readthrough_on_shelve(
user, annotated_book, status, start_date=None, finish_date=None
@@ -159,27 +195,6 @@ def delete_readthrough(request):
return redirect(request.headers.get("Referer", "/"))
-@login_required
-@require_POST
-def create_readthrough(request):
- """can't use the form because the dates are too finnicky"""
- book = get_object_or_404(models.Edition, id=request.POST.get("book"))
-
- start_date = load_date_in_user_tz_as_utc(
- request.POST.get("start_date"), request.user
- )
- finish_date = load_date_in_user_tz_as_utc(
- request.POST.get("finish_date"), request.user
- )
- models.ReadThrough.objects.create(
- user=request.user,
- book=book,
- start_date=start_date,
- finish_date=finish_date,
- )
- return redirect("book", book.id)
-
-
@login_required
@require_POST
def delete_progressupdate(request):
diff --git a/bookwyrm/views/status.py b/bookwyrm/views/status.py
index bb69d30c..5dc8e8fa 100644
--- a/bookwyrm/views/status.py
+++ b/bookwyrm/views/status.py
@@ -159,6 +159,7 @@ def update_progress(request, book_id): # pylint: disable=unused-argument
@require_POST
def edit_readthrough(request):
"""can't use the form because the dates are too finnicky"""
+ # TODO: remove this, it duplicates the code in the ReadThrough view
readthrough = get_object_or_404(models.ReadThrough, id=request.POST.get("id"))
readthrough.raise_not_editable(request.user)
diff --git a/pytest.ini b/pytest.ini
index 9ef72449..c5cdc35d 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -6,13 +6,18 @@ markers =
integration: marks tests as requiring external resources (deselect with '-m "not integration"')
env =
+ SECRET_KEY = beepbeep
DEBUG = false
- USE_HTTPS=true
+ USE_HTTPS = true
DOMAIN = your.domain.here
BOOKWYRM_DATABASE_BACKEND = postgres
MEDIA_ROOT = images/
CELERY_BROKER = ""
REDIS_BROKER_PORT = 6379
+ REDIS_BROKER_PASSWORD = beep
+ REDIS_ACTIVITY_PORT = 6379
+ REDIS_ACTIVITY_PASSWORD = beep
+ USE_DUMMY_CACHE = true
FLOWER_PORT = 8888
EMAIL_HOST = "smtp.mailgun.org"
EMAIL_PORT = 587
@@ -20,4 +25,3 @@ env =
EMAIL_HOST_PASSWORD = ""
EMAIL_USE_TLS = true
ENABLE_PREVIEW_IMAGES = false
- USE_S3 = false