From 66d54460f02002226fde95e78e88726420a91ab0 Mon Sep 17 00:00:00 2001 From: xishandong Date: Mon, 17 Jul 2023 15:36:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=84=E8=AE=BA=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/__pycache__/comment.cpython-39.pyc | Bin 1500 -> 2286 bytes Server01/views/comment.py | 31 ++++++++++++++++-- webServer/__pycache__/settings.cpython-39.pyc | Bin 2663 -> 2644 bytes webServer/__pycache__/urls.cpython-39.pyc | Bin 1737 -> 1777 bytes webServer/urls.py | 3 +- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Server01/views/__pycache__/comment.cpython-39.pyc b/Server01/views/__pycache__/comment.cpython-39.pyc index 06a67c4e0d029f83b3afb01c47f72290aec802c9..636f3b8d989cdde768bffd5e5f76243be4960c8e 100644 GIT binary patch delta 1245 zcmZ8g&2QX96rUN7$6nj(Y^u=D&`8Xbz5pl6pMQ&!2?#dtAu@iyh zWe?4D50QHT}H*~W7Z<|GC%f>?W950jk}a6 zU%IlhOJ2}8l%Di=NjxJ1*@bsc(lru=hq%|{h_?1>v7J|71dqxh|45a?A}1B$_?z>c!YIh0WOXWvCW)%m?~b z^V+&NcLzNB9fX?*R{##0pRJo$=D{k@0*F8yamuO31cm!=Zga|xnj3tXdd`WXSOAgGb7*4`jpg(ufYv=eec61+7aqI?F0&1x0d?V?ry*=60``{(dsHt$ ze1igh3t&w$1E#v@*Ho!5NeeCd8gMt0SyZJ>|?q1H$smAj-C$MgYtm0we! z+udgp$TK8@=wtvScBktooRVldj_7n?S7Aqe4d6fhFw)$%K3vx~AQ186(PHLp1RQVV zzTw5zb%fxa#NQbIUG$y*7cQW64`8L~@Js&Xv`FN-p|e@ybK{6<{0Cdxh(-sP-8BxS zb)mOsz&?EW`R}h@{r1J~ug&C_@AvyJVU|&#F{FD4vk3UV=rafl0Ij{**JWkY(ppKH zo^sk+smdeA5IdeSi()r((&x}ZiN)b&KLtIQUP0dfJ5uYN9%K>HOFZ!j|7TEYpaJ2r zBN3dXdIe(9tm(Mz$w88D6^rueVpiOfDlLuXTL0Mptg41ad-2Sg(mP5oEkh#aHSgQ0 dKr!i+=4<=bc~qv$0vf>61L*}8qn_(t_y-pv5AXm0 delta 588 zcmYLG&59H;5KeV>(wXj_AJL);xB!|GX*+UP|q~u4-uvH|JG(#)X{8Y9_ZoeuJyN!7XsqPdI~6 zy>*U3s*ld-+}*$>xk9J@CA~r`Pj(uwahb>P#$DkC3&sfZ*QmiSOg}4-0iz9MVEfuQ zQ)KxG`p@HVB0|%oCe>n5a~VTRud%V2zHy!vnVf^2qZKtGQ;5}9cMm+J-Ge7FZ4<xc%W;-^Uh+V7SHlY2bS>7yTVrWex18N69p4x!g1|W!lnsWzw-~kDoKO`D} z7#mOA7kzW-ke#OGNp<*6%4PdN(w}l+e&Xo(u&5Z%YvGzW^_1o?R-fsk-GQOhiJSop LO!>%lAfSH%Yx;=r diff --git a/Server01/views/comment.py b/Server01/views/comment.py index 6f368a2..9decc82 100644 --- a/Server01/views/comment.py +++ b/Server01/views/comment.py @@ -1,8 +1,9 @@ import json +from django.db.models import Count from django.http import JsonResponse -from Server01.models import Comment, Post +from Server01.models import Comment from Server01.util.auxiliaryFuction import convert_to_timezone, filter_querySet from Server01.util.verifyJWT import authenticate_request from webServer.settings import TIME_ZONE @@ -21,7 +22,7 @@ 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() + comments = Comment.objects.filter(post_id=post_id, parent_comment=None).annotate(reply_count=Count('replies')) filter_comments = filter_querySet(comments, offset, limit=5) if filter_comments: data = [ @@ -33,10 +34,34 @@ def get_comment(request): 'id': comment.user.id, 'username': comment.user.username, 'avatar': comment.user.avatar - } + }, + 'replyCount': comment.reply_count, + 'replies': [] } for comment in filter_comments if comment ] return JsonResponse({'info': data}, status=200) return JsonResponse({'info': []}, status=200) +def load_reply(request): + data = json.loads(request.body) + id = data['id'] + offset = data['offset'] + comment = Comment.objects.filter(id=id).first() + if comment: + replies = comment.replies.all() + filter_replies = filter_querySet(replies, offset, limit=5) + 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_replies if comment + ] + return JsonResponse({'info': data, 'count': len(data)}, status=200) + return JsonResponse({'error': '错误的操作'}, status=404) \ No newline at end of file diff --git a/webServer/__pycache__/settings.cpython-39.pyc b/webServer/__pycache__/settings.cpython-39.pyc index 9cda3c6ba781709db3ea16f19f524baa47136f82..fb35fda3fe441f096367f9241a22af8769762919 100644 GIT binary patch delta 134 zcmaDZaz%tUk(ZZ?0SMyWZ%Hwm$U7xoC`C9$WDZ*Y_??+X8`~sNF(q7 diff --git a/webServer/__pycache__/urls.cpython-39.pyc b/webServer/__pycache__/urls.cpython-39.pyc index 0c9e907491a570db6782db27475f5f2d9e7f9ac8..f96b3417d0b491e4f18f3e4f7ab3ac6573f1f22d 100644 GIT binary patch delta 129 zcmX@f`;k{Wk(ZZ?0SF#F-;%=3&cN^(#6bq)K#l_t7xPTi{wtEok|LSPktNs6lr9=2 zpCT2^peeoCh;a_Ha1~#2er|4RUWtBDYC%q=zMrPT=8G&9j66|XIr)hx@nF%(o@_ph OMw6$p88I_*y#N3nZXfUf delta 88 zcmey!dy-c>k(ZZ?0SNTAZb`Yt#=!6x#6bpPK#l_t7c))N{>zmv5+#=+8O)$5wb_Po c4l}c#ru^pDEESBC^VxhD4JPklGh%!R0QdtF5C8xG diff --git a/webServer/urls.py b/webServer/urls.py index 75324b5..e5e5f30 100644 --- a/webServer/urls.py +++ b/webServer/urls.py @@ -41,5 +41,6 @@ path('post/delete/', post.post_delete), # 评论相关 path('comment/', comment.do_comment), - path('comment/main/', comment.get_comment) + path('comment/main/', comment.get_comment), + path('comment/reply/', comment.load_reply) ]