Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Open

test #72

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions squawker/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
-- TODO change this
DROP TABLE IF EXISTS mytable;
CREATE TABLE mytable (id integer);
DROP TABLE IF EXISTS listOfSquawks;
CREATE TABLE listOfSquawks (id integer primary key, caption VARCHAR(140));
19 changes: 13 additions & 6 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import Flask, g
from flask import Flask, g, request, render_template, abort
import sqlite3


# -- leave these lines intact --
# -- leave these lines intact test--
app = Flask(__name__)


Expand Down Expand Up @@ -37,12 +37,19 @@ def close_connection(exception):
# ------------------------------


@app.route('/')
@app.route('/', methods=["GET", "POST"])
def root():
conn = get_db()
# TODO change this
return "Hello World!"

if request.method == "POST":
getCaption = request.form['caption']
if len(getCaption) > 140:
abort(400)
else:
cc_object = conn.execute('INSERT INTO listOfSquawks (caption) VALUES (?)', [getCaption])
conn.commit()
cc_object = conn.execute('SELECT * FROM listOfSquawks ORDER BY id desc')
squawkers = cc_object.fetchall()
return render_template('index.html', captions=squawkers)

if __name__ == '__main__':
app.run()
28 changes: 28 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Elya's squawker assignment</title>
</head>
<body>
<div class="postMsg">
<form action="/" method="POST">
<div>
<label for="msg">Type your message:</label>
<br><textarea name="caption" id="message" maxlength="140"></textarea>
</div>
<div class="button">
<button type="submit">Post it!</button>
</div>
</form>
</div>

<div class="getMsg">
<label for="previousMsg">Below are the previous squawks:</label>
{% for msg in captions %}
<div>
<p>{{ msg[1] }}</p>
</div>
{% endfor %}
</div>
</body>
</html>