boost
This commit is contained in:
parent
f60da91c52
commit
7f50c1128b
22 changed files with 120 additions and 103 deletions
|
@ -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 %}
|
||||
</span>
|
||||
|
|
|
@ -51,15 +51,12 @@
|
|||
{% if forloop.counter <= 10 %}
|
||||
<section>
|
||||
<span class="action">
|
||||
<span>
|
||||
{% liked_piece comment as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=comment %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if comment.shared_link %} href="{{ comment.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if comment.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
{% 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 %}
|
||||
</span>
|
||||
<span>
|
||||
{% if comment.rating_grade %}{{ comment.rating_grade|rating_star }}{% endif %}
|
||||
|
|
|
@ -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 %}
|
||||
</span>
|
||||
|
|
|
@ -59,16 +59,14 @@
|
|||
hx-target="body"
|
||||
hx-swap="beforeend"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
{% liked_piece mark.comment as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=mark.comment %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if mark.comment.shared_link %} href="{{ mark.comment.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if mark.comment.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
{% comment %} <span class="timestamp">{{ mark.comment.created_time|date }}</span> {% 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 %}
|
||||
<span class="timestamp">{{ mark.comment.created_time|date }}</span>
|
||||
{% endcomment %}
|
||||
</span>
|
||||
<p>{{ mark.comment.html|safe }}</p>
|
||||
{% endif %}
|
||||
|
@ -82,15 +80,11 @@
|
|||
hx-target="body"
|
||||
hx-swap="beforeend"><i class="fa-solid fa-pen-to-square"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
{% liked_piece comment as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=comment %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if comment.shared_link %} href="{{ comment.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if comment.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
{% 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 %} <span class="timestamp">{{ comment.created_time|date }}</span> {% endcomment %}
|
||||
</span>
|
||||
<p>
|
||||
|
@ -120,16 +114,14 @@
|
|||
<i class="fa-solid fa-pen-to-square"></i>
|
||||
</a>
|
||||
</span>
|
||||
<span>
|
||||
{% liked_piece mark.review as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=mark.review %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if mark.review.shared_link %} href="{{ mark.review.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if mark.review.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
{% 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 %}
|
||||
<span class="timestamp">{{ mark.review.created_time|date }}</span>
|
||||
{% endcomment %}
|
||||
</span>
|
||||
<p>
|
||||
<a href="{% url 'journal:review_retrieve' review.uuid %}">{{ review.title }}</a>
|
||||
|
|
|
@ -34,17 +34,12 @@
|
|||
{% with member.mark as mark %}
|
||||
<section>
|
||||
<div class="action">
|
||||
{% if mark.comment %}
|
||||
<span>
|
||||
{% liked_piece mark.comment as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=mark.comment %}
|
||||
</span>
|
||||
{% 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 %}
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if mark.shared_link %} href="{{ mark.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if mark.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
{% include "action_open_post.html" with post=mark.shelfmember.latest_post %}
|
||||
<span class="timestamp">{{ mark.created_time|date }}</span>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -54,6 +49,7 @@
|
|||
{% if mark.comment.item != item %}<a href="{{ mark.comment.item_url }}">{{ mark.comment.item.title }}</a>{% endif %}
|
||||
</div>
|
||||
<div>{{ mark.comment.html|safe }}</div>
|
||||
{% if mark.comment.latest_post %}<div id="replies_{{ mark.comment.latest_post.pk }}"></div>{% endif %}
|
||||
</section>
|
||||
{% endwith %}
|
||||
{% empty %}
|
||||
|
|
|
@ -28,15 +28,12 @@
|
|||
{% for review in reviews %}
|
||||
<section>
|
||||
<div class="action">
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if review.shared_link %} href="{{ review.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if review.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
<span>
|
||||
{% liked_piece review as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=review %}
|
||||
</span>
|
||||
{% 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 %}
|
||||
<span class="timestamp">{{ review.created_time|date }}</span>
|
||||
</div>
|
||||
<div>
|
||||
|
|
|
@ -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__)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -46,17 +46,6 @@
|
|||
{% if mark.action_label %}
|
||||
<section>
|
||||
<div class="action">
|
||||
{% if mark.comment %}
|
||||
<span>
|
||||
{% liked_piece mark.comment as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=mark.comment %}
|
||||
</span>
|
||||
{% endif %}
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if mark.shared_link %} href="{{ mark.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if mark.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
<span class="timestamp">{{ mark.created_time|date }}</span>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -81,15 +70,6 @@
|
|||
{% if mark.review %}
|
||||
<section>
|
||||
<span class="action">
|
||||
<span>
|
||||
{% liked_piece mark.review as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=mark.review %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if mark.review.shared_link %} href="{{ mark.review.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if mark.review.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
<span class="timestamp">{{ mark.review.created_time|date }}</span>
|
||||
</span>
|
||||
<div>
|
||||
|
|
14
journal/templates/action_boost_post.html
Normal file
14
journal/templates/action_boost_post.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% load user_actions %}
|
||||
{% boosted_post post as boosted %}
|
||||
<span hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
{% if not request.user.is_authenticated %}hx-disable{% endif %}>
|
||||
<a hx-post="{% url 'journal:post_boost' post.pk %}"
|
||||
hx-include="[name='post_url']"
|
||||
{% if boosted %}class="activated"{% endif %}
|
||||
title="转播">
|
||||
<input type="hidden" name="post_url" value="{{ post.object_uri }}">
|
||||
<i class="fa-solid fa-retweet"></i>
|
||||
{% if post.stats.boosts > 2 %}<span>{{ post.stats.boosts }}</span>{% endif %}
|
||||
</a>
|
||||
</span>
|
|
@ -1,8 +1,8 @@
|
|||
{% load user_actions %}
|
||||
{% liked_post post as liked %}
|
||||
<span hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
{% if not request.user.is_authenticated %}hx-disable{% endif %}>
|
||||
{% liked_post post as liked %}
|
||||
{% if liked %}
|
||||
<a class="activated"
|
||||
hx-post="{% url 'journal:post_unlike' post.pk %}"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<a target="_blank"
|
||||
rel="noopener"
|
||||
href="{{ post.object_uri }}"
|
||||
title="打开联邦宇宙分享链接">
|
||||
title="联邦宇宙分享链接">
|
||||
{% if post.visibility == 1 %}
|
||||
<i class="fa-solid fa-lock-open"></i>
|
||||
{% elif post.visibility == 2 %}
|
||||
|
|
|
@ -33,10 +33,6 @@
|
|||
<hgroup>
|
||||
<h3>
|
||||
<div class="action">
|
||||
<span>
|
||||
{% liked_piece collection as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=collection label='关注' icon='fa-heart' %}
|
||||
</span>
|
||||
{% if request.user.is_authenticated %}
|
||||
<span>{% include '_feature_stats.html' with featured=featured_since %}</span>
|
||||
<span>
|
||||
|
@ -47,6 +43,10 @@
|
|||
title="分享到联邦宇宙"><i class="fa-solid fa-share-nodes"></i></a>
|
||||
</span>
|
||||
{% 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 %}
|
||||
</div>
|
||||
{{ collection.title }}
|
||||
{% if collection.visibility > 0 %}<small><i class="fa-solid fa-lock"></i></small>{% endif %}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<span class="action">
|
||||
{% include "action_reply_post.html" %}
|
||||
{% include "action_like_post.html" %}
|
||||
{% include "action_boost_post.html" %}
|
||||
{% include "action_open_post.html" %}
|
||||
</span>
|
||||
<span>
|
||||
|
@ -76,7 +77,7 @@
|
|||
</ul>
|
||||
</details>
|
||||
<button class="secondary">
|
||||
<i class="fa-solid fa-reply"></i>
|
||||
<i class="fa-regular fa-paper-plane"></i>
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
|
|
|
@ -34,10 +34,10 @@
|
|||
<hgroup>
|
||||
<h3>
|
||||
<div class="action">
|
||||
<span>
|
||||
{% liked_piece review as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=review icon='fa-heart' %}
|
||||
</span>
|
||||
{% 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 %}
|
||||
</div>
|
||||
{{ review.title }}
|
||||
</h3>
|
||||
|
|
|
@ -30,16 +30,11 @@
|
|||
{% for collection in collections %}
|
||||
<p>
|
||||
<div class="action">
|
||||
<span>
|
||||
{% liked_piece collection as liked %}
|
||||
{% include 'like_stats.html' with liked=liked piece=collection label='关注' icon='fa-heart' %}
|
||||
</span>
|
||||
<span>
|
||||
<a target="_blank"
|
||||
rel="noopener"
|
||||
{% if collection.shared_link %} href="{{ collection.shared_link }}" title="打开联邦宇宙分享链接" {% else %} class="disabled" {% endif %}><i class="fa-solid {% if collection.visibility > 0 %} fa-lock {% else %} fa-globe {% endif %}"></i></a>
|
||||
</span>
|
||||
<span class="timestamp">{{ collection.created_time|date }}</span>
|
||||
{% 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 %}
|
||||
</div>
|
||||
<span><a href="{{ collection.url }}">{{ collection.title }}</a></span>
|
||||
{% if liked %}
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
|
|
@ -26,6 +26,7 @@ urlpatterns = [
|
|||
path("piece/<str:piece_uuid>/replies", piece_replies, name="piece_replies"),
|
||||
path("post/<int:post_id>/replies", post_replies, name="post_replies"),
|
||||
path("post/<int:post_id>/reply", post_reply, name="post_reply"),
|
||||
path("post/<int:post_id>/boost", post_boost, name="post_boost"),
|
||||
path("post/<int:post_id>/like", post_like, name="post_like"),
|
||||
path("post/<int:post_id>/unlike", post_unlike, name="post_unlike"),
|
||||
path("mark_log/<str:item_uuid>/<int:log_id>", mark_log, name="mark_log"),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue