fix(pre-existing): FUser has no nickname field - use first_name (article notify, message sender_name, bug user_name)
This commit is contained in:
+2
-2
@@ -330,7 +330,7 @@ class ArticleCommentListCreateView(generics.ListCreateAPIView):
|
|||||||
parent_comment_id = comment.parent_id
|
parent_comment_id = comment.parent_id
|
||||||
parent_comment_user_id = comment.parent.user_id if comment.parent else None
|
parent_comment_user_id = comment.parent.user_id if comment.parent else None
|
||||||
user_id = request.user.id
|
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(
|
transaction.on_commit(lambda: self._send_notification_messages(
|
||||||
article_id, article_title, article_author_id, comment_id,
|
article_id, article_title, article_author_id, comment_id,
|
||||||
@@ -455,7 +455,7 @@ class ArticleLikeToggleView(APIView):
|
|||||||
recipient=article.author,
|
recipient=article.author,
|
||||||
sender=request.user,
|
sender=request.user,
|
||||||
msg_type='like',
|
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}》',
|
content=f'《{article.title}》',
|
||||||
extra_info='',
|
extra_info='',
|
||||||
target_link=f'/article/{pk}',
|
target_link=f'/article/{pk}',
|
||||||
|
|||||||
+8
-8
@@ -1,4 +1,4 @@
|
|||||||
from adrf.serializers import (
|
from adrf.serializers import (
|
||||||
ModelSerializer, CharField, ImageField, DateTimeField,
|
ModelSerializer, CharField, ImageField, DateTimeField,
|
||||||
ListField, FileField, SerializerMethodField,
|
ListField, FileField, SerializerMethodField,
|
||||||
)
|
)
|
||||||
@@ -34,7 +34,7 @@ class BugReportCommentAttachmentSerializer(ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class BugReportCommentSerializer(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)
|
user_avatar = ImageField(source='user.avatar', read_only=True)
|
||||||
images = BugReportCommentImageSerializer(many=True, read_only=True)
|
images = BugReportCommentImageSerializer(many=True, read_only=True)
|
||||||
attachments = BugReportCommentAttachmentSerializer(many=True, read_only=True)
|
attachments = BugReportCommentAttachmentSerializer(many=True, read_only=True)
|
||||||
@@ -50,7 +50,7 @@ class BugReportCommentSerializer(ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class BugReportListSerializer(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()
|
images_count = SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -65,7 +65,7 @@ class BugReportListSerializer(ModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class BugReportDetailSerializer(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)
|
user_avatar = ImageField(source='user.avatar', read_only=True)
|
||||||
images = BugReportImageSerializer(many=True, read_only=True)
|
images = BugReportImageSerializer(many=True, read_only=True)
|
||||||
attachments = BugReportAttachmentSerializer(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
|
max_size = 10 * 1024 * 1024 # 10MB
|
||||||
for image in value:
|
for image in value:
|
||||||
if image.size > max_size:
|
if image.size > max_size:
|
||||||
raise ValidationError(f"图片 {image.name} 大小超过10MB限制")
|
raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_attachments(self, value):
|
def validate_attachments(self, value):
|
||||||
max_size = 20 * 1024 * 1024 # 20MB
|
max_size = 20 * 1024 * 1024 # 20MB
|
||||||
for attachment in value:
|
for attachment in value:
|
||||||
if attachment.size > max_size:
|
if attachment.size > max_size:
|
||||||
raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制")
|
raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
async def acreate(self, validated_data):
|
async def acreate(self, validated_data):
|
||||||
@@ -152,14 +152,14 @@ class BugReportCommentCreateSerializer(ModelSerializer):
|
|||||||
max_size = 10 * 1024 * 1024 # 10MB
|
max_size = 10 * 1024 * 1024 # 10MB
|
||||||
for image in value:
|
for image in value:
|
||||||
if image.size > max_size:
|
if image.size > max_size:
|
||||||
raise ValidationError(f"图片 {image.name} 大小超过10MB限制")
|
raise ValidationError(f"鍥剧墖 {image.name} 澶у皬瓒呰繃10MB闄愬埗")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_attachments(self, value):
|
def validate_attachments(self, value):
|
||||||
max_size = 20 * 1024 * 1024 # 20MB
|
max_size = 20 * 1024 * 1024 # 20MB
|
||||||
for attachment in value:
|
for attachment in value:
|
||||||
if attachment.size > max_size:
|
if attachment.size > max_size:
|
||||||
raise ValidationError(f"附件 {attachment.name} 大小超过20MB限制")
|
raise ValidationError(f"闄勪欢 {attachment.name} 澶у皬瓒呰繃20MB闄愬埗")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
async def acreate(self, validated_data):
|
async def acreate(self, validated_data):
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class MessageListSerializer(ModelSerializer):
|
|||||||
async def get_sender_name(self, obj):
|
async def get_sender_name(self, obj):
|
||||||
sender = await _load_sender(obj)
|
sender = await _load_sender(obj)
|
||||||
if sender:
|
if sender:
|
||||||
return sender.nickname or sender.username
|
return sender.first_name or sender.username
|
||||||
return '系统'
|
return '系统'
|
||||||
|
|
||||||
async def get_sender_avatar(self, obj):
|
async def get_sender_avatar(self, obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user