From 03168a5d53457fdb8676a4ac9fca0f76a23c6852 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 11 Apr 2010 17:58:45 +0200 Subject: [PATCH] Removed the useless apishowcase example --- examples/apishowcase/apishowcase.py | 30 ---------------- examples/apishowcase/static/style.css | 7 ---- examples/apishowcase/templates/counter.html | 12 ------- examples/apishowcase/templates/hello.html | 13 ------- examples/apishowcase/templates/index.html | 11 ------ examples/apishowcase/templates/layout.html | 8 ----- examples/minitwit/minitwit.py | 38 ++++++++++++++++----- 7 files changed, 30 insertions(+), 89 deletions(-) delete mode 100644 examples/apishowcase/apishowcase.py delete mode 100644 examples/apishowcase/static/style.css delete mode 100644 examples/apishowcase/templates/counter.html delete mode 100644 examples/apishowcase/templates/hello.html delete mode 100644 examples/apishowcase/templates/index.html delete mode 100644 examples/apishowcase/templates/layout.html diff --git a/examples/apishowcase/apishowcase.py b/examples/apishowcase/apishowcase.py deleted file mode 100644 index b3ab2dd1..00000000 --- a/examples/apishowcase/apishowcase.py +++ /dev/null @@ -1,30 +0,0 @@ -from flask import Flask, abort, redirect, request, session, \ - render_template, url_for - -#: create a new flask applications. We pass it the name of our module -#: so that flask knows where to look for templates and static files. -app = Flask(__name__) - - -@app.route('/', methods=['GET']) -def index(): - """Show an overview page""" - return render_template('index.html') - - -@app.route('/hello/', methods=['GET', 'POST']) -def hello_user(): - """Ask the user for a name and redirect to :func:`hello`""" - if request.method == 'POST': - return redirect(url_for('hello', name=request.form['name'])) - return render_template('hello.html', name=None) - - -@app.route('/hello/', methods=['GET']) -def hello(name): - """Greet name friendly""" - return render_template('hello.html', name=name) - - -if __name__ == '__main__': - app.run(debug=True) diff --git a/examples/apishowcase/static/style.css b/examples/apishowcase/static/style.css deleted file mode 100644 index 65a9ec14..00000000 --- a/examples/apishowcase/static/style.css +++ /dev/null @@ -1,7 +0,0 @@ -body { - font-family: 'Trebuchet MS', sans-serif; -} - -a { - color: #44AD80; -} diff --git a/examples/apishowcase/templates/counter.html b/examples/apishowcase/templates/counter.html deleted file mode 100644 index ef888995..00000000 --- a/examples/apishowcase/templates/counter.html +++ /dev/null @@ -1,12 +0,0 @@ -{% extends "layout.html" %} -{% block body %} -

- This is an example application that shows how - the Werkzeug powered Flask microframework works. -

- The various parts of the example application: -

-{% endblock %} diff --git a/examples/apishowcase/templates/hello.html b/examples/apishowcase/templates/hello.html deleted file mode 100644 index dc86737c..00000000 --- a/examples/apishowcase/templates/hello.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "layout.html" %} -{% block body %} - {% if name %} -

Hello {{ name }}!

- {% else %} -

Hello Stranger …

-
-

… What's your name? -

- -

- {% endif %} -{% endblock %} diff --git a/examples/apishowcase/templates/index.html b/examples/apishowcase/templates/index.html deleted file mode 100644 index d210d54f..00000000 --- a/examples/apishowcase/templates/index.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "layout.html" %} -{% block body %} -

- This is an example application that shows how - the Werkzeug powered Flask microframework works. -

- The various parts of the example application: -

-{% endblock %} diff --git a/examples/apishowcase/templates/layout.html b/examples/apishowcase/templates/layout.html deleted file mode 100644 index 166d39ec..00000000 --- a/examples/apishowcase/templates/layout.html +++ /dev/null @@ -1,8 +0,0 @@ - -Flask API Showcase - -

Flask API Showcase

-{% if request.endpoint != 'index' %} - -{% endif %} -{% block body %}{% endblock %} diff --git a/examples/minitwit/minitwit.py b/examples/minitwit/minitwit.py index 06168746..f3bbe7c3 100644 --- a/examples/minitwit/minitwit.py +++ b/examples/minitwit/minitwit.py @@ -1,4 +1,13 @@ # -*- 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 import re import time @@ -66,21 +75,26 @@ def before_request(): up the current user so that we know he's there. """ g.db = connect_db() + g.user = None if 'user_id' in session: g.user = query_db('select * from user where user_id = ?', [session['user_id']], one=True) @app.request_shutdown -def after_request(request): +def after_request(response): """Closes the database again at the end of the request.""" g.db.close() - return request + return response @app.route('/') 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')) offset = request.args.get('offset', type=int) return render_template('timeline.html', messages=query_db(''' @@ -95,6 +109,7 @@ def timeline(): @app.route('/public') def public_timeline(): + """Displays the latest messages of all users.""" return render_template('timeline.html', messages=query_db(''' select message.*, user.* from message, user where message.author_id = user.user_id @@ -103,12 +118,13 @@ def public_timeline(): @app.route('/') 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 'user_id' in session: + 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 @@ -122,7 +138,8 @@ def user_timeline(username): @app.route('//follow') 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) whom_id = get_user_id(username) if whom_id is None: @@ -136,7 +153,8 @@ def follow_user(username): @app.route('//unfollow') 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) whom_id = get_user_id(username) if whom_id is None: @@ -150,6 +168,7 @@ def unfollow_user(username): @app.route('/add_message', methods=['POST']) def add_message(): + """Registers a new message for the user""" if 'user_id' not in session: abort(401) if request.form['text']: @@ -163,7 +182,8 @@ def add_message(): @app.route('/login', methods=['GET', 'POST']) def login(): - if 'user_id' in session: + """Logs the user in""" + if g.user: return redirect(url_for('timeline')) error = None if request.method == 'POST': @@ -183,7 +203,8 @@ def login(): @app.route('/register', methods=['GET', 'POST']) def register(): - if 'user_id' in session: + """Registers the user""" + if g.user: return redirect(url_for('timeline')) error = None if request.method == 'POST': @@ -211,6 +232,7 @@ def register(): @app.route('/logout') def logout(): + """Logs the user out""" flash('You were logged out') session.pop('user_id', None) return redirect(url_for('public_timeline'))