From 225d74c0fce77d445db2ca9a799ac32d6e9b6954 Mon Sep 17 00:00:00 2001 From: Fatih Demir <101219059+fatih260@users.noreply.github.com> Date: Sun, 12 May 2024 15:24:32 +0300 Subject: [PATCH 1/4] profile view of users --- backend/nba_app/urls.py | 3 +-- backend/nba_app/views.py | 32 +++++++------------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/backend/nba_app/urls.py b/backend/nba_app/urls.py index 022e7da1..d6d5adc1 100644 --- a/backend/nba_app/urls.py +++ b/backend/nba_app/urls.py @@ -13,8 +13,7 @@ path('user_followers/', views.user_followers, name='user_followers'), path('follow_user/', views.follow_user, name='follow_user'), path('unfollow_user/', views.unfollow_user, name='unfollow_user'), - path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'), - path('profile_view_of_other_users/', views.profile_view_of_other_users, name='profile_view_of_other_users'), + path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'), path('reset_password/', views.reset_password, name='reset_password'), path('post/', views.post, name='post'), path('search/', views.search, name='search'), diff --git a/backend/nba_app/views.py b/backend/nba_app/views.py index ec06871a..042396f9 100644 --- a/backend/nba_app/views.py +++ b/backend/nba_app/views.py @@ -118,7 +118,7 @@ def user_followers(request): return JsonResponse({'followers_info': followers_info}, status=200) -def profile_view_edit(request): +def profile_view_edit(request, user_id): if request.method == 'POST': new_username = request.POST.get('username') new_email = request.POST.get('email') @@ -155,46 +155,28 @@ def profile_view_edit(request): return JsonResponse({'message': 'Account information updated successfully.'}, status=200) # if request.method == 'GET': - user = request.user + user = User.objects.get(user_id=user_id) following_count = user.following.count() followers_count = user.followers.count() posts = Post.objects.filter(user=user) + if request.user == user: + is_following = None + else: + is_following = Follow.objects.filter(follower=request.user, followed=user).exists() data = { 'username': user.username, 'email': user.email, 'bio': user.bio, 'profile_picture': user.profile_picture.url if user.profile_picture else None, - # Add any other fields you want to include in the response 'following_count': following_count, 'followers_count': followers_count, 'profile_picture': user.profile_picture.url if user.profile_picture else None, + 'is_following': is_following, # True if the authenticated user is following the user, False otherwise, None if the authenticated user is the user 'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts] } return JsonResponse(data, status=200) #return render(request, 'profile_view_edit.html', data) -def profile_view_of_other_users(request, user_id): - try: - user = User.objects.get(pk=user_id) - except User.DoesNotExist: - return JsonResponse({'error': 'User not found.'}, status=404) - - following_count = user.following.count() - followers_count = user.followers.count() - posts = Post.objects.filter(user=user) - - is_following = Follow.objects.filter(follower=request.user, followed=user).exists() - - data = { - 'username': user.username, - 'bio': user.bio, - 'profile_picture': user.profile_picture.url if user.profile_picture else None, - 'following_count': following_count, - 'followers_count': followers_count, - 'is_following': is_following, - 'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts] - } - return JsonResponse(data, status=200) def reset_password(request): if request.method != 'POST': From 2416fa6d5bcca619a858382cfd137df74a08b5b2 Mon Sep 17 00:00:00 2001 From: Fatih Demir <101219059+fatih260@users.noreply.github.com> Date: Sun, 12 May 2024 15:35:54 +0300 Subject: [PATCH 2/4] profile view of users --- backend/nba_app/views.py | 43 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/backend/nba_app/views.py b/backend/nba_app/views.py index 042396f9..f8b428e0 100644 --- a/backend/nba_app/views.py +++ b/backend/nba_app/views.py @@ -154,28 +154,27 @@ def profile_view_edit(request, user_id): return JsonResponse({'message': 'Account information updated successfully.'}, status=200) - # if request.method == 'GET': - user = User.objects.get(user_id=user_id) - following_count = user.following.count() - followers_count = user.followers.count() - posts = Post.objects.filter(user=user) - if request.user == user: - is_following = None - else: - is_following = Follow.objects.filter(follower=request.user, followed=user).exists() - data = { - 'username': user.username, - 'email': user.email, - 'bio': user.bio, - 'profile_picture': user.profile_picture.url if user.profile_picture else None, - 'following_count': following_count, - 'followers_count': followers_count, - 'profile_picture': user.profile_picture.url if user.profile_picture else None, - 'is_following': is_following, # True if the authenticated user is following the user, False otherwise, None if the authenticated user is the user - 'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts] - } - return JsonResponse(data, status=200) - #return render(request, 'profile_view_edit.html', data) + if request.method == 'GET': + user = User.objects.get(user_id=user_id) + following_count = user.following.count() + followers_count = user.followers.count() + posts = Post.objects.filter(user=user) + if request.user == user: + is_following = None + else: + is_following = Follow.objects.filter(follower=request.user, followed=user).exists() + data = { + 'username': user.username, + 'email': user.email, + 'bio': user.bio, + 'profile_picture': user.profile_picture.url if user.profile_picture else None, + 'following_count': following_count, + 'followers_count': followers_count, + 'profile_picture': user.profile_picture.url if user.profile_picture else None, + 'is_following': is_following, # True if the authenticated user is following the user, False otherwise, None if the authenticated user is the user + 'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts] + } + return JsonResponse(data, status=200) def reset_password(request): From 7986f316af18587dd78de5992669ea10b4cbf88d Mon Sep 17 00:00:00 2001 From: Fatih Demir <101219059+fatih260@users.noreply.github.com> Date: Sun, 12 May 2024 15:44:29 +0300 Subject: [PATCH 3/4] profile view of users --- backend/nba_app/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/nba_app/views.py b/backend/nba_app/views.py index f8b428e0..75b0b882 100644 --- a/backend/nba_app/views.py +++ b/backend/nba_app/views.py @@ -167,7 +167,6 @@ def profile_view_edit(request, user_id): 'username': user.username, 'email': user.email, 'bio': user.bio, - 'profile_picture': user.profile_picture.url if user.profile_picture else None, 'following_count': following_count, 'followers_count': followers_count, 'profile_picture': user.profile_picture.url if user.profile_picture else None, From f2f18acad86b896a498f813fb9ad198290901d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bilge=20Kaan=20G=C3=BCneyli?= <75316186+kaanguneyli@users.noreply.github.com> Date: Mon, 13 May 2024 22:46:37 +0300 Subject: [PATCH 4/4] try of bug fix --- backend/nba_app/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/nba_app/views.py b/backend/nba_app/views.py index 75b0b882..8540daec 100644 --- a/backend/nba_app/views.py +++ b/backend/nba_app/views.py @@ -96,12 +96,18 @@ def post_detail(request, post_id): print({'post': post, 'comments': comments}) return render(request, 'post_detail.html', {'post': post, 'comments': comments}) """ - +""" def post_detail(request, post_id): post = Post.objects.get(post_id=post_id) comments = Comment.objects.filter(post = post) #post.comments.all() print({'post': post, 'image': post.image, 'comments': comments}) return render(request, 'post_detail.html', {'post': post, 'image': post.image, 'comments': comments}) +""" +def post_detail(request, post_id): + post = Post.objects.get(post_id=post_id) + comments = post.comments.all() + print({'post': post, 'image': post.image.url, 'comments': comments}) + return render(request, 'post_detail.html', {'post': post, 'image': post.image.url, 'comments': comments}) def user_followings(request):