Beispiel #1
0
def profile_timeline(id):
    if request.method == 'POST':
        tweet = Tweets(content=request.form['tweet'],
                       tweet_owner=current_user.id)
        owner_id = tweet.tweet_owner
        owner = User.query.filter_by(id=owner_id).first()
        tweet.owner_nickname = owner.nickname
        tweet.owner_username = owner.username
        db.session.add(tweet)
        db.session.commit()
        return redirect(url_for('profile', id=current_user.id))

    elif request.method == 'DELETE':
        tweet = Tweets.query.filter_by(
            id=id).first()  #Mandar para o controller
        db.session.delete(tweet)  #Mandar para o controller
        db.session.commit()  #Mandar para o controller
        return redirect(url_for('profile'))

    elif request.method == 'GET':
        i = User.query.filter_by(id=current_user.id).first()
        user = User.query.filter_by(id=id).first()
        user_tweets = Tweets.query.filter_by(tweet_owner=id).order_by(
            Tweets.id.desc()).all()
        followers = user.count_followers()
        followed = user.count_followed()
        return render_template('profile.html',
                               user=user,
                               user_tweets=user_tweets,
                               i=i)
Beispiel #2
0
def timeline():
    if request.method == 'POST':
        tweet = Tweets(content=request.form['tweet'],
                       tweet_owner=current_user.id)
        owner_id = tweet.tweet_owner
        owner = User.query.filter_by(id=owner_id).first()
        tweet.owner_nickname = owner.nickname
        tweet.owner_username = owner.username
        db.session.add(tweet)
        db.session.commit()
        return redirect(url_for('timeline'))
    elif request.method == 'GET':
        uid = current_user.id
        user = User.query.filter_by(id=uid).first()
        tweets = user.followed_posts()
        followers = user.count_followers()
        followed = user.count_followed()
        #all_tweets = Tweets.query.filter().order_by(Tweets.id.desc()).all()
        return render_template('timeline.html',
                               tweets=tweets,
                               user=user,
                               followers=followers,
                               followed=followed)