clarify personal tag visibility

This commit is contained in:
Your Name 2023-06-06 21:57:13 -04:00 committed by Henri Dickson
parent b576281126
commit d155523d83
4 changed files with 20 additions and 33 deletions

View file

@ -643,10 +643,6 @@ class ShelfMember(ListMember):
def tags(self):
return self.mark.tags
@property
def public_tags(self):
return self.mark.public_tags
class Shelf(List):
class Meta:
@ -974,7 +970,7 @@ class Tag(List):
class TagManager:
@staticmethod
def public_tags_for_item(item):
def indexable_tags_for_item(item):
tags = (
item.tag_set.all()
.filter(visibility=0)
@ -982,9 +978,13 @@ class TagManager:
.annotate(frequency=Count("owner"))
.order_by("-frequency")[:20]
)
tag_titles = [
t for t in set(map(lambda t: Tag.deep_cleanup_title(t["title"]), tags)) if t
]
tag_titles = sorted(
[
t
for t in set(map(lambda t: Tag.deep_cleanup_title(t["title"]), tags))
if t
]
)
return tag_titles
@staticmethod
@ -1062,18 +1062,8 @@ class TagManager:
]
)
def get_item_public_tags(self, item):
return sorted(
[
m["parent__title"]
for m in TagMember.objects.filter(
parent__owner=self.owner, item=item, visibility=0
).values("parent__title")
]
)
Item.tags = property(TagManager.public_tags_for_item)
Item.tags = property(TagManager.indexable_tags_for_item)
User.tags = property(TagManager.all_tags_for_user)
User.tag_manager = cached_property(TagManager.get_manager_for_user)
User.tag_manager.__set_name__(User, "tag_manager")
@ -1144,10 +1134,6 @@ class Mark:
def tags(self):
return self.owner.tag_manager.get_item_tags(self.item)
@cached_property
def public_tags(self):
return self.owner.tag_manager.get_item_public_tags(self.item)
@cached_property
def rating_grade(self):
return Rating.get_item_rating_by_user(self.item, self.owner)

View file

@ -41,7 +41,7 @@
required=""
id="id_visibility_0"
{% if tag.visibility == 0 %}checked{% endif %}>
</label>
</li>
<li>
@ -52,12 +52,13 @@
required=""
id="id_visibility_2"
{% if tag.visibility != 0 %}checked{% endif %}>
仅自己
个人
</label>
</li>
</ul>
</span>
</div>
<i>个人标签仅限于在个人主页的标签列表里不向他人展示,如果公开标记一个条目时使用这个标签仍会被别人看到。</i>
</div>
<div class="mark-modal__confirm-button">
<input type="submit" class="button float-right" value="保存">

View file

@ -16,7 +16,7 @@
{% endif %}
<br>
<small>
{% if tag.visibility > 0 %}<i class="fa-solid fa-lock"></i>{% endif %}
{% if tag.visibility > 0 %}<i class="fa-solid fa-user" title="个人标签"></i>{% endif %}
{{ user.mastodon_username }}的{% trans '标签' %}
</small>
{% endblock %}

View file

@ -108,18 +108,18 @@ class TagTest(TestCase):
pass
def test_user_tag(self):
t1 = "tag-1"
t2 = "tag-2"
t3 = "tag-3"
t1 = "tag 1"
t2 = "tag 2"
t3 = "tag 3"
TagManager.tag_item_by_user(self.book1, self.user2, [t1, t3])
self.assertEqual(self.book1.tags, [t1, t3])
TagManager.tag_item_by_user(self.book1, self.user2, [t2, t3])
self.assertEqual(self.book1.tags, [t2, t3])
def test_tag(self):
t1 = "tag-1"
t2 = "tag-2"
t3 = "tag-3"
t1 = "tag 1"
t2 = "tag 2"
t3 = "tag 3"
TagManager.add_tag_by_user(self.book1, t3, self.user2)
TagManager.add_tag_by_user(self.book1, t1, self.user1)
TagManager.add_tag_by_user(self.book1, t1, self.user2)
@ -173,4 +173,4 @@ class MarkTest(TestCase):
TagManager.tag_item_by_user(self.book1, self.user1, [" Sci-Fi ", " fic "])
mark = Mark(self.user1, self.book1)
self.assertEqual(mark.tags, ["fic", "sci-fi"])
self.assertEqual(mark.tags, ["Sci-Fi", "fic"])