diff --git a/squawker/schema.sql b/squawker/schema.sql index 5e67ffb..6c6dcfc 100644 --- a/squawker/schema.sql +++ b/squawker/schema.sql @@ -1,3 +1,5 @@ -- TODO change this DROP TABLE IF EXISTS mytable; -CREATE TABLE mytable (id integer); +CREATE TABLE mytable ( +id integer primary key autoincrement, +posts text not null); diff --git a/squawker/server.py b/squawker/server.py index 6ff24ba..4997951 100644 --- a/squawker/server.py +++ b/squawker/server.py @@ -1,9 +1,11 @@ -from flask import Flask, g +from flask import Flask, request, g, session, redirect, url_for, abort, render_template, flash import sqlite3 # -- leave these lines intact -- app = Flask(__name__) +app.config.from_object(__name__) +app.secret_key = "super secret key" def get_db(): @@ -37,11 +39,28 @@ def close_connection(exception): # ------------------------------ -@app.route('/') +@app.route('/', methods=['POST', 'GET']) def root(): conn = get_db() - # TODO change this - return "Hello World!" + cur = conn.cursor() + conts = cur.execute('SELECT posts From mytable ORDER BY ID DESC') + posts = conts.fetchall() + return render_template('index.html', posts=posts) + + +@app.route('/add', methods=['POST', 'GET']) +def add_post(): + conn = get_db() + cur = conn.cursor() + if request.method == "POST": + apost = request.form['posts'] + if len(apost) > 140: + abort(400) + else: + cur.execute('INSERT INTO mytable (posts) VALUES (?)', [apost]) + conn.commit() + flash('Successfully posted') + return redirect(url_for('root')) if __name__ == '__main__': diff --git a/squawker/static/style.css b/squawker/static/style.css new file mode 100644 index 0000000..9f84650 --- /dev/null +++ b/squawker/static/style.css @@ -0,0 +1,20 @@ + +body { font-family: sans-serif; background: #eee; } +a, h1, h2 { color: #377ba8; } +h1, h2 { font-family: 'Georgia', serif; margin: 0; } +h1 { border-bottom: 2px solid #eee; } +h2 { font-size: 1.2em; } + +.page { margin: 2em auto; width: 35em; border: 5px solid #ccc; + padding: 0.8em; background: white; } +.posts { list-style: none; margin: 0; padding: 0; } +.posts li { margin: 0.8em 1.2em; } +.posts li h2 { margin-left: -1em; } +.add-post { font-size: 0.9em; border-bottom: 1px solid #ccc; } +.add-post dl { font-weight: bold; } +.metanav { text-align: right; font-size: 0.8em; padding: 0.3em; + margin-bottom: 1em; background: #fafafa; } +.flash { background: #cee5F5; padding: 0.5em; + border: 1px solid #aacbe2; } +.error { background: #f0d6d6; padding: 0.5em; } + diff --git a/squawker/templates/index.html b/squawker/templates/index.html new file mode 100644 index 0000000..a677e06 --- /dev/null +++ b/squawker/templates/index.html @@ -0,0 +1,18 @@ +{% extends "layout.html" %} +{% block body %} +
+
+
Posts goes here: +
+
+
+
+ +{% endblock %} + diff --git a/squawker/templates/layout.html b/squawker/templates/layout.html new file mode 100644 index 0000000..fa4688b --- /dev/null +++ b/squawker/templates/layout.html @@ -0,0 +1,15 @@ + + +squawker + +
+

Squawker

+
+
+ {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} + {% block body %}{% endblock %} +
+ + diff --git a/src/pip-delete-this-directory.txt b/src/pip-delete-this-directory.txt new file mode 100644 index 0000000..c8883ea --- /dev/null +++ b/src/pip-delete-this-directory.txt @@ -0,0 +1,5 @@ +This file is placed here by pip to indicate the source was put +here by pip. + +Once this package is successfully installed this source code will be +deleted (unless you remove this file). diff --git a/src/splinter b/src/splinter new file mode 160000 index 0000000..ba3afc8 --- /dev/null +++ b/src/splinter @@ -0,0 +1 @@ +Subproject commit ba3afc8a0750dcfea096f8f89adb58f8f8d78276