Beispiel #1
0
def tweet():
    tweet_form = TweetForm()
    if tweet_form.validate_on_submit():
        with models.database.transaction():
            models.Tweet.create(user=current_user._get_current_object(),
                                content=tweet_form.content.data.strip())
        flash('You just tweeted. :)', 'success')
        return redirect(url_for('index'))

    return render_template('tweet.html', tweet_form=tweet_form)
Beispiel #2
0
def user(user_id):
    user = User.query.get_or_404(user_id)
    tweet_form = TweetForm()

    if tweet_form.validate_on_submit() and g.logged_user:
        tweet = Tweet(g.logged_user, tweet_form.content.data)
        db.session.add(tweet)
        db.session.commit()
        tweet_form.content.data = ''  # TODO: keksi siistimpi keino
        flash(u'Uusi töötti lisätty!')

    return render_template('user.html', user=user, tweet_form=tweet_form)
Beispiel #3
0
def show_tweets():
    if "user_id" not in session:
        flash("Please login first!", "danger")
        return redirect('/')
    form = TweetForm()
    all_tweets = Tweet.query.all()
    if form.validate_on_submit():
        text = form.text.data
        new_tweet = Tweet(text=text, user_id=session['user_id'])
        db.session.add(new_tweet)
        db.session.commit()
        flash('Tweet Created!', 'success')
        return redirect('/tweets')

    return render_template("tweets.html", form=form, tweets=all_tweets)
Beispiel #4
0
def show_tweets():
    """Show all tweets"""

    if "user_id" not in session:
        flash('Please log in first.', 'danger')
        return redirect('/login')

    form = TweetForm()
    all_tweets = Tweet.query.all()
    if form.validate_on_submit():
        text = form.text.data
        new_tweet = Tweet(text=text, user_id=session['user_id'])
        db.session.add(new_tweet)
        db.session.commit()

        flash('Successfully created tweet!', 'success')
        return redirect('/tweets')
    else:
        return render_template('tweets.html', form=form, tweets=all_tweets)
Beispiel #5
0
def tweet():
    if "user_id" not in session:
        return redirect("/")

    form = TweetForm()

    if form.validate_on_submit():
        tweet = form.tweet.data

        new_tweet = Tweet(tweet=tweet, user_id=session["user_id"])

        db.session.add(new_tweet)
        db.session.commit()

        flash("Tweet created", "success")

        return redirect("/")

    return render_template("tweets.html", form=form)
Beispiel #6
0
def show_tweets():
    if "user_id" not in session:
        flash('Please login first.', 'danger')
        return redirect('/')
    
    form = TweetForm()
    all_tweets = Tweet.query.all()

    if form.validate_on_submit():
        text = form.text.data
        user = User.query.get(session['user_id'])
        new_tweet = Tweet(text=text, user_id=user.id)

        db.session.add(new_tweet)
        db.session.commit()

        flash(f'{user.username} Successfully Created a Tweet.', 'success')
        return redirect('/tweets')

    return render_template('tweets.html', form=form, tweets=all_tweets)
Beispiel #7
0
def show_tweets():

    # if not session['user_id']:
    if 'user_id' not in session:
        flash("Please sign in first to see tweets", "danger")
        return redirect('/')

    form = TweetForm()

    all_tweets = Tweet.query.all()

    if form.validate_on_submit():
        text = form.text.data

        new_tweet = Tweet(text=text, user_id=session['user_id'])
        db.session.add(new_tweet)
        db.session.commit()

        flash(f"{new_tweet.user.username} you just created a new tweet!",
              "success")
        return redirect("/tweets")

    return render_template('tweets.html', form=form, tweets=all_tweets)
Beispiel #8
0
def show_tweets():
    """"""

    if "user_id" not in session:
        flash("Please login first!", "danger")
        return redirect('/')

    # The code below will only run if there is a logged in user.

    # We could put this form instance above the if stmt, and it wouldn't affect what the user sees, but there's no sense in creating an instance of the form if we are just going to redirect anyway.
    form = TweetForm()

    all_tweets = Tweet.query.all()

    if form.validate_on_submit():
        text = form.text.data
        new_tweet = Tweet(text=text, user_id=session["user_id"])

        db.session.add(new_tweet)
        db.session.commit()
        flash("Tweet Created!", "success")
        return redirect('/tweets')

    return render_template("tweets.html", form=form, tweets=all_tweets)