예제 #1
0
def my_profile_view(request):
    # if(User.is_authenticated):
    #     username = User.get_username
    username = None
    following = 0
    followTweets = []
    peopleToFollow = []
    if request.user.is_authenticated:
        username = request.user.username
        userdata = TwitterUser.objects.filter(user=request.user)
        allTwitterUsers = TwitterUser.objects.all()
        userTweets = Tweet.objects.filter(author=request.user)
        logged_in_user_tweet_count = userTweets.count
        #presentuser = TwitterUser.objects.get(user=request.user)
        followTweets.append(Tweet.objects.filter(author=request.user))
        for user in userdata:
            if user.following:
                following = user.following.count
            else:
                following = 0

        print(followTweets)
        return render(
            request, "myprofile.html", {
                'userprofile': username,
                'following': following,
                'followTweets': followTweets,
                'logged_in_user_tweet_count': logged_in_user_tweet_count
            })
    else:

        form = LoginForm()
        return HttpResponseRedirect(reverse('login'))
예제 #2
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            #form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            #messages.error(request, f'Dont have an account, please sign up')
            if user:
                login(request, user)
                return HttpResponseRedirect(request.GET.get(
                    "next", "/profile"))
    else:
        form = LoginForm()
        return render(request, "login.html", {'form': form})
예제 #3
0
def profile_view(request):
    # if(User.is_authenticated):
    #     username = User.get_username
    username = None
    following = 0
    followTweets = []
    peopleToFollow = []
    tweetsnewlist = []
    notifications = 0
    if request.user.is_authenticated:
        username = request.user.username
        userdata = TwitterUser.objects.filter(user=request.user)
        curuser = TwitterUser.objects.get(user=request.user)
        all_notifications = Notification.objects.filter(tweetfor=curuser)
        notifications = all_notifications.count
        allTwitterUsers = TwitterUser.objects.all()
        userTweets = Tweet.objects.filter(author=request.user)
        logged_in_user_tweet_count = userTweets.count
        #presentuser = TwitterUser.objects.get(user=request.user)
        followTweets.append(Tweet.objects.filter(author=request.user))
        for user in userdata:
            if user.following:
                following = user.following.count
            else:
                following = 0
            for follow in user.following.all():
                followTweets.append(Tweet.objects.filter(author=follow.user))
        for curtwitteruser in allTwitterUsers:
            if curtwitteruser not in user.following.all(
            ) and not curtwitteruser.user == request.user:
                peopleToFollow.append(curtwitteruser)
        for tweet in followTweets:
            for curtweet in tweet:
                tweetsnewlist.append(curtweet)
        tweetsnewlist.sort(key=lambda present_tweet: present_tweet.created)
        print(followTweets)
        return render(
            request, "profile.html", {
                'userprofile': username,
                'following': following,
                'followTweets': tweetsnewlist,
                'peopleToFollow': peopleToFollow,
                'logged_in_user_tweet_count': logged_in_user_tweet_count,
                'notifications': notifications
            })
    else:

        form = LoginForm()
        return HttpResponseRedirect(reverse('login'))
예제 #4
0
def follower_view(request, authorname):
    # if(User.is_authenticated):
    #     username = User.get_username
    username = authorname
    following = 0
    followTweets = []
    peopleToFollow = []
    follow_status = 0
    if request.user.is_authenticated:
        logged_in_twitterUser = TwitterUser.objects.get(user=request.user)
        curuser = TwitterUser.objects.get(user=User.objects.get(
            username=authorname))
        print(curuser)
        allTwitterUsers = TwitterUser.objects.all()
        userTweets = Tweet.objects.filter(author=User.objects.get(
            username=authorname))
        logged_in_user_tweet_count = userTweets.count
        followTweets.append(
            Tweet.objects.filter(author=User.objects.get(username=authorname)))
        if curuser.following:
            following = curuser.following.count
        if curuser in logged_in_twitterUser.following.all():
            follow_status = 1
        if curuser == logged_in_twitterUser:
            follow_status = 2

        return render(
            request, "followerprofile.html", {
                'userprofile': username,
                'following': following,
                'followTweets': followTweets,
                'logged_in_user_tweet_count': logged_in_user_tweet_count,
                'follow_status': follow_status
            })
    else:

        form = LoginForm()
        return HttpResponseRedirect(reverse('login'))