Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into branch #208

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/nba_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
path('signup/', views.sign_up, name='signup'),
path('login/', views.log_in, name='login'),
path('feed/', views.feed, name='feed'),
path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'),
path('user_followings/', views.user_followings, name='user_followings'),
path('user_followers/', views.user_followers, name='user_followers'),
path('follow_user/<int:user_id>', views.follow_user, name='follow_user'),
path('unfollow_user/<int:user_id>', views.unfollow_user, name='unfollow_user'),
path('profile_view_edit/', views.profile_view_edit, name='profile_view_edit'),
path('profile_view_of_other_users/<int:user_id>', views.profile_view_of_other_users, name='profile_view_of_other_users'),
path('reset_password/', views.reset_password, name='reset_password'),
path('post/', views.post, name='post'),
path('search/', views.search, name='search'),
Expand Down
29 changes: 25 additions & 4 deletions backend/nba_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def profile_view_edit(request):
following_count = user.following.count()
followers_count = user.followers.count()
posts = Post.objects.filter(user=user)
#post_contents = [post.content for post in posts]
data = {
'username': user.username,
'email': user.email,
Expand All @@ -169,11 +168,33 @@ def profile_view_edit(request):
'following_count': following_count,
'followers_count': followers_count,
'profile_picture': user.profile_picture.url if user.profile_picture else None,
'posts': [{'content': post.content, 'created_at': post.created_at} for post in posts]
'posts': [{'content': post.content, 'created_at': post.created_at, 'image':post.image} for post in posts]
}
return render(request, 'profile_view_edit.html', data)
#return JsonResponse(data, status=200)
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':
Expand Down
Loading