Skip to content

Commit

Permalink
Removed the useless apishowcase example
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Apr 11, 2010
1 parent 0b8e01b commit 03168a5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 89 deletions.
30 changes: 0 additions & 30 deletions examples/apishowcase/apishowcase.py

This file was deleted.

7 changes: 0 additions & 7 deletions examples/apishowcase/static/style.css

This file was deleted.

12 changes: 0 additions & 12 deletions examples/apishowcase/templates/counter.html

This file was deleted.

13 changes: 0 additions & 13 deletions examples/apishowcase/templates/hello.html

This file was deleted.

11 changes: 0 additions & 11 deletions examples/apishowcase/templates/index.html

This file was deleted.

8 changes: 0 additions & 8 deletions examples/apishowcase/templates/layout.html

This file was deleted.

38 changes: 30 additions & 8 deletions examples/minitwit/minitwit.py
@@ -1,4 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
MiniTwit
~~~~~~~~
A microblogging application written with Flask and sqlite3.
:copyright: (c) 2010 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
from __future__ import with_statement from __future__ import with_statement
import re import re
import time import time
Expand Down Expand Up @@ -66,21 +75,26 @@ def before_request():
up the current user so that we know he's there. up the current user so that we know he's there.
""" """
g.db = connect_db() g.db = connect_db()
g.user = None
if 'user_id' in session: if 'user_id' in session:
g.user = query_db('select * from user where user_id = ?', g.user = query_db('select * from user where user_id = ?',
[session['user_id']], one=True) [session['user_id']], one=True)




@app.request_shutdown @app.request_shutdown
def after_request(request): def after_request(response):
"""Closes the database again at the end of the request.""" """Closes the database again at the end of the request."""
g.db.close() g.db.close()
return request return response




@app.route('/') @app.route('/')
def timeline(): def timeline():
if not 'user_id' in session: """Shows a users timeline or if no user is logged in it will
redirect to the public timeline. This timeline shows the user's
messages as well as all the messages of followed users.
"""
if not g.user:
return redirect(url_for('public_timeline')) return redirect(url_for('public_timeline'))
offset = request.args.get('offset', type=int) offset = request.args.get('offset', type=int)
return render_template('timeline.html', messages=query_db(''' return render_template('timeline.html', messages=query_db('''
Expand All @@ -95,6 +109,7 @@ def timeline():


@app.route('/public') @app.route('/public')
def public_timeline(): def public_timeline():
"""Displays the latest messages of all users."""
return render_template('timeline.html', messages=query_db(''' return render_template('timeline.html', messages=query_db('''
select message.*, user.* from message, user select message.*, user.* from message, user
where message.author_id = user.user_id where message.author_id = user.user_id
Expand All @@ -103,12 +118,13 @@ def public_timeline():


@app.route('/<username>') @app.route('/<username>')
def user_timeline(username): def user_timeline(username):
"""Display's a users tweets."""
profile_user = query_db('select * from user where username = ?', profile_user = query_db('select * from user where username = ?',
[username], one=True) [username], one=True)
if profile_user is None: if profile_user is None:
abort(404) abort(404)
followd = False followd = False
if 'user_id' in session: if g.user:
followed = query_db('''select 1 from follower where followed = query_db('''select 1 from follower where
follower.who_id = ? and follower.whom_id = ?''', follower.who_id = ? and follower.whom_id = ?''',
[session['user_id'], profile_user['user_id']], one=True) is not None [session['user_id'], profile_user['user_id']], one=True) is not None
Expand All @@ -122,7 +138,8 @@ def user_timeline(username):


@app.route('/<username>/follow') @app.route('/<username>/follow')
def follow_user(username): def follow_user(username):
if not 'user_id' in session: """Adds the current user as follower of the given user"""
if not g.user:
abort(401) abort(401)
whom_id = get_user_id(username) whom_id = get_user_id(username)
if whom_id is None: if whom_id is None:
Expand All @@ -136,7 +153,8 @@ def follow_user(username):


@app.route('/<username>/unfollow') @app.route('/<username>/unfollow')
def unfollow_user(username): def unfollow_user(username):
if not 'user_id' in session: """Removes the current user as follower of the given user"""
if not g.user:
abort(401) abort(401)
whom_id = get_user_id(username) whom_id = get_user_id(username)
if whom_id is None: if whom_id is None:
Expand All @@ -150,6 +168,7 @@ def unfollow_user(username):


@app.route('/add_message', methods=['POST']) @app.route('/add_message', methods=['POST'])
def add_message(): def add_message():
"""Registers a new message for the user"""
if 'user_id' not in session: if 'user_id' not in session:
abort(401) abort(401)
if request.form['text']: if request.form['text']:
Expand All @@ -163,7 +182,8 @@ def add_message():


@app.route('/login', methods=['GET', 'POST']) @app.route('/login', methods=['GET', 'POST'])
def login(): def login():
if 'user_id' in session: """Logs the user in"""
if g.user:
return redirect(url_for('timeline')) return redirect(url_for('timeline'))
error = None error = None
if request.method == 'POST': if request.method == 'POST':
Expand All @@ -183,7 +203,8 @@ def login():


@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
if 'user_id' in session: """Registers the user"""
if g.user:
return redirect(url_for('timeline')) return redirect(url_for('timeline'))
error = None error = None
if request.method == 'POST': if request.method == 'POST':
Expand Down Expand Up @@ -211,6 +232,7 @@ def register():


@app.route('/logout') @app.route('/logout')
def logout(): def logout():
"""Logs the user out"""
flash('You were logged out') flash('You were logged out')
session.pop('user_id', None) session.pop('user_id', None)
return redirect(url_for('public_timeline')) return redirect(url_for('public_timeline'))
Expand Down

0 comments on commit 03168a5

Please sign in to comment.