예제 #1
0
def tweets(search=None):
    form = TweetForm(request.form)

    # The use either posted a tweet or interacted with a tweet.
    if request.method == 'POST':
        if dispatch_tweet_actions(request.form) == NO_DISPATCH:
            if form.validate():
                try:
                    post_tweet(form.post.data)
                except (DatabaseException, NotLoggedInException) as error:
                    flash(str(error), 'danger')

    if search:
        tweet_posts = search_for_tweets(search)

        # Only notify first time we're getting the page.
        if request.method == 'GET':
            if len(tweet_posts) == 0:
                flash('No tweets found!', 'danger')
            else:
                flash('{number} tweets found!'.format(number=len(tweet_posts)), 'success')
    else:
        tweet_posts = get_newest_tweets(18)

    if session.get('logged_in'):
        user = User(*session['user'])
        followers = get_user_followers(user.user_id)
        return render_template('tweets.html', form=form, tweets=chunks(tweet_posts, 3), followers=followers)
    else:
        return render_template('tweets.html', form=form, tweets=chunks(tweet_posts, 3), followers=[])
예제 #2
0
파일: routes.py 프로젝트: magicaljyy/flask
def add_tweet():
    form = TweetForm(request.form)    
    if request.method == "POST" and form.validate():
        new_tweet = Message(session['uid'], form.text.data)
        db.session.add(new_tweet)
        db.session.commit()
        return redirect(url_for('home'))
    else:
        return redirect(url_for('home'))
예제 #3
0
def post_tweet():
    form = TweetForm()
    if form.validate():
        tweet = Tweet(user_id=current_user.id, text=form.text.data, date_created=datetime.now())
        db.session.add(tweet)
        db.session.commit()
        return redirect(url_for('timeline'))

    return 'Something went wrong.'
예제 #4
0
def post_tweet():
    form = TweetForm()
    if form.validate():
        tweet = Tweet(user_id=current_user.id,
                      text=form.text.data,
                      date_created=datetime.now())
        db.session.add(tweet)
        db.session.commit()
        return redirect(url_for('timeline'))

    return 'Что-то пошло не так'  #todo добавь позже нормальную страницу с ошибкой
예제 #5
0
def post_tweet():
    form = TweetForm()
    # if the method is only post then use only validate because it is obvious
    if form.validate():
        tweet = Tweet(user_id=current_user.id,
                      text=form.text.data,
                      date_created=datetime.now())
        db.session.add(tweet)
        db.session.commit()

        return redirect(url_for('timeline'))
    return 'Something went wrong'
예제 #6
0
def post_tweet():
    form = TweetForm()
    if form.validate():
        #inseram in baza de date
        tweet = Tweet(user_id=current_user.id,
                      text=form.text.data,
                      date_created=datetime.now())
        db.session.add(tweet)
        db.session.commit()
        # ma intorc pe aceasi pagina
        return redirect(url_for('timeline'))

    return 'Something went wrong'
예제 #7
0
def index():
	form = TweetForm(request.form)
	#tweetmaster = Tweet(key_name='tm')
	#t = Tweet(parent=tweetmaster)

	if request.method=='POST' and form.validate():
		tweet_id = "post:" + str(getTweetId())
		content = request.form['tweet']
		date = datetime.datetime.now()
		tweet = {'content': content, 'date': str(date)}
		redis_server.hmset(tweet_id, tweet)
		redis_server.save()
		return redirect(url_for('index'))
		
	retrieve = []
	listOfPostKeys = redis_server.keys('post:*')
	for keys in listOfPostKeys:
		contentOfTweet=redis_server.hgetall(keys)
		retrieve.append(contentOfTweet)
	photo_url = {}
	display = []
	return render_template("index.html", form=form, retrieve=retrieve)