diff --git a/Server01/static/img/post/64-img1.jpg b/Server01/static/img/post/64-img1.jpg new file mode 100644 index 0000000..d7e47b3 Binary files /dev/null and b/Server01/static/img/post/64-img1.jpg differ diff --git a/Server01/static/img/post/65-img4.jpg b/Server01/static/img/post/65-img4.jpg new file mode 100644 index 0000000..a7a0d2d Binary files /dev/null and b/Server01/static/img/post/65-img4.jpg differ diff --git a/Server01/static/img/post/65-project.png b/Server01/static/img/post/65-project.png new file mode 100644 index 0000000..7eadfc8 Binary files /dev/null and b/Server01/static/img/post/65-project.png differ diff --git a/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc b/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc index d257264..ac2ab7f 100644 Binary files a/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc and b/Server01/util/__pycache__/auxiliaryFuction.cpython-39.pyc differ diff --git a/Server01/util/__pycache__/verifyJWT.cpython-39.pyc b/Server01/util/__pycache__/verifyJWT.cpython-39.pyc index 6de5b83..5322381 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/util/auxiliaryFuction.py b/Server01/util/auxiliaryFuction.py index 3beceb7..66de6aa 100644 --- a/Server01/util/auxiliaryFuction.py +++ b/Server01/util/auxiliaryFuction.py @@ -3,6 +3,7 @@ import pytz import Server01.models as models +from webServer.settings import TIME_ZONE # 更换时区 @@ -54,3 +55,33 @@ def filter_querySet(querySet, offset, limit=20): filterQuerySet = querySet.order_by('-id')[start:end] return filterQuerySet return [] + + +def get_user_post_info(posts, offset): + clear_posts = filter_querySet(posts, offset, 10) + info = [{ + 'date': convert_to_timezone(post.created_at, TIME_ZONE), + 'title': post.title, + 'likeCount': post.favoritePosts.count(), + 'collectCount': post.collectedPosts.count(), + 'commentCount': post.comments.count(), + 'content': post.content, + 'id': post.id, + 'username': post.user.username, + } for post in clear_posts if post] + return info + + +def get_user_info(users, offset): + clear_users = filter_querySet(users, offset, 10) + info = [ + { + 'username': user.username, + 'avatar': user.avatar, + 'id': user.id, + 'fans': user.beFocusOn.count(), + 'follow': user.following.count(), + 'note': user.posts.count() + } for user in clear_users + ] + return info diff --git a/Server01/util/verifyJWT.py b/Server01/util/verifyJWT.py index cb2f17c..9ddd957 100644 --- a/Server01/util/verifyJWT.py +++ b/Server01/util/verifyJWT.py @@ -25,6 +25,7 @@ def wrapper(request, *args, **kwargs): error_message = {'error': '非法的token'} return JsonResponse(error_message, status=401) except AttributeError as e: + print(e) error_message = {'error': '未查询到登录信息,请重新登录'} return JsonResponse(error_message, status=403) diff --git a/Server01/views/__pycache__/user.cpython-39.pyc b/Server01/views/__pycache__/user.cpython-39.pyc index c0f51bd..adc60ac 100644 Binary files a/Server01/views/__pycache__/user.cpython-39.pyc and b/Server01/views/__pycache__/user.cpython-39.pyc differ diff --git a/Server01/views/user.py b/Server01/views/user.py index b7536f8..9db7730 100644 --- a/Server01/views/user.py +++ b/Server01/views/user.py @@ -4,7 +4,7 @@ import Server01.models as models from Server01.util.auxiliaryFuction import check_email, combine_index_post, check_and_delete, filter_querySet, \ - convert_to_timezone + convert_to_timezone, get_user_post_info, get_user_info from Server01.util.verifyJWT import create_token, authenticate_request from webServer.settings import SYSTEM_PATH, TIME_ZONE @@ -130,6 +130,20 @@ def unfollow(request, payload): return JsonResponse({'error': '非法的操作'}, status=401) +@authenticate_request +def remove_fans(request, payload): + # 移除操作的用户id + user_id = payload['user_id'] + user = models.User.objects.filter(id=user_id).first() + # 移除的粉丝id + fans_id = json.loads(request.body)['id'] + fan = models.User.objects.filter(id=fans_id).first() + if user and fan: + fan.following.remove(user) + return JsonResponse({'info': '成功移除粉丝'}, status=200) + return JsonResponse({'error': '非法的操作'}, status=401) + + @authenticate_request def update_user_info(request, payload): data = json.loads(request.body) @@ -161,21 +175,34 @@ def update_avatar(request, payload): @authenticate_request -def user_post_control_index(request, payload): +def user_control_index(request, payload): user_id = payload['user_id'] - offset = json.loads(request.body)['offset'] + data = json.loads(request.body) + offset = data['offset'] + types = data['types'] user = models.User.objects.filter(id=user_id).first() if user: - user_post = user.posts.all() - clear_user_post = filter_querySet(user_post, offset, 10) - 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 clear_user_post if post] - return JsonResponse({'info': info, 'total': user_post.count()}, status=200) - return JsonResponse({'error': '错误的操作'}, status=404) \ No newline at end of file + if types == 'posts': + user_data = user.posts.all() + info = get_user_post_info(user_data, offset) + elif types == 'collected': + user_data = user.collected.all() + info = get_user_post_info(user_data, offset) + elif types == 'favorites': + user_data = user.favorites.all() + info = get_user_post_info(user_data, offset) + elif types == 'fans': + user_data = user.beFocusOn.all() + info = get_user_info(user_data, offset) + elif types == 'follow': + user_data = user.following.all() + info = get_user_info(user_data, offset) + else: + return JsonResponse({'error': '错误的操作'}, status=404) + total = user_data.count() + return JsonResponse({'info': info, 'total': total}, status=200) + return JsonResponse({'error': '错误的操作'}, status=404) + + + + diff --git a/webServer/__pycache__/settings.cpython-39.pyc b/webServer/__pycache__/settings.cpython-39.pyc index b40c2f6..9cda3c6 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 4aa858a..0c9e907 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 b70bf1e..75324b5 100644 --- a/webServer/urls.py +++ b/webServer/urls.py @@ -15,6 +15,7 @@ """ from django.contrib import admin from django.urls import path + from Server01.views import user, post, comment urlpatterns = [ @@ -29,7 +30,8 @@ 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('user/post/control/', user.user_control_index), + path('user/remove/fan/', user.remove_fans), # 帖子相关 path('upload/', post.upload_post), path('upload/info/', post.upload_post_info),