diff --git a/catalog/templates/_item_comments.html b/catalog/templates/_item_comments.html index 07dc3622..c0bb78f1 100644 --- a/catalog/templates/_item_comments.html +++ b/catalog/templates/_item_comments.html @@ -49,6 +49,7 @@ {% if comment.latest_post %} {% include "action_reply_piece.html" with post=comment.latest_post piece=comment %} {% include "action_like_post.html" with post=comment.latest_post %} + {% include "action_boost_post.html" with post=comment.latest_post %} {% include "action_open_post.html" with post=comment.latest_post %} {% endif %} diff --git a/catalog/templates/_item_comments_by_episode.html b/catalog/templates/_item_comments_by_episode.html index 0487894e..52018fec 100644 --- a/catalog/templates/_item_comments_by_episode.html +++ b/catalog/templates/_item_comments_by_episode.html @@ -51,15 +51,12 @@ {% if forloop.counter <= 10 %}
- - {% liked_piece comment as liked %} - {% include 'like_stats.html' with liked=liked piece=comment %} - - - - + {% if comment.latest_post %} + {% include "action_reply_piece.html" with post=comment.latest_post piece=comment %} + {% include "action_like_post.html" with post=comment.latest_post %} + {% include "action_boost_post.html" with post=comment.latest_post %} + {% include "action_open_post.html" with post=comment.latest_post %} + {% endif %} {% if comment.rating_grade %}{{ comment.rating_grade|rating_star }}{% endif %} diff --git a/catalog/templates/_item_reviews.html b/catalog/templates/_item_reviews.html index d14bd0dc..b814afd0 100644 --- a/catalog/templates/_item_reviews.html +++ b/catalog/templates/_item_reviews.html @@ -14,6 +14,7 @@ {% if review.latest_post %} {% include "action_reply_piece.html" with post=review.latest_post piece=review href=review.url %} {% include "action_like_post.html" with post=review.latest_post %} + {% include "action_boost_post.html" with post=review.latest_post %} {% include "action_open_post.html" with post=review.latest_post %} {% endif %} diff --git a/catalog/templates/_item_user_pieces.html b/catalog/templates/_item_user_pieces.html index 3e90664a..c7919dbf 100644 --- a/catalog/templates/_item_user_pieces.html +++ b/catalog/templates/_item_user_pieces.html @@ -59,16 +59,14 @@ hx-target="body" hx-swap="beforeend"> - - {% liked_piece mark.comment as liked %} - {% include 'like_stats.html' with liked=liked piece=mark.comment %} - - - - - {% comment %} {{ mark.comment.created_time|date }} {% endcomment %} + {% if mark.comment.latest_post %} + {% include "action_like_post.html" with post=mark.comment.latest_post %} + {% include "action_boost_post.html" with post=mark.comment.latest_post %} + {% include "action_open_post.html" with post=mark.comment.latest_post %} + {% endif %} + {% comment %} + {{ mark.comment.created_time|date }} + {% endcomment %}

{{ mark.comment.html|safe }}

{% endif %} @@ -82,15 +80,11 @@ hx-target="body" hx-swap="beforeend"> - - {% liked_piece comment as liked %} - {% include 'like_stats.html' with liked=liked piece=comment %} - - - - + {% if comment.latest_post %} + {% include "action_like_post.html" with post=comment.latest_post %} + {% include "action_boost_post.html" with post=comment.latest_post %} + {% include "action_open_post.html" with post=comment.latest_post %} + {% endif %} {% comment %} {{ comment.created_time|date }} {% endcomment %}

@@ -120,16 +114,14 @@ - - {% liked_piece mark.review as liked %} - {% include 'like_stats.html' with liked=liked piece=mark.review %} - - - - + {% if review.latest_post %} + {% include "action_like_post.html" with post=review.latest_post %} + {% include "action_boost_post.html" with post=review.latest_post %} + {% include "action_open_post.html" with post=review.latest_post %} + {% endif %} + {% comment %} {{ mark.review.created_time|date }} + {% endcomment %}

{{ review.title }} diff --git a/catalog/templates/item_mark_list.html b/catalog/templates/item_mark_list.html index ed0c3505..3110eb36 100644 --- a/catalog/templates/item_mark_list.html +++ b/catalog/templates/item_mark_list.html @@ -34,17 +34,12 @@ {% with member.mark as mark %}

- {% if mark.comment %} - - {% liked_piece mark.comment as liked %} - {% include 'like_stats.html' with liked=liked piece=mark.comment %} - + {% if mark.comment.latest_post %} + {% include "action_reply_piece.html" with post=mark.comment.latest_post piece=mark.comment %} + {% include "action_like_post.html" with post=mark.comment.latest_post %} + {% include "action_boost_post.html" with post=mark.comment.latest_post %} {% endif %} - - - + {% include "action_open_post.html" with post=mark.shelfmember.latest_post %} {{ mark.created_time|date }}
@@ -54,6 +49,7 @@ {% if mark.comment.item != item %}{{ mark.comment.item.title }}{% endif %}
{{ mark.comment.html|safe }}
+ {% if mark.comment.latest_post %}
{% endif %}
{% endwith %} {% empty %} diff --git a/catalog/templates/item_review_list.html b/catalog/templates/item_review_list.html index 90e3339e..878d9287 100644 --- a/catalog/templates/item_review_list.html +++ b/catalog/templates/item_review_list.html @@ -28,15 +28,12 @@ {% for review in reviews %}
- - - - - {% liked_piece review as liked %} - {% include 'like_stats.html' with liked=liked piece=review %} - + {% if review.latest_post %} + {% include "action_reply_piece.html" with post=review.latest_post piece=review href=review.url %} + {% include "action_like_post.html" with post=review.latest_post %} + {% include "action_boost_post.html" with post=review.latest_post %} + {% include "action_open_post.html" with post=review.latest_post %} + {% endif %} {{ review.created_time|date }}
diff --git a/catalog/views_edit.py b/catalog/views_edit.py index 9c3de809..8317d732 100644 --- a/catalog/views_edit.py +++ b/catalog/views_edit.py @@ -16,7 +16,7 @@ from .common.models import ExternalResource, IdealIdTypes, IdType from .forms import * from .models import * from .search.views import * -from .sites.imdb import IMDB +from .sites.imdb import IMDB as IMDB _logger = logging.getLogger(__name__) diff --git a/journal/importers/goodreads.py b/journal/importers/goodreads.py index 74a352b5..446f2b79 100644 --- a/journal/importers/goodreads.py +++ b/journal/importers/goodreads.py @@ -132,7 +132,7 @@ class GoodreadsImporter: print(f"Shelf parsing error {url_shelf}") break title = title_elem[0].strip() # type:ignore - print("Shelf title: " + title) + print(f"Shelf title: {title}") except Exception: print(f"Shelf loading/parsing error {url_shelf}") break diff --git a/journal/templates/_list_item.html b/journal/templates/_list_item.html index 344b171d..0d032ae0 100644 --- a/journal/templates/_list_item.html +++ b/journal/templates/_list_item.html @@ -46,17 +46,6 @@ {% if mark.action_label %}
- {% if mark.comment %} - - {% liked_piece mark.comment as liked %} - {% include 'like_stats.html' with liked=liked piece=mark.comment %} - - {% endif %} - - - {{ mark.created_time|date }}
@@ -81,15 +70,6 @@ {% if mark.review %}
- - {% liked_piece mark.review as liked %} - {% include 'like_stats.html' with liked=liked piece=mark.review %} - - - - {{ mark.review.created_time|date }}
diff --git a/journal/templates/action_boost_post.html b/journal/templates/action_boost_post.html new file mode 100644 index 00000000..cdf5b5ce --- /dev/null +++ b/journal/templates/action_boost_post.html @@ -0,0 +1,14 @@ +{% load user_actions %} +{% boosted_post post as boosted %} + + + + + {% if post.stats.boosts > 2 %}{{ post.stats.boosts }}{% endif %} + + diff --git a/journal/templates/action_like_post.html b/journal/templates/action_like_post.html index 1e89f5f8..812d313b 100644 --- a/journal/templates/action_like_post.html +++ b/journal/templates/action_like_post.html @@ -1,8 +1,8 @@ {% load user_actions %} +{% liked_post post as liked %} - {% liked_post post as liked %} {% if liked %} + title="联邦宇宙分享链接"> {% if post.visibility == 1 %} {% elif post.visibility == 2 %} diff --git a/journal/templates/collection.html b/journal/templates/collection.html index 116c55d9..16ac8524 100644 --- a/journal/templates/collection.html +++ b/journal/templates/collection.html @@ -33,10 +33,6 @@

- - {% liked_piece collection as liked %} - {% include 'like_stats.html' with liked=liked piece=collection label='关注' icon='fa-heart' %} - {% if request.user.is_authenticated %} {% include '_feature_stats.html' with featured=featured_since %} @@ -47,6 +43,10 @@ title="分享到联邦宇宙"> {% endif %} + {% if collection.latest_post %} + {% include "action_like_post.html" with post=collection.latest_post %} + {% include "action_boost_post.html" with post=collection.latest_post %} + {% endif %}
{{ collection.title }} {% if collection.visibility > 0 %}{% endif %} diff --git a/journal/templates/replies.html b/journal/templates/replies.html index d5099651..0d6c6c1f 100644 --- a/journal/templates/replies.html +++ b/journal/templates/replies.html @@ -4,6 +4,7 @@ {% include "action_reply_post.html" %} {% include "action_like_post.html" %} + {% include "action_boost_post.html" %} {% include "action_open_post.html" %} @@ -76,7 +77,7 @@

diff --git a/journal/templates/review.html b/journal/templates/review.html index c6da823b..e5b61dbc 100644 --- a/journal/templates/review.html +++ b/journal/templates/review.html @@ -34,10 +34,10 @@

- - {% liked_piece review as liked %} - {% include 'like_stats.html' with liked=liked piece=review icon='fa-heart' %} - + {% if review.latest_post %} + {% include "action_like_post.html" with post=review.latest_post %} + {% include "action_boost_post.html" with post=review.latest_post %} + {% endif %}
{{ review.title }}

diff --git a/journal/templates/user_collection_list.html b/journal/templates/user_collection_list.html index df31d674..571fa384 100644 --- a/journal/templates/user_collection_list.html +++ b/journal/templates/user_collection_list.html @@ -30,16 +30,11 @@ {% for collection in collections %}

- - {% liked_piece collection as liked %} - {% include 'like_stats.html' with liked=liked piece=collection label='关注' icon='fa-heart' %} - - - - - {{ collection.created_time|date }} + {% if collection.latest_post %} + {% include "action_like_post.html" with post=collection.latest_post %} + {% include "action_boost_post.html" with post=collection.latest_post %} + {% include "action_open_post.html" with post=collection.latest_post %} + {% endif %}
{{ collection.title }} {% if liked %} diff --git a/journal/templatetags/user_actions.py b/journal/templatetags/user_actions.py index cc817319..c830bbb2 100644 --- a/journal/templatetags/user_actions.py +++ b/journal/templatetags/user_actions.py @@ -45,3 +45,13 @@ def liked_post(context, post): and user.is_authenticated and Takahe.post_liked_by(post.pk, user.identity.pk) ) + + +@register.simple_tag(takes_context=True) +def boosted_post(context, post): + user = context["request"].user + return ( + user + and user.is_authenticated + and Takahe.post_boosted_by(post.pk, user.identity.pk) + ) diff --git a/journal/urls.py b/journal/urls.py index c7af3dcb..c688f0a0 100644 --- a/journal/urls.py +++ b/journal/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ path("piece//replies", piece_replies, name="piece_replies"), path("post//replies", post_replies, name="post_replies"), path("post//reply", post_reply, name="post_reply"), + path("post//boost", post_boost, name="post_boost"), path("post//like", post_like, name="post_like"), path("post//unlike", post_unlike, name="post_unlike"), path("mark_log//", mark_log, name="mark_log"), diff --git a/journal/views/__init__.py b/journal/views/__init__.py index 536d31be..64653bca 100644 --- a/journal/views/__init__.py +++ b/journal/views/__init__.py @@ -17,7 +17,14 @@ from .collection import ( ) from .common import piece_delete from .mark import comment, like, mark, mark_log, unlike, user_mark_list, wish -from .post import piece_replies, post_like, post_replies, post_reply, post_unlike +from .post import ( + piece_replies, + post_boost, + post_like, + post_replies, + post_reply, + post_unlike, +) from .profile import profile, user_calendar_data from .review import ReviewFeed, review_edit, review_retrieve, user_review_list from .tag import user_tag_edit, user_tag_list, user_tag_member_list diff --git a/journal/views/post.py b/journal/views/post.py index cc10e615..9873b111 100644 --- a/journal/views/post.py +++ b/journal/views/post.py @@ -3,6 +3,7 @@ from django.core.exceptions import BadRequest, ObjectDoesNotExist, PermissionDen from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse from django.utils.translation import gettext_lazy as _ +from django.views.decorators.http import require_http_methods from common.utils import ( AuthedHttpRequest, @@ -10,6 +11,7 @@ from common.utils import ( get_uuid_or_404, target_identity_required, ) +from mastodon.api import boost_toot_later from takahe.utils import Takahe from ..forms import * @@ -35,11 +37,12 @@ def post_replies(request: AuthedHttpRequest, post_id: int): ) +@require_http_methods(["POST"]) @login_required def post_reply(request: AuthedHttpRequest, post_id: int): content = request.POST.get("content", "").strip() visibility = Takahe.Visibilities(int(request.POST.get("visibility", -1))) - if request.method != "POST" or not content: + if not content: raise BadRequest() Takahe.reply_post(post_id, request.user.identity.pk, content, visibility) replies = Takahe.get_replies_for_posts([post_id], request.user.identity.pk) @@ -48,14 +51,24 @@ def post_reply(request: AuthedHttpRequest, post_id: int): ) +@require_http_methods(["POST"]) +@login_required +def post_boost(request: AuthedHttpRequest, post_id: int): + Takahe.boost_post(post_id, request.user.identity.pk) + post_url = request.POST.get("post_url") + if post_url and request.user.mastodon_site: + boost_toot_later(request.user, post_url) + return render(request, "action_boost_post.html", {"post": Takahe.get_post(post_id)}) + + +@require_http_methods(["POST"]) @login_required def post_like(request: AuthedHttpRequest, post_id: int): - if request.method != "POST": - raise BadRequest() Takahe.like_post(post_id, request.user.identity.pk) return render(request, "action_like_post.html", {"post": Takahe.get_post(post_id)}) +@require_http_methods(["POST"]) @login_required def post_unlike(request: AuthedHttpRequest, post_id: int): if request.method != "POST": diff --git a/pyproject.toml b/pyproject.toml index cd6bdd9a..9e8d11e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,8 @@ [tool.pyright] exclude = [ "media", ".venv", ".git", "playground", "catalog/*/tests.py", "neodb", "**/migrations", "**/sites/douban_*", "neodb-takahe" ] +reportIncompatibleVariableOverride = false +reportFunctionMemberAccess = false +reportIncompatibleMethodOverride = false [tool.djlint] ignore="T002,T003,H006,H019,H020,H021,H023,H030,H031" diff --git a/takahe/utils.py b/takahe/utils.py index e6e9e404..5c4ae8d8 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -753,6 +753,15 @@ class Takahe: ): return Takahe.post(identity_pk, "", content, visibility, reply_to_pk=post_pk) + @staticmethod + def boost_post(post_pk: int, identity_pk: int): + return Takahe.interact_post(post_pk, identity_pk, "boost") + + @staticmethod + def post_boosted_by(post_pk: int, identity_pk: int) -> bool: + interaction = Takahe.get_user_interaction(post_pk, identity_pk, "boost") + return interaction is not None and interaction.state in ["new", "fanned_out"] + @staticmethod def like_post(post_pk: int, identity_pk: int): return Takahe.interact_post(post_pk, identity_pk, "like")