Skip to content

Commit

Permalink
更新用户帖子管理页面
Browse files Browse the repository at this point in the history
  • Loading branch information
xishandong committed Jul 14, 2023
1 parent f83c0b0 commit 15e9600
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 5 deletions.
Binary file modified Server01/__pycache__/models.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Server01/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def delete(self, *args, **kwargs):
self.imgs.all().delete()
# 删除帖子的图片的存储
path = SYSTEM_PATH + 'post/'
check_and_delete(path, self.id)
check_and_delete(mainPath=path, id=self.id)
# 删除帖子本身
super().delete(*args, **kwargs)

Expand Down
Binary file removed Server01/static/img/post/14-金智秀.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/23-img4.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/28-img3.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/34-张娜英.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/35-search.png
Binary file not shown.
Binary file removed Server01/static/img/post/36-池秀媛.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/37-02.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/38-01.jpg
Binary file not shown.
Binary file removed Server01/static/img/post/39-03.gif
Binary file not shown.
Binary file modified Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Server01/util/auxiliaryFuction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def combine_index_post(posts):


# 检查和删除图片,用于删除帖子时删除文件,以及删除用户上一次上传的头像
def check_and_delete(id, mainPath):
def check_and_delete(*, id, mainPath):
# 获取目录下的文件
file_list = os.listdir(mainPath)
# 遍历文件列表,检查是否有对应的文件,如果有就删除
Expand Down
Binary file modified Server01/views/__pycache__/post.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/user.cpython-39.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions Server01/views/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_post_detail(request):
'likeCount': post.favoritePosts.all().count(),
'collectCount': post.collectedPosts.all().count(),
'commentCount': post.comments.all().count(),
'content': post.content
}
return JsonResponse({'info': info}, status=200)
return JsonResponse({'error': '错误的访问'}, status=404)
Expand Down Expand Up @@ -108,3 +109,14 @@ def control_like_collect(request, payload):
user.collected.remove(post)
return JsonResponse({'info': '成功取消收藏'}, status=200)
return JsonResponse({'error': '错误的操作'}, status=404)


@authenticate_request
def post_delete(request, payload):
data = json.loads(request.body)
id = data['id']
post = models.Post.objects.filter(id=id).first()
if post.user.id == payload['user_id']:
post.delete()
return JsonResponse({'success': '帖子删除成功'}, status=200)
return JsonResponse({'error': '错误操作'}, status=404)
26 changes: 23 additions & 3 deletions Server01/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from django.http import JsonResponse

import Server01.models as models
from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet
from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet, \
convert_to_timezone
from Server01.util.verifyJWT import create_token, authenticate_request
from webServer.settings import SYSTEM_PATH
from webServer.settings import SYSTEM_PATH, TIME_ZONE


# 用户登录
Expand Down Expand Up @@ -145,7 +146,7 @@ def update_avatar(request, payload):
file = request.FILES['file']
id = payload['user_id']
file_path = SYSTEM_PATH + 'avatar/' + str(id) + '-' + file.name
check_and_delete(id, SYSTEM_PATH + 'avatar/')
check_and_delete(id=id, mainPath=SYSTEM_PATH + 'avatar/')
with open(file_path, 'wb') as destination:
for chunk in file.chunks():
destination.write(chunk)
Expand All @@ -157,3 +158,22 @@ def update_avatar(request, payload):
user.avatar = 'http://localhost:8000/static/img/avatar/' + str(id) + '-' + file.name
user.save()
return JsonResponse({'info': result}, status=200)


@authenticate_request
def user_post_control_index(request, payload):
user_id = payload['user_id']
user = models.User.objects.filter(id=user_id).first()
if user:
user_post = user.posts.all()
info = [{
'date': convert_to_timezone(post.created_at, TIME_ZONE),
'title': post.title,
'likeCount': post.favoritePosts.all().count(),
'collectCount': post.collectedPosts.all().count(),
'commentCount': post.comments.all().count(),
'content': post.content,
'id': post.id
} for post in user_post if post]
return JsonResponse({'info': info}, status=200)
return JsonResponse({'error': '错误的操作'}, status=404)
Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified webServer/__pycache__/urls.cpython-39.pyc
Binary file not shown.
2 changes: 2 additions & 0 deletions webServer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
path('user/update/', user.update_user_info),
path('user/avatar/', user.update_avatar),
path('user/post/', user.query_user_index_post),
path('user/post/control/', user.user_post_control_index),
# 帖子相关
path('upload/', post.upload_post),
path('upload/info/', post.upload_post_info),
path('post/detail/', post.get_post_detail),
path('post/', post.query_post_index),
path('post/control/', post.control_like_collect),
path('post/delete/', post.post_delete),
# 评论相关
path('comment/', comment.do_comment),
path('comment/main/', comment.get_comment)
Expand Down

0 comments on commit 15e9600

Please sign in to comment.