Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

修复时区显示错误 #280

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions hinghwa-dict-backend/article/dto/article_all.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..models import Article
from user.dto.user_all import user_all
from django.utils.timezone import localtime


# 返回文章详细信息
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions hinghwa-dict-backend/article/dto/article_normal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils.timezone import localtime
from ..models import Article


Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion hinghwa-dict-backend/article/dto/comment_normal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..models import Comment
from user.dto.user_simple import user_simple
from django.utils.timezone import localtime


# 返回评论基本信息
Expand All @@ -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,
}
Expand Down
7 changes: 5 additions & 2 deletions hinghwa-dict-backend/user/dto/user_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..models import User
from django.utils.timezone import localtime


# 返回用户除了 密码 以外的全部信息
Expand All @@ -11,7 +12,9 @@ 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,
Expand All @@ -21,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 "",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils.timezone import localtime
from word.models import Pronunciation
from user.dto.user_all import user_all

Expand All @@ -24,6 +25,8 @@ 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