diff --git a/Server01/static/img/avatar/10-lisa.jpg b/Server01/static/img/avatar/10-lisa.jpg deleted file mode 100644 index 4908391..0000000 Binary files a/Server01/static/img/avatar/10-lisa.jpg and /dev/null differ diff --git "a/Server01/static/img/avatar/10-\351\207\221\347\217\215\345\246\256.jpg" "b/Server01/static/img/avatar/10-\351\207\221\347\217\215\345\246\256.jpg" new file mode 100644 index 0000000..8b0f144 Binary files /dev/null and "b/Server01/static/img/avatar/10-\351\207\221\347\217\215\345\246\256.jpg" differ diff --git "a/Server01/static/img/avatar/9-\351\207\221\346\231\272\347\247\200.jpg" "b/Server01/static/img/avatar/9-\351\207\221\346\231\272\347\247\200.jpg" new file mode 100644 index 0000000..81c2c29 Binary files /dev/null and "b/Server01/static/img/avatar/9-\351\207\221\346\231\272\347\247\200.jpg" differ diff --git a/Server01/static/img/post/38-01.jpg b/Server01/static/img/post/38-01.jpg new file mode 100644 index 0000000..1ef271c Binary files /dev/null and b/Server01/static/img/post/38-01.jpg differ diff --git a/Server01/static/img/post/39-03.gif b/Server01/static/img/post/39-03.gif new file mode 100644 index 0000000..142c7d7 Binary files /dev/null and b/Server01/static/img/post/39-03.gif differ diff --git a/Server01/util/__pycache__/verifyJWT.cpython-39.pyc b/Server01/util/__pycache__/verifyJWT.cpython-39.pyc index 6581339..cf83233 100644 Binary files a/Server01/util/__pycache__/verifyJWT.cpython-39.pyc and b/Server01/util/__pycache__/verifyJWT.cpython-39.pyc differ diff --git a/Server01/views/__pycache__/comment.cpython-39.pyc b/Server01/views/__pycache__/comment.cpython-39.pyc index eaf9572..06a67c4 100644 Binary files a/Server01/views/__pycache__/comment.cpython-39.pyc and b/Server01/views/__pycache__/comment.cpython-39.pyc differ diff --git a/Server01/views/__pycache__/post.cpython-39.pyc b/Server01/views/__pycache__/post.cpython-39.pyc index e9eeb19..c798fdb 100644 Binary files a/Server01/views/__pycache__/post.cpython-39.pyc and b/Server01/views/__pycache__/post.cpython-39.pyc differ diff --git a/Server01/views/comment.py b/Server01/views/comment.py index ac202c9..6f368a2 100644 --- a/Server01/views/comment.py +++ b/Server01/views/comment.py @@ -2,8 +2,10 @@ from django.http import JsonResponse -from Server01.models import Comment +from Server01.models import Comment, Post +from Server01.util.auxiliaryFuction import convert_to_timezone, filter_querySet from Server01.util.verifyJWT import authenticate_request +from webServer.settings import TIME_ZONE @authenticate_request @@ -13,3 +15,28 @@ def do_comment(request, verify_payload): data['user_id'] = user_id comment = Comment.objects.create(**data) return JsonResponse({'info': '评论已发送!', 'id': comment.id}, status=200) + + +def get_comment(request): + data = json.loads(request.body) + post_id = data['id'] + offset = data['offset'] + comments = Post.objects.filter(id=post_id).first().comments.all() + filter_comments = filter_querySet(comments, offset, limit=5) + if filter_comments: + data = [ + { + 'id': comment.id, + 'content': comment.content, + 'createTime': convert_to_timezone(comment.created_at, TIME_ZONE), + 'user': { + 'id': comment.user.id, + 'username': comment.user.username, + 'avatar': comment.user.avatar + } + } for comment in filter_comments if comment + ] + return JsonResponse({'info': data}, status=200) + return JsonResponse({'info': []}, status=200) + + diff --git a/Server01/views/post.py b/Server01/views/post.py index bc0cb18..ea64b14 100644 --- a/Server01/views/post.py +++ b/Server01/views/post.py @@ -51,19 +51,6 @@ def get_post_detail(request): 'title': post.title, 'id': post.id, 'imgs': [img.imagePath for img in imgs], - 'comment': [ - { - 'id': comment.id, - 'content': comment.content, - 'createTime': convert_to_timezone(comment.created_at, TIME_ZONE), - 'user': { - 'id': comment.user.id, - 'username': comment.user.username, - 'avatar': comment.user.avatar - } - - } for comment in post.comments.all() - ], 'user': { 'id': post.user.id, 'username': post.user.username, @@ -72,6 +59,7 @@ def get_post_detail(request): 'createTime': convert_to_timezone(post.created_at, TIME_ZONE), 'likeCount': post.favoritePosts.all().count(), 'collectCount': post.collectedPosts.all().count(), + 'commentCount': post.comments.all().count(), } return JsonResponse({'info': info}, status=200) return JsonResponse({'error': '错误的访问'}, status=404) diff --git a/webServer/__pycache__/settings.cpython-39.pyc b/webServer/__pycache__/settings.cpython-39.pyc index bdb637f..931433d 100644 Binary files a/webServer/__pycache__/settings.cpython-39.pyc and b/webServer/__pycache__/settings.cpython-39.pyc differ diff --git a/webServer/__pycache__/urls.cpython-39.pyc b/webServer/__pycache__/urls.cpython-39.pyc index f3a0725..0018f49 100644 Binary files a/webServer/__pycache__/urls.cpython-39.pyc and b/webServer/__pycache__/urls.cpython-39.pyc differ diff --git a/webServer/urls.py b/webServer/urls.py index 2803f9c..04aa2dd 100644 --- a/webServer/urls.py +++ b/webServer/urls.py @@ -36,5 +36,6 @@ path('post/', post.query_post_index), path('post/control/', post.control_like_collect), # 评论相关 - path('comment/', comment.do_comment) + path('comment/', comment.do_comment), + path('comment/main/', comment.get_comment) ]