Removed the useless apishowcase example
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 0b8e01b · Browse files · 7 files·+30 added−89 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+30 added−89 removed
- other:+30 added−89 removed
Provenance
- Commit
03168a5- Tree
6e7d4f2- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
0b8e01b
7 files changed+30 added−89 removed
deleted:examples/apishowcase/static/style.css-7 removed
1234567body { font-family: 'Trebuchet MS', sans-serif;}
a { color: #44AD80;}deleted:examples/apishowcase/templates/counter.html-12 removed
123456789101112{% extends "layout.html" %}{% block body %}<p> This is an example application that shows how the Werkzeug powered Flask microframework works.<p> The various parts of the example application:<ul> <li><a href="{{ url_for('hello_user') }}">Hello World</a> <li><a href="{{ url_for('counter') }}">Counter</a></ul>{% endblock %}deleted:examples/apishowcase/templates/hello.html-13 removed
12345678910111213{% extends "layout.html" %}{% block body %} {% if name %} <h2>Hello {{ name }}!</h2> {% else %} <h3>Hello Stranger …</h3> <form action="{{ url_for('hello_user') }}" method="post"> <p>… What's your name? <p><input type=text name=name size=30> <input type=submit value="That's me"> </form> {% endif %}{% endblock %}deleted:examples/apishowcase/templates/index.html-11 removed
1234567891011{% extends "layout.html" %}{% block body %}<p> This is an example application that shows how the Werkzeug powered Flask microframework works.<p> The various parts of the example application:<ul> <li><a href="{{ url_for('hello_user') }}">Hello World</a></ul>{% endblock %}deleted:examples/apishowcase/templates/layout.html-8 removed
12345678<!doctype html><title>Flask API Showcase</title><link rel=stylesheet href="{{ url_for('static', filename='style.css') }}" type=text/css><h1>Flask API Showcase</h1>{% if request.endpoint != 'index' %}<div class=backlink><a href="{{ url_for('index') }}">« back to index</a></div>{% endif %}{% block body %}{% endblock %}deleted:examples/apishowcase/apishowcase.py-30 removed
1-from flask import Flask, abort, redirect, request, session, \2- render_template, url_for3-4-#: create a new flask applications. We pass it the name of our module5-#: so that flask knows where to look for templates and static files.6-app = Flask(__name__)7-8-9-@app.route('/', methods=['GET'])10-def index():11- """Show an overview page"""12- return render_template('index.html')13-14-15-@app.route('/hello/', methods=['GET', 'POST'])16-def hello_user():17- """Ask the user for a name and redirect to :func:`hello`"""18- if request.method == 'POST':19- return redirect(url_for('hello', name=request.form['name']))20- return render_template('hello.html', name=None)21-22-23-@app.route('/hello/<name>', methods=['GET'])24-def hello(name):25- """Greet name friendly"""26- return render_template('hello.html', name=name)27-28-29-if __name__ == '__main__':30- app.run(debug=True)modified:examples/minitwit/minitwit.py+30 added-8 removed
1 # -*- coding: utf-8 -*-2+"""3+ MiniTwit4+ ~~~~~~~~5+6+ A microblogging application written with Flask and sqlite3.7+8+ :copyright: (c) 2010 by Armin Ronacher.9+ :license: BSD, see LICENSE for more details.10+"""11 from __future__ import with_statement12 import re13 import time14 import sqlite359 unmodified lines74 """Make sure we are connected to the database each request and look75 up the current user so that we know he's there.76 """77 g.db = connect_db()78+ g.user = None79 if 'user_id' in session:80 g.user = query_db('select * from user where user_id = ?',81 [session['user_id']], one=True)82 83 84 @app.request_shutdown75-def after_request(request):85+def after_request(response):86 """Closes the database again at the end of the request."""87 g.db.close()78- return request88+ return response89 90 91 @app.route('/')92 def timeline():83- if not 'user_id' in session:93+ """Shows a users timeline or if no user is logged in it will94+ redirect to the public timeline. This timeline shows the user's95+ messages as well as all the messages of followed users.96+ """97+ if not g.user:98 return redirect(url_for('public_timeline'))99 offset = request.args.get('offset', type=int)100 return render_template('timeline.html', messages=query_db('''101 select message.*, user.* from message, user6 unmodified lines108 109 110 @app.route('/public')111 def public_timeline():112+ """Displays the latest messages of all users."""113 return render_template('timeline.html', messages=query_db('''114 select message.*, user.* from message, user115 where message.author_id = user.user_id116 order by message.pub_date desc limit ?''', [PER_PAGE]))117 118 119 @app.route('/<username>')120 def user_timeline(username):121+ """Display's a users tweets."""122 profile_user = query_db('select * from user where username = ?',123 [username], one=True)124 if profile_user is None:125 abort(404)126 followd = False111- if 'user_id' in session:127+ if g.user:128 followed = query_db('''select 1 from follower where129 follower.who_id = ? and follower.whom_id = ?''',130 [session['user_id'], profile_user['user_id']], one=True) is not None131 return render_template('timeline.html', messages=query_db('''5 unmodified lines137 138 139 @app.route('/<username>/follow')140 def follow_user(username):125- if not 'user_id' in session:141+ """Adds the current user as follower of the given user"""142+ if not g.user:143 abort(401)144 whom_id = get_user_id(username)145 if whom_id is None:146 abort(404)5 unmodified lines152 153 154 @app.route('/<username>/unfollow')155 def unfollow_user(username):139- if not 'user_id' in session:156+ """Removes the current user as follower of the given user"""157+ if not g.user:158 abort(401)159 whom_id = get_user_id(username)160 if whom_id is None:161 abort(404)5 unmodified lines167 168 169 @app.route('/add_message', methods=['POST'])170 def add_message():171+ """Registers a new message for the user"""172 if 'user_id' not in session:173 abort(401)174 if request.form['text']:175 g.db.execute('''insert into message (author_id, text, pub_date)5 unmodified lines181 182 183 @app.route('/login', methods=['GET', 'POST'])184 def login():166- if 'user_id' in session:185+ """Logs the user in"""186+ if g.user:187 return redirect(url_for('timeline'))188 error = None189 if request.method == 'POST':190 user = query_db('''select * from user where11 unmodified lines202 203 204 @app.route('/register', methods=['GET', 'POST'])205 def register():186- if 'user_id' in session:206+ """Registers the user"""207+ if g.user:208 return redirect(url_for('timeline'))209 error = None210 if request.method == 'POST':211 if not request.form['username']:19 unmodified lines231 232 233 @app.route('/logout')234 def logout():235+ """Logs the user out"""236 flash('You were logged out')237 session.pop('user_id', None)238 return redirect(url_for('public_timeline'))239 11 unmodified lines