def add_message(): """Registers a new message for the user.""" if 'user_id' not in session: abort(401) if request.form['text']: g.db.execute( '''insert into message (author_id, text, pub_date) values (?, ?, ?)''', (session['user_id'], request.form['text'], int(time.time()))) g.db.commit() flash('Your message was recorded') return redirect(url_for('timeline'))
def unfollow_user(username): """Removes the current user as follower of the given user.""" if not g.user: abort(401) whom_id = get_user_id(username) if whom_id is None: abort(404) g.db.execute('delete from follower where who_id=? and whom_id=?', [session['user_id'], whom_id]) g.db.commit() flash('You are no longer following "%s"' % username) return redirect(url_for('user_timeline', username=username))
def follow_user(username): """Adds the current user as follower of the given user.""" if not g.user: abort(401) whom_id = get_user_id(username) if whom_id is None: abort(404) g.db.execute('insert into follower (who_id, whom_id) values (?, ?)', [session['user_id'], whom_id]) g.db.commit() flash('You are now following "%s"' % username) return redirect(url_for('user_timeline', username=username))
def add_entry(): if not session.get('logged_in'): abort(401) title = request.form['title'] text = request.form['text'] if not title or not text: flash('title and text is required!') return redirect(url_for('show_entries')) g.db.execute('insert into entries (title, text) values (?, ?)', [request.form['title'], request.form['text']]) g.db.commit() flash('New entry was successfully posted') return redirect(url_for('show_entries'))
def user_timeline(username): """Display's a users tweets.""" profile_user = query_db('select * from user where username = ?', [username], one=True) if profile_user is None: abort(404) followd = False if g.user: followed = query_db('''select 1 from follower where follower.who_id = ? and follower.whom_id = ?''', [session['user_id'], profile_user['user_id']], one=True) is not None return render_template('timeline.html', messages=query_db( ''' select message.*, user.* from message, user where user.user_id = message.author_id and user.user_id = ? order by message.pub_date desc limit ?''', [profile_user['user_id'], PER_PAGE]), followed=followed, profile_user=profile_user)
def index(): spoon.abort(404)