def user_info_page(request, user_id): html = "user_info_page.html" user = get_object_or_404(User, pk=user_id) other_user = get_user_data(user) logged_user = get_user_data(request.user) followed = False if logged_user["user"] in other_user["followers"].all(): followed = True data = { "other_user": other_user, "logged_user": logged_user, "followed": followed, } return render(request, html, data)
def user_followers(request, user_id): html = "user_list.html" user_q = get_object_or_404(User, pk=user_id) user = get_user_data(user_q)["user"] followers = user.followers.all() data = {"title": f"@{user.handle}'s followers", "users": followers} return render(request, html, data)
def user_following(request, user_id): html = "user_list.html" user_q = get_object_or_404(User, pk=user_id) user_data = get_user_data(user_q) user = user_data["user"] following = user_data["following"] data = {"title": f"@{user.handle}'s followed users", "users": following} return render(request, html, data)
def tweet_post(request): user_data = get_user_data(request.user) html = "tweet_post.html" if request.method == "POST": form = PostTweetForm(request.POST) if form.is_valid(): form_data = form.cleaned_data body = form_data["body"] sender = user_data["user"] mentioned_users, new_body = get_mentioned_users(body) tweet = Tweet.objects.create(sender_id=sender, body=new_body) if mentioned_users is not None: for mentioned_user in mentioned_users: Notification.objects.create(tweet=tweet, tagged=mentioned_user) return redirect("homepage") else: form = PostTweetForm() return render(request, "tweet_post.html", {"form": form})
def user_notifications(request): html = "user_notifications.html" data = get_user_data(request.user) return render(request, html, data)
def user_unfollow(request, user_id): logged_user = get_user_data(request.user)["user"] other_user = get_object_or_404(TwitterUser, pk=user_id) other_user.followers.remove(logged_user) user_id = other_user.id return redirect("userdetail", user_id=user_id)
def user_homepage(request): data = get_user_data(request.user) html = "user_homepage.html" return render(request, html, data)
def user_detail(request, user_id): html = "user_detail.html" user = get_object_or_404(User, pk=user_id) data = get_user_data(user) return render(request, html, data)