Skip to content
Myr

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

7 files+30 added−89 removed

deleted:examples/apishowcase/static/style.css-7 removed
deleted:examples/apishowcase/templates/counter.html-12 removed
deleted:examples/apishowcase/templates/hello.html-13 removed
deleted:examples/apishowcase/templates/index.html-11 removed
deleted:examples/apishowcase/templates/layout.html-8 removed
deleted:examples/apishowcase/apishowcase.py-30 removed
1from flask import Flask, abort, redirect, request, session, \2 render_template, url_for34#: 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.6app = Flask(__name__)789@app.route('/', methods=['GET'])10def index():11 """Show an overview page"""12 return render_template('index.html')131415@app.route('/hello/', methods=['GET', 'POST'])16def 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)212223@app.route('/hello/<name>', methods=['GET'])24def hello(name):25 """Greet name friendly"""26 return render_template('hello.html', name=name)272829if __name__ == '__main__':30 app.run(debug=True)
modified:examples/minitwit/minitwit.py+30 added-8 removed
1# -*- coding: utf-8 -*-2"""3 MiniTwit4 ~~~~~~~~56 A microblogging application written with Flask and sqlite3.78 :copyright: (c) 2010 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from __future__ import with_statement12import re13import time14import sqlite3
59 unmodified lines
74 """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)828384@app.request_shutdown75def after_request(request):85def after_request(response):86 """Closes the database again at the end of the request."""87 g.db.close()78 return request88 return response899091@app.route('/')92def 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, user
6 unmodified lines
108109110@app.route('/public')111def 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]))117118119@app.route('/<username>')120def 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 lines
137138139@app.route('/<username>/follow')140def 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 lines
152153154@app.route('/<username>/unfollow')155def 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 lines
167168169@app.route('/add_message', methods=['POST'])170def 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 lines
181182183@app.route('/login', methods=['GET', 'POST'])184def 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 where
11 unmodified lines
202203204@app.route('/register', methods=['GET', 'POST'])205def 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 lines
231232233@app.route('/logout')234def 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