From 42ab248de3e18786157f39e313ed2c0d8c658281 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 3 Jun 2024 17:33:39 -0400 Subject: [PATCH] show date in recent posts --- common/templatetags/duration.py | 23 ++++++ common/templatetags/prettydate.py | 22 ------ journal/templates/posts.html | 7 +- locale/zh_Hans/LC_MESSAGES/django.po | 70 ++++++++++--------- locale/zh_Hant/LC_MESSAGES/django.po | 70 ++++++++++--------- .../activity/comment_child_item.html | 1 - .../templates/activity/create_collection.html | 1 - .../activity/feature_collection.html | 1 - .../templates/activity/like_collection.html | 1 - social/templates/activity/mark_item.html | 1 - social/templates/activity/review_item.html | 1 - social/templates/events.html | 3 +- social/templates/feed_data.html | 3 +- users/templates/users/announcements.html | 3 +- 14 files changed, 104 insertions(+), 103 deletions(-) delete mode 100644 common/templatetags/prettydate.py diff --git a/common/templatetags/duration.py b/common/templatetags/duration.py index c2d9c96d..bee41481 100644 --- a/common/templatetags/duration.py +++ b/common/templatetags/duration.py @@ -1,7 +1,10 @@ +from datetime import date, datetime, timedelta, timezone + from django import template from django.conf import settings from django.template.defaultfilters import stringfilter from django.utils.safestring import mark_safe +from django.utils.translation import gettext_lazy as _ from catalog.common.models import item_categories from catalog.search.views import visible_categories as _visible_categories @@ -37,6 +40,26 @@ def duration_format(value, unit): return f"{value} (format error)" +@register.filter(is_safe=True) +def naturaldelta(v: datetime | None): + if not v: + return "" + d = int(datetime.timestamp(datetime.now()) - datetime.timestamp(v)) + if d < 60: + return _("just now") + if d < 3600: + return f"{d//60}m" + if d < 38400: + return f"{d//3600}h" + if d < 38400 * 14: + return f"{d//38400}d" + if d < 38400 * 56: + return f"{d//38400//7}w" + if d < 38400 * 30 * 18: + return f"{d//38400//30}mo" + return f"{d//38400//365}yr" + + @register.filter(is_safe=True) @stringfilter def rating_star(value): diff --git a/common/templatetags/prettydate.py b/common/templatetags/prettydate.py deleted file mode 100644 index 538adb58..00000000 --- a/common/templatetags/prettydate.py +++ /dev/null @@ -1,22 +0,0 @@ -from django import template -from django.utils import timezone -from django.utils.translation import gettext as _ - -register = template.Library() - - -@register.filter -def prettydate(d): - # TODO use date and naturaltime instead https://docs.djangoproject.com/en/3.2/ref/contrib/humanize/ - diff = timezone.now() - d - s = diff.seconds - if diff.days > 14 or diff.days < 0: - return d.strftime("%Y-%m-%d") - elif diff.days >= 1: - return "{}d".format(diff.days) - elif s < 120: - return _("just now") - elif s < 3600: - return "{}m".format(s // 60) - else: - return "{}h".format(s // 3600) diff --git a/journal/templates/posts.html b/journal/templates/posts.html index 16ca04de..70140a95 100644 --- a/journal/templates/posts.html +++ b/journal/templates/posts.html @@ -1,19 +1,18 @@ {% load bleach_tags %} +{% load duration %} {% load humanize %} {% load i18n %} {% for post in posts %}
- {# {{ post.created|date }} #} + {{ post.created|naturaldelta }} {% include "action_reply_post.html" %} {% include "action_like_post.html" %} {% include "action_boost_post.html" %} {% include "action_open_post.html" %} - + \n" "Language-Team: LANGUAGE \n" @@ -667,7 +667,7 @@ 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:270 +#: common/templates/_sidebar.html:231 msgid "show more" msgstr "显示更多" @@ -675,7 +675,7 @@ msgstr "显示更多" #: catalog/templates/_item_comments_by_episode.html:82 #: catalog/templates/_item_reviews.html:47 #: catalog/templates/podcast_episode_data.html:44 -#: social/templates/events.html:44 social/templates/feed_data.html:45 +#: social/templates/events.html:43 social/templates/feed_data.html:44 msgid "nothing more." msgstr "没有更多内容了。" @@ -1166,16 +1166,16 @@ msgstr "简介" #: catalog/templates/item_base.html:236 #: catalog/templates/item_mark_list.html:54 #: catalog/templates/item_review_list.html:50 common/templates/_sidebar.html:37 -#: common/templates/_sidebar.html:86 common/templates/_sidebar.html:165 -#: common/templates/_sidebar.html:265 +#: common/templates/_sidebar.html:126 common/templates/_sidebar.html:226 #: common/templates/_sidebar_anonymous.html:43 #: common/templates/_sidebar_anonymous.html:58 -#: journal/templates/collection_items.html:8 journal/templates/profile.html:109 -#: journal/templates/profile.html:151 journal/templates/profile.html:187 +#: journal/templates/collection_items.html:8 journal/templates/posts.html:39 +#: journal/templates/profile.html:109 journal/templates/profile.html:151 +#: 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:46 -#: users/templates/users/announcements.html:53 +#: journal/templates/user_tag_list.html:29 social/templates/events.html:45 +#: users/templates/users/announcements.html:54 #: users/templates/users/relationship_list.html:11 msgid "nothing so far." msgstr "暂无内容。" @@ -1442,8 +1442,8 @@ msgid "Terms" msgstr "服务协议" #: common/templates/_footer.html:8 common/templates/_sidebar_anonymous.html:40 -#: users/templates/users/announcements.html:10 -#: users/templates/users/announcements.html:40 +#: users/templates/users/announcements.html:11 +#: users/templates/users/announcements.html:41 msgid "Announcements" msgstr "公告栏" @@ -1540,34 +1540,38 @@ msgstr "热门标签" msgid "Popular Posts" msgstr "热门帖文" -#: common/templates/_sidebar.html:120 +#: common/templates/_sidebar.html:81 msgid "approving followers manually" msgstr "已开启关注审核" -#: common/templates/_sidebar.html:150 +#: common/templates/_sidebar.html:111 msgid "Current Targets" msgstr "当前目标" -#: common/templates/_sidebar.html:163 +#: common/templates/_sidebar.html:124 msgid "Set a collection as target, its progress will show up here." msgstr "将自己或他人的收藏单设为目标,这里就会显示进度" -#: common/templates/_sidebar.html:176 +#: common/templates/_sidebar.html:137 msgid "Recent podcast episodes" msgstr "近期播客节目" -#: common/templates/_sidebar.html:211 +#: common/templates/_sidebar.html:172 msgid "Currently reading" msgstr "正在阅读" -#: common/templates/_sidebar.html:234 +#: common/templates/_sidebar.html:195 msgid "Currently watching" msgstr "正在追看" -#: common/templates/_sidebar.html:257 +#: common/templates/_sidebar.html:218 msgid "Common Tags" msgstr "常用标签" +#: common/templates/_sidebar.html:242 +msgid "Recent Posts" +msgstr "近期帖文" + #: common/templates/_sidebar_anonymous.html:16 #, python-format msgid "" @@ -1622,6 +1626,10 @@ msgstr "验证邮件已发送,请查阅收件箱。" msgid "Please click the login link in the email, or enter the verification code you received." msgstr "请点击邮件中的登录链接,或输入收到的验证码。" +#: common/templatetags/duration.py:49 +msgid "just now" +msgstr "刚刚" + #: common/templatetags/mastodon.py:42 msgid "mutual followed" msgstr "互相关注" @@ -1634,10 +1642,6 @@ msgstr "已关注" msgid "following you" msgstr "关注了你" -#: common/templatetags/prettydate.py:18 -msgid "just now" -msgstr "刚刚" - #: common/utils.py:61 common/utils.py:91 users/views.py:35 users/views.py:121 msgid "User not found" msgstr "用户不存在" @@ -2755,35 +2759,35 @@ msgstr "本地标识" msgid "target site domain name" msgstr "目标实例域名" -#: social/templates/activity/comment_child_item.html:13 +#: social/templates/activity/comment_child_item.html:12 msgid "play" msgstr "播放" -#: social/templates/activity/comment_child_item.html:26 +#: social/templates/activity/comment_child_item.html:25 msgid "comment" msgstr "写短评" -#: social/templates/activity/create_collection.html:17 takahe/utils.py:561 +#: social/templates/activity/create_collection.html:16 takahe/utils.py:561 msgid "created collection" msgstr "创建了收藏单" -#: social/templates/activity/feature_collection.html:18 +#: social/templates/activity/feature_collection.html:17 msgid "set a target" msgstr "设置了目标" -#: social/templates/activity/like_collection.html:18 +#: social/templates/activity/like_collection.html:17 #, python-format msgid "liked %(owner_name)s's collection" msgstr "赞了 %(owner_name)s 的收藏单" -#: social/templates/activity/mark_item.html:13 -#: social/templates/activity/mark_item.html:20 -#: social/templates/activity/review_item.html:13 -#: social/templates/activity/review_item.html:20 +#: social/templates/activity/mark_item.html:12 +#: social/templates/activity/mark_item.html:19 +#: social/templates/activity/review_item.html:12 +#: social/templates/activity/review_item.html:19 msgid "mark" msgstr "标记" -#: social/templates/activity/review_item.html:36 +#: social/templates/activity/review_item.html:35 #, python-format msgid "wrote a review of %(item)s" msgstr "评论了 %(item)s" @@ -2947,7 +2951,7 @@ msgstr "" msgid "Activities from those you follow" msgstr "好友动态" -#: social/templates/feed_data.html:49 +#: social/templates/feed_data.html:48 #, python-format msgid "Find and mark some books/movies/podcasts/games, import your data from Goodreads/Letterboxd/Douban, follow some fellow %(site_name)s users on the fediverse, so their recent activities and yours will show up here." msgstr "搜索并标记一些书影音/播客/游戏,导入你的豆瓣、Letterboxd或Goodreads记录,去联邦宇宙(长毛象)关注一些正在使用%(site_name)s的用户,这里就会显示你和她们的近期动态。" diff --git a/locale/zh_Hant/LC_MESSAGES/django.po b/locale/zh_Hant/LC_MESSAGES/django.po index 2ea81ca0..4b572d60 100644 --- a/locale/zh_Hant/LC_MESSAGES/django.po +++ b/locale/zh_Hant/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-06-03 09:12-0400\n" +"POT-Creation-Date: 2024-06-03 17:32-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -667,7 +667,7 @@ 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:270 +#: common/templates/_sidebar.html:231 msgid "show more" msgstr "顯示更多" @@ -675,7 +675,7 @@ msgstr "顯示更多" #: catalog/templates/_item_comments_by_episode.html:82 #: catalog/templates/_item_reviews.html:47 #: catalog/templates/podcast_episode_data.html:44 -#: social/templates/events.html:44 social/templates/feed_data.html:45 +#: social/templates/events.html:43 social/templates/feed_data.html:44 msgid "nothing more." msgstr "沒有更多內容了。" @@ -1166,16 +1166,16 @@ msgstr "簡介" #: catalog/templates/item_base.html:236 #: catalog/templates/item_mark_list.html:54 #: catalog/templates/item_review_list.html:50 common/templates/_sidebar.html:37 -#: common/templates/_sidebar.html:86 common/templates/_sidebar.html:165 -#: common/templates/_sidebar.html:265 +#: common/templates/_sidebar.html:126 common/templates/_sidebar.html:226 #: common/templates/_sidebar_anonymous.html:43 #: common/templates/_sidebar_anonymous.html:58 -#: journal/templates/collection_items.html:8 journal/templates/profile.html:109 -#: journal/templates/profile.html:151 journal/templates/profile.html:187 +#: journal/templates/collection_items.html:8 journal/templates/posts.html:39 +#: journal/templates/profile.html:109 journal/templates/profile.html:151 +#: 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:46 -#: users/templates/users/announcements.html:53 +#: journal/templates/user_tag_list.html:29 social/templates/events.html:45 +#: users/templates/users/announcements.html:54 #: users/templates/users/relationship_list.html:11 msgid "nothing so far." msgstr "暫無內容。" @@ -1442,8 +1442,8 @@ msgid "Terms" msgstr "服務協議" #: common/templates/_footer.html:8 common/templates/_sidebar_anonymous.html:40 -#: users/templates/users/announcements.html:10 -#: users/templates/users/announcements.html:40 +#: users/templates/users/announcements.html:11 +#: users/templates/users/announcements.html:41 msgid "Announcements" msgstr "公告欄" @@ -1540,34 +1540,38 @@ msgstr "熱門標籤" msgid "Popular Posts" msgstr "熱門帖文" -#: common/templates/_sidebar.html:120 +#: common/templates/_sidebar.html:81 msgid "approving followers manually" msgstr "已開啓關注審覈" -#: common/templates/_sidebar.html:150 +#: common/templates/_sidebar.html:111 msgid "Current Targets" msgstr "當前目標" -#: common/templates/_sidebar.html:163 +#: common/templates/_sidebar.html:124 msgid "Set a collection as target, its progress will show up here." msgstr "將自己或他人的收藏單設爲目標,這裏就會顯示進度" -#: common/templates/_sidebar.html:176 +#: common/templates/_sidebar.html:137 msgid "Recent podcast episodes" msgstr "近期播客節目" -#: common/templates/_sidebar.html:211 +#: common/templates/_sidebar.html:172 msgid "Currently reading" msgstr "正在閱讀" -#: common/templates/_sidebar.html:234 +#: common/templates/_sidebar.html:195 msgid "Currently watching" msgstr "正在追看" -#: common/templates/_sidebar.html:257 +#: common/templates/_sidebar.html:218 msgid "Common Tags" msgstr "常用標籤" +#: common/templates/_sidebar.html:242 +msgid "Recent Posts" +msgstr "近期帖文" + #: common/templates/_sidebar_anonymous.html:16 #, python-format msgid "" @@ -1622,6 +1626,10 @@ msgstr "驗證郵件已發送,請查閱收件箱。" msgid "Please click the login link in the email, or enter the verification code you received." msgstr "請點擊郵件中的登錄鏈接,或輸入收到的驗證碼。" +#: common/templatetags/duration.py:49 +msgid "just now" +msgstr "剛剛" + #: common/templatetags/mastodon.py:42 msgid "mutual followed" msgstr "互相關注" @@ -1634,10 +1642,6 @@ msgstr "已關注" msgid "following you" msgstr "關注了你" -#: common/templatetags/prettydate.py:18 -msgid "just now" -msgstr "剛剛" - #: common/utils.py:61 common/utils.py:91 users/views.py:35 users/views.py:121 msgid "User not found" msgstr "用戶不存在" @@ -2757,35 +2761,35 @@ msgstr "本地標識" msgid "target site domain name" msgstr "目標實例域名" -#: social/templates/activity/comment_child_item.html:13 +#: social/templates/activity/comment_child_item.html:12 msgid "play" msgstr "播放" -#: social/templates/activity/comment_child_item.html:26 +#: social/templates/activity/comment_child_item.html:25 msgid "comment" msgstr "寫短評" -#: social/templates/activity/create_collection.html:17 takahe/utils.py:561 +#: social/templates/activity/create_collection.html:16 takahe/utils.py:561 msgid "created collection" msgstr "創建了收藏單" -#: social/templates/activity/feature_collection.html:18 +#: social/templates/activity/feature_collection.html:17 msgid "set a target" msgstr "設置了目標" -#: social/templates/activity/like_collection.html:18 +#: social/templates/activity/like_collection.html:17 #, python-format msgid "liked %(owner_name)s's collection" msgstr "讚了 %(owner_name)s 的收藏單" -#: social/templates/activity/mark_item.html:13 -#: social/templates/activity/mark_item.html:20 -#: social/templates/activity/review_item.html:13 -#: social/templates/activity/review_item.html:20 +#: social/templates/activity/mark_item.html:12 +#: social/templates/activity/mark_item.html:19 +#: social/templates/activity/review_item.html:12 +#: social/templates/activity/review_item.html:19 msgid "mark" msgstr "標記" -#: social/templates/activity/review_item.html:36 +#: social/templates/activity/review_item.html:35 #, python-format msgid "wrote a review of %(item)s" msgstr "評論了 %(item)s" @@ -2949,7 +2953,7 @@ msgstr "" msgid "Activities from those you follow" msgstr "好友動態" -#: social/templates/feed_data.html:49 +#: social/templates/feed_data.html:48 #, python-format msgid "Find and mark some books/movies/podcasts/games, import your data from Goodreads/Letterboxd/Douban, follow some fellow %(site_name)s users on the fediverse, so their recent activities and yours will show up here." msgstr "搜索並標記一些書影音/播客/遊戲,導入你的豆瓣、Letterboxd或Goodreads記錄,去聯邦宇宙(長毛象)關注一些正在使用%(site_name)s的用戶,這裏就會顯示你和她們的近期動態。" diff --git a/social/templates/activity/comment_child_item.html b/social/templates/activity/comment_child_item.html index 9400abf5..93388eee 100644 --- a/social/templates/activity/comment_child_item.html +++ b/social/templates/activity/comment_child_item.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% load duration %} {% wish_item_action activity.action_object.item.parent_item as action %} diff --git a/social/templates/activity/create_collection.html b/social/templates/activity/create_collection.html index 120d21b7..9c4b2844 100644 --- a/social/templates/activity/create_collection.html +++ b/social/templates/activity/create_collection.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% if activity.action_object.latest_post %} diff --git a/social/templates/activity/feature_collection.html b/social/templates/activity/feature_collection.html index 8b0648c5..ac405e15 100644 --- a/social/templates/activity/feature_collection.html +++ b/social/templates/activity/feature_collection.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% with activity.action_object.target as collection %} diff --git a/social/templates/activity/like_collection.html b/social/templates/activity/like_collection.html index 901403f1..b4253988 100644 --- a/social/templates/activity/like_collection.html +++ b/social/templates/activity/like_collection.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% with activity.action_object.target as collection %} diff --git a/social/templates/activity/mark_item.html b/social/templates/activity/mark_item.html index 05103a5e..e2917752 100644 --- a/social/templates/activity/mark_item.html +++ b/social/templates/activity/mark_item.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% load duration %} {% wish_item_action activity.action_object.item as action %} diff --git a/social/templates/activity/review_item.html b/social/templates/activity/review_item.html index 40aea1b7..c435905c 100644 --- a/social/templates/activity/review_item.html +++ b/social/templates/activity/review_item.html @@ -3,7 +3,6 @@ {% load l10n %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% load duration %} {% wish_item_action activity.action_object.item as action %} diff --git a/social/templates/events.html b/social/templates/events.html index 35e75250..6bacc6f3 100644 --- a/social/templates/events.html +++ b/social/templates/events.html @@ -4,7 +4,6 @@ {% load humanize %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% load duration %} {% for event in events %} @@ -15,7 +14,7 @@
- {{ event.created|naturaltime }} + {{ event.created|naturaldelta }}
diff --git a/social/templates/feed_data.html b/social/templates/feed_data.html index 63f5cb9f..5da255eb 100644 --- a/social/templates/feed_data.html +++ b/social/templates/feed_data.html @@ -4,7 +4,6 @@ {% load humanize %} {% load mastodon %} {% load thumb %} -{% load prettydate %} {% load user_actions %} {% load duration %} {% for activity in activities %} @@ -15,7 +14,7 @@
- {{ activity.action_object.created_time|naturaltime }} + {{ activity.action_object.created_time|naturaldelta }}
diff --git a/users/templates/users/announcements.html b/users/templates/users/announcements.html index e1b3675a..f328750b 100644 --- a/users/templates/users/announcements.html +++ b/users/templates/users/announcements.html @@ -1,6 +1,7 @@ {% load static %} {% load i18n %} {% load humanize %} +{% load duration %} @@ -45,7 +46,7 @@