def all_tweets(): """ This method handles All Tweets View. :return: If "GET" rendering template "all_tweets", If "POST" adding new Tweet to db and redirecting back to all_tweets. """ if not session['logged_in']: return redirect(url_for('login')) if request.method == "GET": cnx = connect_db() tweets = Tweet.load_all_tweets(cnx.cursor()) return render_template('all_tweets.html', tweets=tweets) elif request.method == "POST": tweet = Tweet() tweet.user_id = session['user_id'] tweet.text = request.form['new_tweet'] tweet.creation_date = datetime.now() cnx = connect_db() tweet.add_tweet(cnx.cursor()) cnx.commit() return redirect(url_for('all_tweets'))
def testCreateTweet(): new_tweet = Tweet() new_tweet.text = 'gollsdfsdfsdfsfdsdfum' new_tweet.creation_date = datetime.now() print(new_tweet.id) try: cnx = connect(user=user, password=password, host=host, database=database) print("Connected...") cursor = cnx.cursor() new_tweet.add_edit_tweet(cursor) cnx.commit() cursor.close() cnx.close() print('Disconnected...') except ProgrammingError: print("Not connected...")