show pinned tag on profile page

This commit is contained in:
Your Name 2024-06-04 20:49:23 -04:00 committed by Henri Dickson
parent abb36cd80f
commit 75c25dcd26
10 changed files with 143 additions and 96 deletions

View file

@ -183,25 +183,31 @@
</article>
</section>
{% endif %}
{% if top_tags %}
{% if top_tags is not None %}
<section>
<article>
<details {% if top_tags %}class="auto-collapse" open{% endif %}>
<summary>{% trans 'Common Tags' %}</summary>
<summary>{% trans 'Tags' %}</summary>
<div class="tag-list">
{% for t in top_tags %}
<span>
<a href="{% url 'journal:user_tag_member_list' identity.user.handler t.title %}">{{ t.title }}</a>
<a href="{% url 'journal:user_tag_member_list' identity.user.handler t.title %}">
{% if t.pinned %}
<i class="fa-solid fa-crown" title="{% trans "featured tag" %}"></i>
{% endif %}
{% if t.visibility > 0 %}
<i class="fa-solid fa-user" title="{% trans "personal tag" %}"></i>
{% endif %}
{{ t.title }}
</a>
<small>({{ t.total }})</small>
</span>
{% empty %}
<div class="empty">{% trans "nothing so far." %}</div>
<div class="empty">{% trans "no tags so far." %}</div>
{% endfor %}
</div>
<small>
{% if top_tags %}
<a href="{% url 'journal:user_tag_list' identity.user.handler %}">...{% trans 'show more' %}</a>
{% endif %}
<a href="{% url 'journal:user_tag_list' identity.user.handler %}">({% trans 'show all' %})</a>
</small>
</details>
</article>

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2.13 on 2024-06-05 00:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("journal", "0025_pin_tags"),
]
operations = [
migrations.AddIndex(
model_name="tag",
index=models.Index(
fields=["owner", "pinned"], name="journal_tag_owner_i_068598_idx"
),
),
]

View file

@ -51,6 +51,7 @@ class Tag(List):
class Meta:
unique_together = [["owner", "title"]]
indexes = [models.Index(fields=["owner", "pinned"])]
@staticmethod
def cleanup_title(title, replace=True):
@ -102,13 +103,6 @@ class TagManager:
)
return tag_titles
@staticmethod
def all_tags_by_owner(owner, public_only=False):
tags = owner.tag_set.all().annotate(total=Count("members")).order_by("-total")
if public_only:
tags = tags.filter(visibility=0)
return tags
@staticmethod
def tag_item_for_owner(
owner: APIdentity,
@ -142,13 +136,14 @@ class TagManager:
def __init__(self, owner):
self.owner = owner
@property
def all_tags(self):
return TagManager.all_tags_by_owner(self.owner)
@property
def public_tags(self):
return TagManager.all_tags_by_owner(self.owner, public_only=True)
def get_tags(self, public_only=False, pinned_only=False):
tags = self.owner.tag_set.all()
tags = tags.annotate(total=Count("members")).order_by("-total")
if public_only:
tags = tags.filter(visibility=0)
if pinned_only:
tags = tags.filter(pinned=True)
return tags
@staticmethod
def popular_tags(days: int = 30):

View file

@ -49,7 +49,7 @@
<label for="id_visibility_2">{% trans "Personal" %}</label>
</fieldset>
<input type="submit" class="button float-right" value="{% trans "Save" %}">
<small>{% trans "Personal tags are not shown to others when they view your tag list, unless you pin them. However, if you use this tag when marking an item publicly, it might still be visible to others." %}</small>
<small>{% trans "Personal tags are not included in public index. However, if you use this tag when marking an item publicly, it might still be visible to others." %}</small>
<label for="_delete">
<input type="checkbox" name="delete" value="1" id="_delete">
{% trans "Delete this tag" %}

View file

@ -21,12 +21,20 @@
{% for v in tags %}
<span style="margin-right:2em; white-space: nowrap;">
<span>
<a href="{% url 'journal:user_tag_member_list' identity.handle v.title %}">{{ v.title }}</a>
<a href="{% url 'journal:user_tag_member_list' identity.handle v.title %}">
{% if v.pinned %}
<i class="fa-solid fa-crown" title="{% trans "featured tag" %}"></i>
{% endif %}
{% if v.visibility > 0 %}
<i class="fa-solid fa-user" title="{% trans "personal tag" %}"></i>
{% endif %}
{{ v.title }}
</a>
</span>
<span>({{ v.total }})</span>
</span>
{% empty %}
{% trans 'nothing so far.' %}
{% trans 'no tags so far.' %}
{% endfor %}
</div>
</div>

View file

@ -4,24 +4,28 @@
<title>{{ site_name }} - {{ identity.display_name }} - {% trans 'Tags' %} - {{ tag.title }}</title>
{% endblock %}
{% block head %}
<span class="action">
{% if tag.pinned %}
<span><a>
<i class="fa-solid fa-crown" title="{% trans "featured tag" %}"></i>
</a></span>
{% endif %}
{% if tag.visibility > 0 %}
<span><a>
<i class="fa-solid fa-user" title="{% trans "personal tag" %}"></i>
</a></span>
{% endif %}
{% if identity.user == request.user %}
<span>
<a hx-get="{% url 'journal:user_tag_edit' %}?tag={{ tag.title }}"
hx-target="body"
hx-swap="beforeend">
<i class="fa-regular fa-pen-to-square"></i>
</a>
</span>
{% endif %}
</span>
<span class="action inline"><span class="timestamp"><a><i class="fa-solid fa-hashtag"></i></a></span></span>
{{ tag.title }}
<br>
<small>
{% if tag.visibility > 0 %}
<i class="fa-solid fa-user" title="{% trans "private tag" %}"></i>
{% endif %}
{{ identity.display_name }} - {% trans 'Tags' %}
{% if identity.user == request.user %}
<form style="display:inline"
hx-get="{% url 'journal:user_tag_edit' %}"
hx-target="body"
hx-swap="beforeend"
hx-boost="true">
<input type="hidden" name="tag" value="{{ tag.title }}">
<button class="outline" style="padding:0 var(--pico-spacing);border:none;">
<i class="fa-regular fa-pen-to-square"></i>
</button>
</form>
{% endif %}
</small>
{% endblock %}

View file

@ -83,10 +83,8 @@ def profile(request: AuthedHttpRequest, user_name):
liked_collections = liked_collections.filter(
q_piece_visible_to_user(request.user)
)
top_tags = target.tag_manager.public_tags[:10]
year = None
else:
top_tags = target.tag_manager.all_tags[:10]
today = datetime.date.today()
if today.month > 11:
year = today.year
@ -94,6 +92,9 @@ def profile(request: AuthedHttpRequest, user_name):
year = today.year - 1
else:
year = None
top_tags = target.tag_manager.get_tags(public_only=not me, pinned_only=True)[:10]
if not top_tags.exists():
top_tags = target.tag_manager.get_tags(public_only=not me)[:10]
if anonymous:
recent_posts = None
else:

View file

@ -8,6 +8,8 @@ from django.views.decorators.http import require_http_methods
from user_messages import api as msg
from catalog.models import *
from takahe.models import Identity
from users.models import APIdentity
from ..forms import *
from ..models import *
@ -19,8 +21,8 @@ PAGE_SIZE = 10
@login_required
@target_identity_required
def user_tag_list(request, user_name):
target = request.target_identity
tags = TagManager.all_tags_by_owner(target, target.user != request.user)
target: APIdentity = request.target_identity
tags = target.tag_manager.get_tags(public_only=target.user != request.user)
return render(
request,
"user_tag_list.html",

View file

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-04 16:48-0400\n"
"POT-Creation-Date: 2024-06-04 20:43-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -667,7 +667,6 @@ msgstr "不再提示"
#: catalog/templates/_item_comments_by_episode.html:78
#: catalog/templates/_item_reviews.html:43
#: catalog/templates/podcast_episode_data.html:41
#: common/templates/_sidebar.html:204
msgid "show more"
msgstr "显示更多"
@ -1113,7 +1112,6 @@ msgstr "热门标签"
#: catalog/templates/discover.html:185 catalog/templates/item_base.html:236
#: catalog/templates/item_mark_list.html:54
#: catalog/templates/item_review_list.html:50 common/templates/_sidebar.html:99
#: common/templates/_sidebar.html:199
#: common/templates/_sidebar_anonymous.html:43
#: common/templates/_sidebar_anonymous.html:58
#: journal/templates/collection_items.html:8 journal/templates/posts.html:45
@ -1121,8 +1119,7 @@ msgstr "热门标签"
#: journal/templates/profile.html:187
#: journal/templates/user_collection_list.html:51
#: journal/templates/user_item_list_base.html:25
#: journal/templates/user_tag_list.html:29 social/templates/events.html:45
#: users/templates/users/announcements.html:54
#: social/templates/events.html:45 users/templates/users/announcements.html:54
#: users/templates/users/relationship_list.html:11
msgid "nothing so far."
msgstr "暂无内容。"
@ -1564,11 +1561,30 @@ msgstr "正在阅读"
msgid "Currently watching"
msgstr "正在追看"
#: common/templates/_sidebar.html:191
msgid "Common Tags"
msgstr "常用标签"
#: common/templates/_sidebar.html:191 journal/templates/user_tag_list.html:12
#: journal/templates/user_tagmember_list.html:4
msgid "Tags"
msgstr "标签"
#: common/templates/_sidebar.html:215
#: common/templates/_sidebar.html:197 journal/templates/user_tag_list.html:26
#: journal/templates/user_tagmember_list.html:10
msgid "featured tag"
msgstr "置顶标签"
#: common/templates/_sidebar.html:200 journal/templates/user_tag_list.html:29
#: journal/templates/user_tagmember_list.html:15
msgid "personal tag"
msgstr "个人标签"
#: common/templates/_sidebar.html:207 journal/templates/user_tag_list.html:37
msgid "no tags so far."
msgstr "暂无标签。"
#: common/templates/_sidebar.html:211
msgid "show all"
msgstr "显示全部"
#: common/templates/_sidebar.html:221
msgid "Recent Posts"
msgstr "近期帖文"
@ -2530,7 +2546,7 @@ msgid "Personal"
msgstr "个人"
#: journal/templates/tag_edit.html:52
msgid "Personal tags are not shown to others when they view your tag list, unless you pin them. However, if you use this tag when marking an item publicly, it might still be visible to others."
msgid "Personal tags are not included in public index. However, if you use this tag when marking an item publicly, it might still be visible to others."
msgstr "个人标签不被包括在条目的公共索引中,但如果公开标记一个条目时使用这个标签仍会被别人看到。"
#: journal/templates/tag_edit.html:55
@ -2542,20 +2558,10 @@ msgstr "删除这个标签"
msgid "Liked Collections"
msgstr "喜欢的收藏单"
#: journal/templates/user_tag_list.html:12
#: journal/templates/user_tagmember_list.html:4
#: journal/templates/user_tagmember_list.html:13
msgid "Tags"
msgstr "标签"
#: journal/templates/user_tag_list.html:19
msgid "All Tags"
msgstr "全部标签"
#: journal/templates/user_tagmember_list.html:11
msgid "private tag"
msgstr "个人标签"
#: journal/templates/wrapped_share.html:16
msgid "Share Annual Summary"
msgstr "分享年度小结"
@ -2669,23 +2675,23 @@ msgstr "链接无效"
msgid "{review_title} - a review of {item_title}"
msgstr "{review_title} - 关于 {item_title} 的评论"
#: journal/views/tag.py:41 journal/views/tag.py:55
#: journal/views/tag.py:43 journal/views/tag.py:57
msgid "Invalid tag"
msgstr "无效标签"
#: journal/views/tag.py:44
#: journal/views/tag.py:46
msgid "Tag not found"
msgstr "标签不存在"
#: journal/views/tag.py:59
#: journal/views/tag.py:61
msgid "Tag deleted."
msgstr "标签已删除"
#: journal/views/tag.py:69
#: journal/views/tag.py:71
msgid "Duplicated tag."
msgstr "重复标签"
#: journal/views/tag.py:76
#: journal/views/tag.py:78
msgid "Tag updated."
msgstr "标签已更新"

View file

@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-04 16:48-0400\n"
"POT-Creation-Date: 2024-06-04 20:43-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -667,7 +667,6 @@ msgstr "不再提示"
#: catalog/templates/_item_comments_by_episode.html:78
#: catalog/templates/_item_reviews.html:43
#: catalog/templates/podcast_episode_data.html:41
#: common/templates/_sidebar.html:204
msgid "show more"
msgstr "顯示更多"
@ -1113,7 +1112,6 @@ msgstr "熱門標籤"
#: catalog/templates/discover.html:185 catalog/templates/item_base.html:236
#: catalog/templates/item_mark_list.html:54
#: catalog/templates/item_review_list.html:50 common/templates/_sidebar.html:99
#: common/templates/_sidebar.html:199
#: common/templates/_sidebar_anonymous.html:43
#: common/templates/_sidebar_anonymous.html:58
#: journal/templates/collection_items.html:8 journal/templates/posts.html:45
@ -1121,8 +1119,7 @@ msgstr "熱門標籤"
#: journal/templates/profile.html:187
#: journal/templates/user_collection_list.html:51
#: journal/templates/user_item_list_base.html:25
#: journal/templates/user_tag_list.html:29 social/templates/events.html:45
#: users/templates/users/announcements.html:54
#: social/templates/events.html:45 users/templates/users/announcements.html:54
#: users/templates/users/relationship_list.html:11
msgid "nothing so far."
msgstr "暫無內容。"
@ -1564,11 +1561,30 @@ msgstr "正在閱讀"
msgid "Currently watching"
msgstr "正在追看"
#: common/templates/_sidebar.html:191
msgid "Common Tags"
msgstr "常用標籤"
#: common/templates/_sidebar.html:191 journal/templates/user_tag_list.html:12
#: journal/templates/user_tagmember_list.html:4
msgid "Tags"
msgstr "標籤"
#: common/templates/_sidebar.html:215
#: common/templates/_sidebar.html:197 journal/templates/user_tag_list.html:26
#: journal/templates/user_tagmember_list.html:10
msgid "featured tag"
msgstr "置頂標籤"
#: common/templates/_sidebar.html:200 journal/templates/user_tag_list.html:29
#: journal/templates/user_tagmember_list.html:15
msgid "personal tag"
msgstr "個人標籤"
#: common/templates/_sidebar.html:207 journal/templates/user_tag_list.html:37
msgid "no tags so far."
msgstr "暫無標籤。"
#: common/templates/_sidebar.html:211
msgid "show all"
msgstr "顯示全部"
#: common/templates/_sidebar.html:221
msgid "Recent Posts"
msgstr "近期帖文"
@ -2530,7 +2546,7 @@ msgid "Personal"
msgstr "個人"
#: journal/templates/tag_edit.html:52
msgid "Personal tags are not shown to others when they view your tag list, unless you pin them. However, if you use this tag when marking an item publicly, it might still be visible to others."
msgid "Personal tags are not included in public index. However, if you use this tag when marking an item publicly, it might still be visible to others."
msgstr "個人標籤不被包括在條目的公共索引中,但如果公開標記一個條目時使用這個標籤仍會被別人看到。"
#: journal/templates/tag_edit.html:55
@ -2542,20 +2558,10 @@ msgstr "刪除這個標籤"
msgid "Liked Collections"
msgstr "喜歡的收藏單"
#: journal/templates/user_tag_list.html:12
#: journal/templates/user_tagmember_list.html:4
#: journal/templates/user_tagmember_list.html:13
msgid "Tags"
msgstr "標籤"
#: journal/templates/user_tag_list.html:19
msgid "All Tags"
msgstr "全部標籤"
#: journal/templates/user_tagmember_list.html:11
msgid "private tag"
msgstr "個人標籤"
#: journal/templates/wrapped_share.html:16
msgid "Share Annual Summary"
msgstr "分享年度小結"
@ -2669,23 +2675,23 @@ msgstr "鏈接無效"
msgid "{review_title} - a review of {item_title}"
msgstr "{review_title} - 關於 {item_title} 的評論"
#: journal/views/tag.py:41 journal/views/tag.py:55
#: journal/views/tag.py:43 journal/views/tag.py:57
msgid "Invalid tag"
msgstr "無效標籤"
#: journal/views/tag.py:44
#: journal/views/tag.py:46
msgid "Tag not found"
msgstr "標籤不存在"
#: journal/views/tag.py:59
#: journal/views/tag.py:61
msgid "Tag deleted."
msgstr "標籤已刪除"
#: journal/views/tag.py:69
#: journal/views/tag.py:71
msgid "Duplicated tag."
msgstr "重複標籤"
#: journal/views/tag.py:76
#: journal/views/tag.py:78
msgid "Tag updated."
msgstr "標籤已更新"