diff --git a/catalog/templates/discover.html b/catalog/templates/discover.html
index 7e9dad04..ec5f58b2 100644
--- a/catalog/templates/discover.html
+++ b/catalog/templates/discover.html
@@ -102,7 +102,7 @@
{% endif %}
{% if request.user.is_authenticated %}
- {% include "_sidebar.html" with show_progress=1 %}
+ {% include "_sidebar.html" with show_progress=1 identity=request.user.identity %}
{% else %}
{% include "_sidebar_anonymous.html" %}
{% endif %}
diff --git a/catalog/templates/search_results.html b/catalog/templates/search_results.html
index 2648ed3f..baa0ea4d 100644
--- a/catalog/templates/search_results.html
+++ b/catalog/templates/search_results.html
@@ -93,7 +93,7 @@
{% empty %}
无站内条目匹配。
- {% if user.is_authenticated %}系统会尝试搜索其它网站的条目,点击标题可添加到本站。{% endif %}
+ {% if request.user.is_authenticated %}系统会尝试搜索其它网站的条目,点击标题可添加到本站。{% endif %}
如果你在
@@ -116,7 +116,7 @@
{% endif %}
- {% if request.GET.q and user.is_authenticated %}
+ {% if request.GET.q and request.user.is_authenticated %}
diff --git a/common/templates/_sidebar.html b/common/templates/_sidebar.html
index db041be9..b1952131 100644
--- a/common/templates/_sidebar.html
+++ b/common/templates/_sidebar.html
@@ -53,7 +53,7 @@
target="_blank"
rel="noopener"
onclick="window.open(this.href); return false;"
- title="@{{ user.mastodon_acct }}">
+ title="@{{ identity.user.mastodon_acct }}">
{% endif %}
@@ -88,7 +88,7 @@
{% for featured_collection in identity.featured_collections.all %}
{% user_visibility_of featured_collection as visible %}
{% if visible %}
- {% user_stats_of collection=featured_collection user=user as stats %}
+ {% user_stats_of collection=featured_collection identity=identity as stats %}
{% endif %}
{% empty %}
- {% if request.user == user %}
+ {% if request.user == identity.user %}
将自己或他人的收藏单设为目标,这里就会显示进度
{% else %}
暂未设置目标
diff --git a/common/templatetags/mastodon.py b/common/templatetags/mastodon.py
index ef18b5d9..982edf99 100644
--- a/common/templatetags/mastodon.py
+++ b/common/templatetags/mastodon.py
@@ -1,9 +1,7 @@
from django import template
-from django.conf import settings
-from django.template.defaultfilters import stringfilter
from django.utils.translation import gettext_lazy as _
-from users.models import APIdentity, User
+from users.models import APIdentity
register = template.Library()
@@ -16,7 +14,7 @@ def mastodon(domain):
@register.simple_tag(takes_context=True)
def current_user_relationship(context, target_identity: "APIdentity"):
- current_identity = (
+ current_identity: "APIdentity | None" = (
context["request"].user.identity
if context["request"].user.is_authenticated
else None
@@ -24,9 +22,7 @@ def current_user_relationship(context, target_identity: "APIdentity"):
r = {
"requesting": False,
"following": False,
- "unfollowable": False,
"muting": False,
- "unmutable": False,
"rejecting": False,
"status": "",
}
@@ -36,10 +32,9 @@ def current_user_relationship(context, target_identity: "APIdentity"):
) or current_identity.is_blocked_by(target_identity):
r["rejecting"] = True
else:
+ r["requesting"] = current_identity.is_requesting(target_identity)
r["muting"] = current_identity.is_muting(target_identity)
- r["unmutable"] = r["muting"]
r["following"] = current_identity.is_following(target_identity)
- r["unfollowable"] = r["following"]
if r["following"]:
if current_identity.is_followed_by(target_identity):
r["status"] = _("互相关注")
diff --git a/common/utils.py b/common/utils.py
index 578e8341..51564195 100644
--- a/common/utils.py
+++ b/common/utils.py
@@ -1,3 +1,4 @@
+import functools
import uuid
from typing import TYPE_CHECKING
@@ -26,6 +27,27 @@ class HTTPResponseHXRedirect(HttpResponseRedirect):
status_code = 200
+def target_identity_required(func):
+ @functools.wraps(func)
+ def wrapper(request, user_name, *args, **kwargs):
+ from users.models import APIdentity
+ from users.views import render_user_blocked, render_user_not_found
+
+ try:
+ target = APIdentity.get_by_handler(user_name)
+ except APIdentity.DoesNotExist:
+ return render_user_not_found(request)
+ if not target.is_visible_to_user(request.user):
+ return render_user_blocked(request)
+ request.target_identity = target
+ # request.identity = (
+ # request.user.identity if request.user.is_authenticated else None
+ # )
+ return func(request, user_name, *args, **kwargs)
+
+ return wrapper
+
+
class PageLinksGenerator:
# TODO inherit django paginator
"""
diff --git a/developer/templates/oauth2_provider/authorize.html b/developer/templates/oauth2_provider/authorize.html
index e67215c7..47bb4bc4 100644
--- a/developer/templates/oauth2_provider/authorize.html
+++ b/developer/templates/oauth2_provider/authorize.html
@@ -10,7 +10,7 @@
{% csrf_token %}
{% if not application.is_official %}
- {{ application.name }} 是由 @{{ application.user.handler }} 创建和维护的应用程序。
+ {{ application.name }} 是由 @{{ application.user.identity.handler }} 创建和维护的应用程序。
{{ site_name }}无法保证其安全性和有效性,请自行验证确认后再授权。
{% endif %}
diff --git a/journal/templates/collection.html b/journal/templates/collection.html
index 94a2f9f8..a311f771 100644
--- a/journal/templates/collection.html
+++ b/journal/templates/collection.html
@@ -115,7 +115,7 @@
- {% if request.user == collection.owner %}
+ {% if request.user.identity == collection.owner %}
{% trans '编辑' %}
@@ -129,7 +129,7 @@
创建于 {{ collection.created_time | date }}
- {% include "_sidebar.html" with user=collection.owner show_profile=1 %}
+ {% include "_sidebar.html" with identity=collection.owner show_profile=1 %}
{% include "_footer.html" %}