From e3d057dd54179048d8d9bd749eeb117ab5cbe1d1 Mon Sep 17 00:00:00 2001 From: async-upgrade Date: Sun, 6 Sep 2026 16:43:20 +0800 Subject: [PATCH] fix(pre-existing): FUser has no nickname field - use first_name (article notify, message sender_name, bug user_name) --- article/views.py | 4 ++-- bug/serializers.py | 16 ++++++++-------- message/serializers.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/article/views.py b/article/views.py index b7a28fb..e8a537d 100644 --- a/article/views.py +++ b/article/views.py @@ -330,7 +330,7 @@ class ArticleCommentListCreateView(generics.ListCreateAPIView): parent_comment_id = comment.parent_id parent_comment_user_id = comment.parent.user_id if comment.parent else None user_id = request.user.id - user_nickname = request.user.nickname or request.user.username + user_nickname = request.user.first_name or request.user.username transaction.on_commit(lambda: self._send_notification_messages( article_id, article_title, article_author_id, comment_id, @@ -455,7 +455,7 @@ class ArticleLikeToggleView(APIView): recipient=article.author, sender=request.user, msg_type='like', - title=f'{request.user.nickname or request.user.username} 赞了你的文章', + title=f'{request.user.first_name or request.user.username} 赞了你的文章', content=f'《{article.title}》', extra_info='', target_link=f'/article/{pk}', diff --git a/bug/serializers.py b/bug/serializers.py index 896de13..711b4cc 100644 --- a/bug/serializers.py +++ b/bug/serializers.py @@ -1,4 +1,4 @@ -from adrf.serializers import ( +from adrf.serializers import ( ModelSerializer, CharField, ImageField, DateTimeField, ListField, FileField, SerializerMethodField, ) @@ -34,7 +34,7 @@ class BugReportCommentAttachmentSerializer(ModelSerializer): class BugReportCommentSerializer(ModelSerializer): - user_name = CharField(source='user.nickname', read_only=True) + user_name = CharField(source='user.first_name', read_only=True) user_avatar = ImageField(source='user.avatar', read_only=True) images = BugReportCommentImageSerializer(many=True, read_only=True) attachments = BugReportCommentAttachmentSerializer(many=True, read_only=True) @@ -50,7 +50,7 @@ class BugReportCommentSerializer(ModelSerializer): class BugReportListSerializer(ModelSerializer): - user_name = CharField(source='user.nickname', read_only=True) + user_name = CharField(source='user.first_name', read_only=True) images_count = SerializerMethodField() class Meta: @@ -65,7 +65,7 @@ class BugReportListSerializer(ModelSerializer): class BugReportDetailSerializer(ModelSerializer): - user_name = CharField(source='user.nickname', read_only=True) + user_name = CharField(source='user.first_name', read_only=True) user_avatar = ImageField(source='user.avatar', read_only=True) images = BugReportImageSerializer(many=True, read_only=True) attachments = BugReportAttachmentSerializer(many=True, read_only=True) @@ -102,14 +102,14 @@ class BugReportCreateSerializer(ModelSerializer): max_size = 10 * 1024 * 1024 # 10MB for image in value: if image.size > max_size: - raise ValidationError(f"图片 {image.name} 大小超过10MB限制") + raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗") return value def validate_attachments(self, value): max_size = 20 * 1024 * 1024 # 20MB for attachment in value: if attachment.size > max_size: - raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制") + raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗") return value async def acreate(self, validated_data): @@ -152,14 +152,14 @@ class BugReportCommentCreateSerializer(ModelSerializer): max_size = 10 * 1024 * 1024 # 10MB for image in value: if image.size > max_size: - raise ValidationError(f"图片 {image.name} 大小超过10MB限制") + raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗") return value def validate_attachments(self, value): max_size = 20 * 1024 * 1024 # 20MB for attachment in value: if attachment.size > max_size: - raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制") + raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗") return value async def acreate(self, validated_data): diff --git a/message/serializers.py b/message/serializers.py index a59c350..cf0b6c1 100644 --- a/message/serializers.py +++ b/message/serializers.py @@ -40,7 +40,7 @@ class MessageListSerializer(ModelSerializer): async def get_sender_name(self, obj): sender = await _load_sender(obj) if sender: - return sender.nickname or sender.username + return sender.first_name or sender.username return '系统' async def get_sender_avatar(self, obj):