From e021046c4f1692562faf88f7a647c8a41f21f4a6 Mon Sep 17 00:00:00 2001 From: Norton-Lin <75243447+Norton-Lin@users.noreply.github.com> Date: Fri, 20 Jan 2023 19:33:19 +0800 Subject: [PATCH 1/4] fix(time): fix the time zone display --- hinghwa-dict-backend/HinghwaDict/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hinghwa-dict-backend/HinghwaDict/settings.py b/hinghwa-dict-backend/HinghwaDict/settings.py index 9f722381..ff9bfa46 100644 --- a/hinghwa-dict-backend/HinghwaDict/settings.py +++ b/hinghwa-dict-backend/HinghwaDict/settings.py @@ -292,7 +292,7 @@ # 分为submit和combine两个文件夹 SAVED_PINYIN = os.path.join(BASE_DIR, "material", "audio") TIME_ZONE = "Asia/Shanghai" -USE_TZ = True +USE_TZ = False CACHES = { "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", From ee71452d8e002d4644c672fcd88b89c4e0e0a88b Mon Sep 17 00:00:00 2001 From: Norton-Lin <75243447+Norton-Lin@users.noreply.github.com> Date: Fri, 20 Jan 2023 20:19:40 +0800 Subject: [PATCH 2/4] fix(time): fix the time zone display --- hinghwa-dict-backend/HinghwaDict/settings.py | 2 +- hinghwa-dict-backend/article/dto/article_all.py | 5 +++-- hinghwa-dict-backend/article/dto/article_normal.py | 5 +++-- hinghwa-dict-backend/article/dto/comment_normal.py | 3 ++- hinghwa-dict-backend/user/dto/user_all.py | 3 ++- .../word/pronunciation/dto/pronunciation_all.py | 3 ++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/hinghwa-dict-backend/HinghwaDict/settings.py b/hinghwa-dict-backend/HinghwaDict/settings.py index ff9bfa46..9f722381 100644 --- a/hinghwa-dict-backend/HinghwaDict/settings.py +++ b/hinghwa-dict-backend/HinghwaDict/settings.py @@ -292,7 +292,7 @@ # 分为submit和combine两个文件夹 SAVED_PINYIN = os.path.join(BASE_DIR, "material", "audio") TIME_ZONE = "Asia/Shanghai" -USE_TZ = False +USE_TZ = True CACHES = { "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", diff --git a/hinghwa-dict-backend/article/dto/article_all.py b/hinghwa-dict-backend/article/dto/article_all.py index 73c96026..4d8b03f0 100644 --- a/hinghwa-dict-backend/article/dto/article_all.py +++ b/hinghwa-dict-backend/article/dto/article_all.py @@ -1,5 +1,6 @@ from ..models import Article from user.dto.user_all import user_all +from django.utils.timezone import localtime # 返回文章详细信息 @@ -10,8 +11,8 @@ def article_all(article: Article) -> dict: "author": user_all(user), "likes": article.like(), "views": article.views, - "publish_time": article.publish_time.__format__("%Y-%m-%d %H:%M:%S"), - "update_time": article.update_time.__format__("%Y-%m-%d %H:%M:%S"), + "publish_time": localtime(article.publish_time).__format__("%Y-%m-%d %H:%M:%S"), + "update_time": localtime(article.update_time).__format__("%Y-%m-%d %H:%M:%S"), "title": article.title, "description": article.description, "content": article.content, diff --git a/hinghwa-dict-backend/article/dto/article_normal.py b/hinghwa-dict-backend/article/dto/article_normal.py index b1a5392b..3fb5b850 100644 --- a/hinghwa-dict-backend/article/dto/article_normal.py +++ b/hinghwa-dict-backend/article/dto/article_normal.py @@ -1,3 +1,4 @@ +from django.utils.timezone import localtime from ..models import Article @@ -8,8 +9,8 @@ def article_normal(article: Article) -> dict: "likes": article.like(), "author": article.author.id, "views": article.views, - "publish_time": article.publish_time.__format__("%Y-%m-%d %H:%M:%S"), - "update_time": article.update_time.__format__("%Y-%m-%d %H:%M:%S"), + "publish_time": localtime(article.publish_time).__format__("%Y-%m-%d %H:%M:%S"), + "update_time": localtime(article.update_time).__format__("%Y-%m-%d %H:%M:%S"), "title": article.title, "description": article.description, "content": article.content, diff --git a/hinghwa-dict-backend/article/dto/comment_normal.py b/hinghwa-dict-backend/article/dto/comment_normal.py index 6189df16..86444ae0 100644 --- a/hinghwa-dict-backend/article/dto/comment_normal.py +++ b/hinghwa-dict-backend/article/dto/comment_normal.py @@ -1,5 +1,6 @@ from ..models import Comment from user.dto.user_simple import user_simple +from django.utils.timezone import localtime # 返回评论基本信息 @@ -9,7 +10,7 @@ def comment_normal(comment: Comment) -> dict: "id": comment.id, "user": user_simple(user), "content": comment.content, - "time": comment.time.__format__("%Y-%m-%d %H:%M:%S"), + "time": localtime(comment.time).__format__("%Y-%m-%d %H:%M:%S"), "parent": comment.parent_id if comment.parent else 0, "article": comment.article.id, } diff --git a/hinghwa-dict-backend/user/dto/user_all.py b/hinghwa-dict-backend/user/dto/user_all.py index 989dd72e..8a713916 100644 --- a/hinghwa-dict-backend/user/dto/user_all.py +++ b/hinghwa-dict-backend/user/dto/user_all.py @@ -1,4 +1,5 @@ from ..models import User +from django.utils.timezone import localtime # 返回用户除了 密码 以外的全部信息 @@ -11,7 +12,7 @@ def user_all(user: User) -> dict: "nickname": info.nickname, "email": user.email, "telephone": info.telephone, - "registration_time": user.date_joined.__format__("%Y-%m-%d %H:%M:%S"), + "registration_time": localtime(user.date_joined).__format__("%Y-%m-%d %H:%M:%S"), "birthday": info.birthday, "avatar": info.avatar, "county": info.county, diff --git a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py index e6b28918..867b3fde 100644 --- a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py +++ b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py @@ -1,3 +1,4 @@ +from django.utils.timezone import localtime from word.models import Pronunciation from user.dto.user_all import user_all @@ -24,6 +25,6 @@ def pronunciation_all(pronunciation: Pronunciation) -> dict: if pronunciation.verifier else None, "granted": pronunciation.granted(), - "upload_time": pronunciation.upload_time.strftime("%Y-%m-%d %H:%M:%S"), + "upload_time": localtime(pronunciation.upload_time).strftime("%Y-%m-%d %H:%M:%S"), } return response From 95423ea26f3edb08d84b26fc69769159d1b106da Mon Sep 17 00:00:00 2001 From: Norton-Lin <75243447+Norton-Lin@users.noreply.github.com> Date: Fri, 20 Jan 2023 20:22:38 +0800 Subject: [PATCH 3/4] =?UTF-8?q?style=EF=BC=9Aformat=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hinghwa-dict-backend/user/dto/user_all.py | 4 +++- .../word/pronunciation/dto/pronunciation_all.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hinghwa-dict-backend/user/dto/user_all.py b/hinghwa-dict-backend/user/dto/user_all.py index 8a713916..ce5ef679 100644 --- a/hinghwa-dict-backend/user/dto/user_all.py +++ b/hinghwa-dict-backend/user/dto/user_all.py @@ -12,7 +12,9 @@ def user_all(user: User) -> dict: "nickname": info.nickname, "email": user.email, "telephone": info.telephone, - "registration_time": localtime(user.date_joined).__format__("%Y-%m-%d %H:%M:%S"), + "registration_time": localtime(user.date_joined).__format__( + "%Y-%m-%d %H:%M:%S" + ), "birthday": info.birthday, "avatar": info.avatar, "county": info.county, diff --git a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py index 867b3fde..78ec2bf8 100644 --- a/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py +++ b/hinghwa-dict-backend/word/pronunciation/dto/pronunciation_all.py @@ -25,6 +25,8 @@ def pronunciation_all(pronunciation: Pronunciation) -> dict: if pronunciation.verifier else None, "granted": pronunciation.granted(), - "upload_time": localtime(pronunciation.upload_time).strftime("%Y-%m-%d %H:%M:%S"), + "upload_time": localtime(pronunciation.upload_time).strftime( + "%Y-%m-%d %H:%M:%S" + ), } return response From 20a62ef0ce1ff1719623c00bde47e47529920618 Mon Sep 17 00:00:00 2001 From: Norton-Lin <75243447+Norton-Lin@users.noreply.github.com> Date: Fri, 20 Jan 2023 22:40:06 +0800 Subject: [PATCH 4/4] Update user_all.py --- hinghwa-dict-backend/user/dto/user_all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hinghwa-dict-backend/user/dto/user_all.py b/hinghwa-dict-backend/user/dto/user_all.py index ce5ef679..4e1cd7c8 100644 --- a/hinghwa-dict-backend/user/dto/user_all.py +++ b/hinghwa-dict-backend/user/dto/user_all.py @@ -24,7 +24,7 @@ def user_all(user: User) -> dict: } response.update( { - "login_time": user.last_login.__format__("%Y-%m-%d %H:%M:%S") + "login_time": localtime(user.last_login).__format__("%Y-%m-%d %H:%M:%S") if user.last_login else "", }