diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 57244484..4894452d 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -208,35 +208,34 @@ def set_related_field( model = apps.get_model(f"bookwyrm.{model_name}", require_ready=True) origin_model = apps.get_model(f"bookwyrm.{origin_model_name}", require_ready=True) - with transaction.atomic(): - if isinstance(data, str): - existing = model.find_existing_by_remote_id(data) - if existing: - data = existing.to_activity() - else: - data = get_data(data) - activity = model.activity_serializer(**data) + if isinstance(data, str): + existing = model.find_existing_by_remote_id(data) + if existing: + data = existing.to_activity() + else: + data = get_data(data) + activity = model.activity_serializer(**data) - # this must exist because it's the object that triggered this function - instance = origin_model.find_existing_by_remote_id(related_remote_id) - if not instance: - raise ValueError(f"Invalid related remote id: {related_remote_id}") + # this must exist because it's the object that triggered this function + instance = origin_model.find_existing_by_remote_id(related_remote_id) + if not instance: + raise ValueError(f"Invalid related remote id: {related_remote_id}") - # set the origin's remote id on the activity so it will be there when - # the model instance is created - # edition.parentWork = instance, for example - model_field = getattr(model, related_field_name) - if hasattr(model_field, "activitypub_field"): - setattr( - activity, getattr(model_field, "activitypub_field"), instance.remote_id - ) - item = activity.to_model() + # set the origin's remote id on the activity so it will be there when + # the model instance is created + # edition.parentWork = instance, for example + model_field = getattr(model, related_field_name) + if hasattr(model_field, "activitypub_field"): + setattr( + activity, getattr(model_field, "activitypub_field"), instance.remote_id + ) + item = activity.to_model() - # if the related field isn't serialized (attachments on Status), then - # we have to set it post-creation - if not hasattr(model_field, "activitypub_field"): - setattr(item, related_field_name, instance) - item.save() + # if the related field isn't serialized (attachments on Status), then + # we have to set it post-creation + if not hasattr(model_field, "activitypub_field"): + setattr(item, related_field_name, instance) + item.save() def get_model_from_type(activity_type): diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 0d27fffe..5af7c455 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -492,3 +492,19 @@ class SortListForm(forms.Form): ("descending", _("Descending")), ), ) + + +class ReadThroughForm(CustomForm): + def clean(self): + """make sure the email isn't in use by a registered user""" + cleaned_data = super().clean() + start_date = cleaned_data.get("start_date") + finish_date = cleaned_data.get("finish_date") + if start_date > finish_date: + self.add_error( + "finish_date", _("Reading finish date cannot be before start date.") + ) + + class Meta: + model = models.ReadThrough + fields = ["user", "book", "start_date", "finish_date"] diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index f75918ac..ceb8e0b6 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -1,5 +1,6 @@ """ progress in a book """ from django.core import validators +from django.core.cache import cache from django.db import models from django.db.models import F, Q @@ -30,6 +31,7 @@ class ReadThrough(BookWyrmModel): def save(self, *args, **kwargs): """update user active time""" + cache.delete(f"latest_read_through-{self.user.id}-{self.book.id}") self.user.update_active_date() # an active readthrough must have an unset finish date if self.finish_date: diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index 03417454..e95c38fa 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -1,7 +1,6 @@ """ defines relationships between users """ from django.apps import apps from django.core.cache import cache -from django.core.cache.utils import make_template_fragment_key from django.db import models, transaction, IntegrityError from django.db.models import Q @@ -41,15 +40,12 @@ class UserRelationship(BookWyrmModel): def save(self, *args, **kwargs): """clear the template cache""" # invalidate the template cache - cache_keys = [ - make_template_fragment_key( - "follow_button", [self.user_subject.id, self.user_object.id] - ), - make_template_fragment_key( - "follow_button", [self.user_object.id, self.user_subject.id] - ), - ] - cache.delete_many(cache_keys) + cache.delete_many( + [ + f"relationship-{self.user_subject.id}-{self.user_object.id}", + f"relationship-{self.user_object.id}-{self.user_subject.id}", + ] + ) super().save(*args, **kwargs) class Meta: diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 92ddd294..18c13671 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -755,6 +755,13 @@ ol.ordered-list li::before { padding: 0 0.75em; } +/* Notifications page + ******************************************************************************/ + +.notification a.icon { + text-decoration: none !important; +} + /* Breadcrumbs ******************************************************************************/ diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index 1060f038..c8c78e0e 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -237,29 +237,21 @@

{% trans "Your reading activity" %}

- {% trans "Add read dates" as button_text %} - {% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="plus" class="is-small" controls_text="add_readthrough" focus="add_readthrough_focus_" %} +
- + {% include "readthrough/readthrough_modal.html" with id="add-readthrough" %} + {% if not readthroughs.exists %}

{% trans "You don't have any reading activity for this book." %}

{% endif %} {% for readthrough in readthroughs %} - {% include 'book/readthrough.html' with readthrough=readthrough %} + {% include 'readthrough/readthrough_list.html' with readthrough=readthrough %} {% endfor %} @@ -383,7 +375,7 @@ {% endif %}
- {% include "book/links.html" %} + {% include "book/file_links/links.html" %}
diff --git a/bookwyrm/templates/book/file_link_modal.html b/bookwyrm/templates/book/file_links/add_link_modal.html similarity index 95% rename from bookwyrm/templates/book/file_link_modal.html rename to bookwyrm/templates/book/file_links/add_link_modal.html index 48921bb8..2965142b 100644 --- a/bookwyrm/templates/book/file_link_modal.html +++ b/bookwyrm/templates/book/file_links/add_link_modal.html @@ -7,7 +7,7 @@ {% endblock %} {% block modal-form-open %} -
+ {% endblock %} {% block modal-body %} diff --git a/bookwyrm/templates/book/file_links/edit_links.html b/bookwyrm/templates/book/file_links/edit_links.html new file mode 100644 index 00000000..c56f97a6 --- /dev/null +++ b/bookwyrm/templates/book/file_links/edit_links.html @@ -0,0 +1,82 @@ +{% extends 'layout.html' %} +{% load i18n %} +{% load utilities %} + +{% block title %}{% trans "Edit links" %}{% endblock %} + +{% block content %} + +
+

+ {% blocktrans with title=book|book_title %} + Links for "{{ title }}" + {% endblocktrans %} +

+
+ + + +
+
+ + + + + + + + + {% for link in book.file_links.all %} + + + + + + + + {% endfor %} + {% if not book.file_links.exists %} + + + + {% endif %} +
{% trans "URL" %}{% trans "Added by" %}{% trans "Filetype" %}{% trans "Domain" %}{% trans "Actions" %}
+ {{ link.url }} + + {{ link.added_by.display_name }} + + {{ link.filelink.filetype }} + + {{ link.domain.name }} ({{ link.domain.get_status_display }}) +

+ {% trans "Report spam" %} +

+
+ + {% csrf_token %} + + +
{% trans "No links available for this book." %}
+
+ + {% url 'file-link-add' book.id as fallback_url %} +
+ +
+
+ +{% endblock %} diff --git a/bookwyrm/templates/book/file_link_page.html b/bookwyrm/templates/book/file_links/file_link_page.html similarity index 56% rename from bookwyrm/templates/book/file_link_page.html rename to bookwyrm/templates/book/file_links/file_link_page.html index 26a8d89d..902057af 100644 --- a/bookwyrm/templates/book/file_link_page.html +++ b/bookwyrm/templates/book/file_links/file_link_page.html @@ -6,5 +6,5 @@ {% endblock %} {% block content %} -{% include "book/file_link_modal.html" with book=book active=True static=True id="file-link" %} +{% include "book/file_links/add_link_modal.html" with book=book active=True static=True id="file-link" %} {% endblock %} diff --git a/bookwyrm/templates/book/links.html b/bookwyrm/templates/book/file_links/links.html similarity index 53% rename from bookwyrm/templates/book/links.html rename to bookwyrm/templates/book/file_links/links.html index f87d5681..10a6da2f 100644 --- a/bookwyrm/templates/book/links.html +++ b/bookwyrm/templates/book/file_links/links.html @@ -10,14 +10,16 @@ {% if can_edit_book %}
- {% url 'file-link' book.id as fallback_url %} - + +
{% endif %} @@ -33,14 +35,18 @@ {% for link in links.all %} {% join "verify" link.id as verify_modal %} -{% include "book/link_verification_modal.html" with id=verify_modal %} +{% include "book/file_links/verification_modal.html" with id=verify_modal %} {% endfor %} {% else %} {% trans "No links available" %} {% endif %} -{% if can_edit_book %} -{% include 'book/file_link_modal.html' with book=book id="edit-links" %} +{% if can_edit_book and links.exists %} + + + {% trans "Edit links" %} + +{% include 'book/file_links/add_link_modal.html' with book=book id="add-links" %} {% endif %} {% endif %} diff --git a/bookwyrm/templates/book/link_verification_modal.html b/bookwyrm/templates/book/file_links/verification_modal.html similarity index 95% rename from bookwyrm/templates/book/link_verification_modal.html rename to bookwyrm/templates/book/file_links/verification_modal.html index eab8987b..1d53c1ef 100644 --- a/bookwyrm/templates/book/link_verification_modal.html +++ b/bookwyrm/templates/book/file_links/verification_modal.html @@ -22,7 +22,7 @@ Is that where you'd like to go? {% if request.user.is_authenticated %}
- {% trans "Report spam" %} + {% trans "Report spam" %}
{% endif %} diff --git a/bookwyrm/templates/feed/suggested_books.html b/bookwyrm/templates/feed/suggested_books.html index 899767d1..a3d3f1fa 100644 --- a/bookwyrm/templates/feed/suggested_books.html +++ b/bookwyrm/templates/feed/suggested_books.html @@ -16,10 +16,7 @@ {% with shelf_counter=forloop.counter %}
  • - {% 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 %}

      diff --git a/bookwyrm/templates/landing/landing.html b/bookwyrm/templates/landing/landing.html index 759e8c61..c3771759 100644 --- a/bookwyrm/templates/landing/landing.html +++ b/bookwyrm/templates/landing/landing.html @@ -1,13 +1,17 @@ {% extends 'landing/layout.html' %} {% load i18n %} {% load cache %} +{% load bookwyrm_tags %} + {% block panel %}

      {% trans "Recent Books" %}

      -{% cache 60 * 60 %} +{% get_current_language as LANGUAGE_CODE %} +{% cache 60 * 60 LANGUAGE_CODE %} +{% get_landing_books as books %}
      diff --git a/bookwyrm/templates/notifications/items/accept.html b/bookwyrm/templates/notifications/items/accept.html index 045e2326..5f26008f 100644 --- a/bookwyrm/templates/notifications/items/accept.html +++ b/bookwyrm/templates/notifications/items/accept.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/add.html b/bookwyrm/templates/notifications/items/add.html index 0e653aeb..6a0183eb 100644 --- a/bookwyrm/templates/notifications/items/add.html +++ b/bookwyrm/templates/notifications/items/add.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/boost.html b/bookwyrm/templates/notifications/items/boost.html index 5f8962b3..6bb373ef 100644 --- a/bookwyrm/templates/notifications/items/boost.html +++ b/bookwyrm/templates/notifications/items/boost.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/fav.html b/bookwyrm/templates/notifications/items/fav.html index fbb865e4..58964d03 100644 --- a/bookwyrm/templates/notifications/items/fav.html +++ b/bookwyrm/templates/notifications/items/fav.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/follow.html b/bookwyrm/templates/notifications/items/follow.html index 7220d5d1..3518e7b1 100644 --- a/bookwyrm/templates/notifications/items/follow.html +++ b/bookwyrm/templates/notifications/items/follow.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/follow_request.html b/bookwyrm/templates/notifications/items/follow_request.html index febb0a50..9cec8116 100644 --- a/bookwyrm/templates/notifications/items/follow_request.html +++ b/bookwyrm/templates/notifications/items/follow_request.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/import.html b/bookwyrm/templates/notifications/items/import.html index f3c8b5c0..7f599481 100644 --- a/bookwyrm/templates/notifications/items/import.html +++ b/bookwyrm/templates/notifications/items/import.html @@ -1,4 +1,4 @@ -{% extends 'notifications/items/item_layout.html' %} +{% extends 'notifications/items/layout.html' %} {% load i18n %} {% block primary_link %}{% spaceless %} diff --git a/bookwyrm/templates/notifications/items/invite.html b/bookwyrm/templates/notifications/items/invite.html index abb8cd02..aff416b0 100644 --- a/bookwyrm/templates/notifications/items/invite.html +++ b/bookwyrm/templates/notifications/items/invite.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/join.html b/bookwyrm/templates/notifications/items/join.html index c10def45..82f8a8c5 100644 --- a/bookwyrm/templates/notifications/items/join.html +++ b/bookwyrm/templates/notifications/items/join.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/item_layout.html b/bookwyrm/templates/notifications/items/layout.html similarity index 70% rename from bookwyrm/templates/notifications/items/item_layout.html rename to bookwyrm/templates/notifications/items/layout.html index 506bda8d..6ddbdcc3 100644 --- a/bookwyrm/templates/notifications/items/item_layout.html +++ b/bookwyrm/templates/notifications/items/layout.html @@ -1,9 +1,9 @@ {% load bookwyrm_tags %} {% related_status notification as related_status %} -
      -
      -
      - +
      +
      + 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 %} +